Author: sdeboy
Date: Fri May 21 06:32:05 2010
New Revision: 946898

URL: http://svn.apache.org/viewvc?rev=946898&view=rev
Log:
Replaced the ability to specify the configuration via 'log4j.configuration' 
system property with application argument (must still be a URL).  Use of an 
application argument overrides initial auto-configuration setting.

Modified:
    
logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java
    
logging/chainsaw/trunk/src/main/resources/org/apache/log4j/chainsaw/help/release-notes.html

Modified: 
logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java
URL: 
http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java?rev=946898&r1=946897&r2=946898&view=diff
==============================================================================
--- 
logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java
 (original)
+++ 
logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java
 Fri May 21 06:32:05 2010
@@ -497,12 +497,17 @@ public static void main(String[] args) {
 
               String defaultPath = ".";
               if (configurationURL.getItemCount() > 0) {
-                File currentConfigurationPath = new 
File(configurationURL.getSelectedItem().toString()).getParentFile();
-                  defaultPath = currentConfigurationPath.getPath();
-                  //JFileChooser constructor will not navigate to this 
location unless we remove the prefixing protocol and slash
-                  //at least on winxp
-                  if (defaultPath.toLowerCase().startsWith("file:\\")) {
-                      defaultPath = defaultPath.substring("file:\\".length());
+                  Object selectedItem = configurationURL.getSelectedItem();
+                  if (selectedItem != null) {
+                      File currentConfigurationPath = new 
File(selectedItem.toString()).getParentFile();
+                      if (currentConfigurationPath != null) {
+                          defaultPath = currentConfigurationPath.getPath();
+                          //JFileChooser constructor will not navigate to this 
location unless we remove the prefixing protocol and slash
+                          //at least on winxp
+                          if (defaultPath.toLowerCase().startsWith("file:\\")) 
{
+                              defaultPath = 
defaultPath.substring("file:\\".length());
+                          }
+                      }
                   }
               }
 

Modified: 
logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java
URL: 
http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java?rev=946898&r1=946897&r2=946898&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java 
(original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java 
Fri May 21 06:32:05 2010
@@ -174,6 +174,7 @@ public class LogUI extends JFrame implem
   private int dividerSize;
   private int cyclicBufferSize;
   private static Logger logger;
+  private static String configurationURLAppArg;
 
   /**
    * Set to true, if and only if the GUI has completed it's full
@@ -258,7 +259,10 @@ public class LogUI extends JFrame implem
    * @param args
    */
   public static void main(String[] args) {
-  
+      if (args.length > 0) {
+          configurationURLAppArg = args[0];
+      }
+
       if(OSXIntegration.IS_OSX) {
           System.setProperty("apple.laf.useScreenMenuBar", "true");
       }
@@ -273,6 +277,10 @@ public class LogUI extends JFrame implem
     final ApplicationPreferenceModel model = new ApplicationPreferenceModel();
 
     SettingsManager.getInstance().configure(new 
ApplicationPreferenceModelSaver(model));
+    //if a configuration URL param was provided, set the configuration URL 
field to null
+    if (configurationURLAppArg != null) {
+        model.setConfigurationURL("");
+    }
 
     applyLookAndFeel(model.getLookAndFeelClassName());
     EventQueue.invokeLater(new Runnable()
@@ -384,10 +392,11 @@ public class LogUI extends JFrame implem
                }
     });
 
-    String config = model.getConfigurationURL();
-    if (config == null || (config.trim().equals(""))) {
-        logger.info("No auto-configuration file found in 
ApplicationPreferenceModel - attempting to use log4j.configurationURL system 
property");
-        config = System.getProperty(Constants.DEFAULT_CONFIGURATION_KEY);
+    String config = configurationURLAppArg;
+    if (config != null) {
+        logger.info("Command-line configuration arg provided (overriding 
auto-configuration URL) - using: " + config);
+    } else {
+        config = model.getConfigurationURL();
     }
 
     if (config != null && (!config.trim().equals(""))) {
@@ -999,10 +1008,12 @@ public class LogUI extends JFrame implem
       });
 
     getSettingsManager().addSettingsListener(this);
-    getSettingsManager().addSettingsListener(new 
ApplicationPreferenceModelSaver(applicationPreferenceModel));
     
getSettingsManager().addSettingsListener(MRUFileListPreferenceSaver.getInstance());
     getSettingsManager().addSettingsListener(receiversPanel);
     getSettingsManager().loadSettings();
+    //app preferences have already been loaded (and configuration url possibly 
set to blank if being overridden)
+    //but we need a listener so the settings will be saved on exit (added 
after loadsettings was called)
+    getSettingsManager().addSettingsListener(new 
ApplicationPreferenceModelSaver(applicationPreferenceModel));
 
     setVisible(true);
 

Modified: 
logging/chainsaw/trunk/src/main/resources/org/apache/log4j/chainsaw/help/release-notes.html
URL: 
http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/resources/org/apache/log4j/chainsaw/help/release-notes.html?rev=946898&r1=946897&r2=946898&view=diff
==============================================================================
--- 
logging/chainsaw/trunk/src/main/resources/org/apache/log4j/chainsaw/help/release-notes.html
 (original)
+++ 
logging/chainsaw/trunk/src/main/resources/org/apache/log4j/chainsaw/help/release-notes.html
 Fri May 21 06:32:05 2010
@@ -12,7 +12,7 @@
 <h1>2.0</h1>
 <h2>20 May 2010</h2>
 <ul>
-<li>For users who would like to specify the Chainsaw configuration file from 
the command line, the 'log4j.configuration' system property will now be used if 
the automatic configuration URL is NOT specified in application-wide 
preferences.  The log4j.configuration system property must provide the -URL- of 
the Chainsaw configuration file.</li>
+<li>For users who would like to specify the Chainsaw configuration file from 
the command line, specify the URL to a configuration file as the first argument 
to Chainsaw (will bypass the the initial use of the automatic configuration URL 
mechanism).  Example: java -classpath {classpath here} 
org.apache.log4j.chainsaw.LogUI 
file:///c:/downloads/tools/log4j/config/log4j.xml</li>
 </ul>
 <h2>13 May 2010</h2>
 <ul>


Reply via email to