r9785 - in helma-ng/trunk/src/org/helma/tools: . launcher

[email protected] Fri, 15 May 2009 12:30:24 +0200 (CEST)
Newsgroups gmane.comp.java.helma.cvs
Message-ID <20090515103024.ED1143D0D6@mia>
Author: hannes
Date: 2009-05-15 12:30:24 +0200 (Fri, 15 May 2009)
New Revision: 9785

Modified:
   helma-ng/trunk/src/org/helma/tools/HelmaConfiguration.java
   helma-ng/trunk/src/org/helma/tools/launcher/Main.java
Log:
Move log4j setup from launcher.Main to HelmaConfiguration constructor.
First, this is a point that all deployment variants use. Second, we actually have the module path set up so we're more likely to use the right configuration resource.

Details at http://dev.helma.org/trac/helma/changeset/9785

Modified: helma-ng/trunk/src/org/helma/tools/HelmaConfiguration.java
===================================================================
--- helma-ng/trunk/src/org/helma/tools/HelmaConfiguration.java	2009-05-15 09:44:27 UTC (rev 9784)
+++ helma-ng/trunk/src/org/helma/tools/HelmaConfiguration.java	2009-05-15 10:30:24 UTC (rev 9785)
@@ -26,6 +26,7 @@
 import java.io.FileNotFoundException;
 import java.util.ArrayList;
 import java.util.List;
+import java.net.MalformedURLException;
 
 /**
  * This class describes the configuration for a Helma NG application or shell session.
@@ -33,15 +34,15 @@
  */
 public class HelmaConfiguration {
 
-    Repository home;
-    List<Repository> repositories;
-    String mainModule;
-    int optimizationLevel = 0;
-    int languageVersion = 180;
-    Class<?>[] hostClasses = null;
-    HelmaClassLoader loader;
-    ClassShutter classShutter = null;
-    boolean sealed = false;
+    private Repository home;
+    private List<Repository> repositories;
+    private String mainModule;
+    private int optimizationLevel = 0;
+    private int languageVersion = 180;
+    private Class<?>[] hostClasses = null;
+    private HelmaClassLoader loader;
+    private ClassShutter classShutter = null;
+    private boolean sealed = false;
 
     /**
      * Create a new Helma configuration and sets up its module search path.
@@ -73,7 +74,7 @@
                 if (repository != null && repository.exists()) {
                     repositories.add(repository);
                 } else {
-                    getLogger().error("Cannot resolve module path entry: " + path);
+                    System.err.println("Cannot resolve module path entry: " + path);
                 }
             }
         }
@@ -84,10 +85,19 @@
                 if (repository != null && repository.exists()) {
                     repositories.add(repository);
                 } else {
-                    getLogger().error("Cannot resolve system module root: " + systemModules);
+                    System.err.println("Cannot resolve system module root: " + systemModules);
                 }
         }
 
+        // now that repositories are set up try to set default log4j configuration file
+        if (System.getProperty("log4j.configuration") == null) {
+            Resource log4jConfig = getResource("config/log4j.properties");
+            try {
+                System.setProperty("log4j.configuration", log4jConfig.getUrl().toString());
+            } catch (MalformedURLException x) {
+                System.setProperty("log4j.configuration", "file:" + log4jConfig.getPath());
+            }
+        }
         getLogger().debug("Parsed repository list: " + repositories);
     }
 

Modified: helma-ng/trunk/src/org/helma/tools/launcher/Main.java
===================================================================
--- helma-ng/trunk/src/org/helma/tools/launcher/Main.java	2009-05-15 09:44:27 UTC (rev 9784)
+++ helma-ng/trunk/src/org/helma/tools/launcher/Main.java	2009-05-15 10:30:24 UTC (rev 9785)
@@ -43,12 +43,6 @@
             File home = getHelmaHome();
             ClassLoader loader = createClassLoader(home);
 
-            // set default log4j configuration file
-            if (System.getProperty("log4j.configuration") == null) {
-                File file = new File(home, "modules/config/log4j.properties"); 
-                System.setProperty("log4j.configuration", "file:" + file.getPath());
-            }
-
             Class clazz = loader.loadClass("org.helma.tools.HelmaRunner");
             Class[] cargs = new Class[] {args.getClass()};
             Method main = clazz.getMethod("main", cargs);