tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1239527 - in /tomcat/trunk/java/org/apache/catalina/startup: Bootstrap.java Catalina.java
Date Thu, 02 Feb 2012 10:35:44 GMT
Author: markt
Date: Thu Feb  2 10:35:44 2012
New Revision: 1239527

URL: http://svn.apache.org/viewvc?rev=1239527&view=rev
Log:
Align the various parts of start-up code that read/set home/base in
slightly different ways.

Modified:
    tomcat/trunk/java/org/apache/catalina/startup/Bootstrap.java
    tomcat/trunk/java/org/apache/catalina/startup/Catalina.java

Modified: tomcat/trunk/java/org/apache/catalina/startup/Bootstrap.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/Bootstrap.java?rev=1239527&r1=1239526&r2=1239527&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/Bootstrap.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/Bootstrap.java Thu Feb  2 10:35:44 2012
@@ -20,6 +20,7 @@ package org.apache.catalina.startup;
 
 
 import java.io.File;
+import java.io.IOException;
 import java.lang.management.ManagementFactory;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -69,6 +70,68 @@ public final class Bootstrap {
     private static Bootstrap daemon = null;
 
 
+    private static final File catalinaBaseFile;
+    private static final File catalinaHomeFile;
+
+    static {
+        // Will always be non-null
+        String userDir = System.getProperty("user.dir");
+
+        // Home first
+        String home = System.getProperty(Globals.CATALINA_HOME_PROP);
+        File homeFile = null;
+
+        if (home != null) {
+            File f = new File(home);
+            try {
+                homeFile = f.getCanonicalFile();
+            } catch (IOException ioe) {
+                homeFile = f.getAbsoluteFile();
+            }
+        }
+
+        if (homeFile == null) {
+            // First fall-back. See if current directory is a bin directory
+            // in a normal Tomcat install
+            File bootstrapJar = new File(userDir, "bootstrap.jar");
+
+            if (bootstrapJar.exists()) {
+                File f = new File(userDir, "..");
+                try {
+                    homeFile = f.getCanonicalFile();
+                } catch (IOException ioe) {
+                    homeFile = f.getAbsoluteFile();
+                }
+            }
+        }
+
+        if (homeFile == null) {
+            // Second fall-back. Use current directory
+            File f = new File(userDir);
+            try {
+                homeFile = f.getCanonicalFile();
+            } catch (IOException ioe) {
+                homeFile = f.getAbsoluteFile();
+            }
+        }
+
+        catalinaHomeFile = homeFile;
+
+        // Then base
+        String base = System.getProperty(Globals.CATALINA_BASE_PROP);
+        if (base == null) {
+            catalinaBaseFile = catalinaHomeFile;
+        } else {
+            File baseFile = new File(base);
+            try {
+                baseFile = baseFile.getCanonicalFile();
+            } catch (IOException ioe) {
+                baseFile = baseFile.getAbsoluteFile();
+            }
+            catalinaBaseFile = baseFile;
+        }
+    }
+
     // -------------------------------------------------------------- Variables
 
 
@@ -216,13 +279,7 @@ public final class Bootstrap {
     /**
      * Initialize daemon.
      */
-    public void init()
-        throws Exception
-    {
-
-        // Set Catalina path
-        setCatalinaHome();
-        setCatalinaBase();
+    public void init() throws Exception {
 
         initClassLoaders();
 
@@ -472,67 +529,42 @@ public final class Bootstrap {
 
     }
 
+
     /**
-     * Set the <code>catalina.base</code> System property to the current
-     * working directory if it has not been set.
+     * Obtain the name of configured home (binary) directory. Note that home and
+     * base may be the same (and are by default).
      */
-    private void setCatalinaBase() {
-
-        if (System.getProperty(Globals.CATALINA_BASE_PROP) != null)
-            return;
-        if (System.getProperty(Globals.CATALINA_HOME_PROP) != null)
-            System.setProperty(Globals.CATALINA_BASE_PROP,
-                               System.getProperty(Globals.CATALINA_HOME_PROP));
-        else
-            System.setProperty(Globals.CATALINA_BASE_PROP,
-                               System.getProperty("user.dir"));
-
+    public static String getCatalinaHome() {
+        return catalinaHomeFile.getPath();
     }
 
 
     /**
-     * Set the <code>catalina.home</code> System property to the current
-     * working directory if it has not been set.
+     * Obtain the name of the configured base (instance) directory. Note that
+     * home and base may be the same (and are by default). If this is not set
+     * the value returned by {@link #getCatalinaHome()} will be used.
      */
-    private void setCatalinaHome() {
-
-        if (System.getProperty(Globals.CATALINA_HOME_PROP) != null)
-            return;
-        File bootstrapJar =
-            new File(System.getProperty("user.dir"), "bootstrap.jar");
-        if (bootstrapJar.exists()) {
-            try {
-                System.setProperty
-                    (Globals.CATALINA_HOME_PROP,
-                     (new File(System.getProperty("user.dir"), ".."))
-                     .getCanonicalPath());
-            } catch (Exception e) {
-                // Ignore
-                System.setProperty(Globals.CATALINA_HOME_PROP,
-                                   System.getProperty("user.dir"));
-            }
-        } else {
-            System.setProperty(Globals.CATALINA_HOME_PROP,
-                               System.getProperty("user.dir"));
-        }
-
+    public static String getCatalinaBase() {
+        return catalinaBaseFile.getPath();
     }
 
 
     /**
-     * Get the value of the catalina.home environment variable.
+     * Obtain the configured home (binary) directory. Note that home and
+     * base may be the same (and are by default).
      */
-    public static String getCatalinaHome() {
-        return System.getProperty(Globals.CATALINA_HOME_PROP,
-                                  System.getProperty("user.dir"));
+    public static File getCatalinaHomeFile() {
+        return catalinaHomeFile;
     }
 
 
     /**
-     * Get the value of the catalina.base environment variable.
+     * Obtain the configured base (instance) directory. Note that
+     * home and base may be the same (and are by default). If this is not set
+     * the value returned by {@link #getCatalinaHomeFile()} will be used.
      */
-    public static String getCatalinaBase() {
-        return System.getProperty(Globals.CATALINA_BASE_PROP, getCatalinaHome());
+    public static File getCatalinaBaseFile() {
+        return catalinaBaseFile;
     }
 
 

Modified: tomcat/trunk/java/org/apache/catalina/startup/Catalina.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/Catalina.java?rev=1239527&r1=1239526&r2=1239527&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/Catalina.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/Catalina.java Thu Feb  2 10:35:44 2012
@@ -30,7 +30,6 @@ import java.util.List;
 import java.util.logging.LogManager;
 
 import org.apache.catalina.Container;
-import org.apache.catalina.Globals;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.LifecycleState;
 import org.apache.catalina.Server;
@@ -273,7 +272,7 @@ public class Catalina {
 
         File file = new File(configFile);
         if (!file.isAbsolute()) {
-            file = new File(System.getProperty(Globals.CATALINA_BASE_PROP), configFile);
+            file = new File(Bootstrap.getCatalinaBase(), configFile);
         }
         return (file);
 
@@ -583,6 +582,8 @@ public class Catalina {
         }
 
         getServer().setCatalina(this);
+        getServer().setCatalinaHome(Bootstrap.getCatalinaHomeFile());
+        getServer().setCatalinaBase(Bootstrap.getCatalinaBaseFile());
 
         // Stream redirection
         initStreams();
@@ -742,51 +743,11 @@ public class Catalina {
 
 
     protected void initDirs() {
-
-        String catalinaHome = System.getProperty(Globals.CATALINA_HOME_PROP);
-        if (catalinaHome == null) {
-            if (System.getProperty(Globals.CATALINA_BASE_PROP) != null) {
-                catalinaHome = System.getProperty(Globals.CATALINA_BASE_PROP);
-            }
-        }
-        // last resort - for minimal/embedded cases.
-        if(catalinaHome==null) {
-            catalinaHome=System.getProperty("user.dir");
-        }
-        if (catalinaHome != null) {
-            File home = new File(catalinaHome);
-            if (!home.isAbsolute()) {
-                try {
-                    catalinaHome = home.getCanonicalPath();
-                } catch (IOException e) {
-                    catalinaHome = home.getAbsolutePath();
-                }
-            }
-            System.setProperty(Globals.CATALINA_HOME_PROP, catalinaHome);
-        }
-
-        if (System.getProperty(Globals.CATALINA_BASE_PROP) == null) {
-            System.setProperty(Globals.CATALINA_BASE_PROP,
-                               catalinaHome);
-        } else {
-            String catalinaBase = System.getProperty(Globals.CATALINA_BASE_PROP);
-            File base = new File(catalinaBase);
-            if (!base.isAbsolute()) {
-                try {
-                    catalinaBase = base.getCanonicalPath();
-                } catch (IOException e) {
-                    catalinaBase = base.getAbsolutePath();
-                }
-            }
-            System.setProperty(Globals.CATALINA_BASE_PROP, catalinaBase);
-        }
-
         String temp = System.getProperty("java.io.tmpdir");
         if (temp == null || (!(new File(temp)).exists())
                 || (!(new File(temp)).isDirectory())) {
             log.error(sm.getString("embedded.notmp", temp));
         }
-
     }
 
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message