Consolidate directory creation from doing it in multiple places with no indication...
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 2 Jun 2009 14:04:42 +0000 (14:04 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 2 Jun 2009 14:04:42 +0000 (14:04 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@781036 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/Host.java
java/org/apache/catalina/core/StandardHost.java
java/org/apache/catalina/startup/HostConfig.java
java/org/apache/catalina/startup/LocalStrings.properties
webapps/docs/config/host.xml

index 2527c43..a9413d3 100644 (file)
@@ -232,5 +232,16 @@ public interface Host extends Container {
      */
     public void removeAlias(String alias);
 
+    /**
+     * Returns true if the Host will attempt to create directories for appBase and xmlBase
+     * unless they already exist.
+     * @return
+     */
+    public boolean getCreateDirs();
+    /**
+     * Set to true if the Host should attempt to create directories for xmlBase and appBase upon startup
+     * @param createDirs
+     */
+    public void setCreateDirs(boolean createDirs);
 
 }
index 951d632..9bb6ef0 100644 (file)
@@ -161,7 +161,11 @@ public class StandardHost
      * Attribute value used to turn on/off XML namespace awarenes.
      */
      private boolean xmlNamespaceAware = false;
-
+     
+    /**
+     * Should we create directories upon startup for appBase and xmlBase
+     */
+     private boolean createDirs = true;
 
     // ------------------------------------------------------------- Properties
 
@@ -216,6 +220,22 @@ public class StandardHost
 
     }
 
+    /**
+     * Returns true if the Host will attempt to create directories for appBase and xmlBase
+     * unless they already exist.
+     * @return
+     */
+    public boolean getCreateDirs() {
+        return createDirs;
+    }
+
+    /**
+     * Set to true if the Host should attempt to create directories for xmlBase and appBase upon startup
+     * @param createDirs
+     */
+    public void setCreateDirs(boolean createDirs) {
+        this.createDirs = createDirs;
+    }
 
     /**
      * Return the value of the auto deploy flag.  If true, it indicates that 
@@ -680,8 +700,7 @@ public class StandardHost
         return (sb.toString());
 
     }
-
-
+    
     /**
      * Start this host.
      *
index 12581ce..07b46eb 100644 (file)
@@ -762,8 +762,6 @@ public class HostConfig
                 if (entry != null) {
                     istream = jar.getInputStream(entry);
                     
-                    configBase().mkdirs();
-                    
                     ostream =
                         new BufferedOutputStream
                         (new FileOutputStream(xml), 1024);
@@ -956,7 +954,6 @@ public class HostConfig
                         digester.reset();
                     }
                 }
-                configBase().mkdirs();
                 File xmlCopy = new File(configBase(), file + ".xml");
                 InputStream is = null;
                 OutputStream os = null;
@@ -1212,6 +1209,15 @@ public class HostConfig
         } catch (Exception e) {
             log.error(sm.getString("hostConfig.jmx.register", oname), e);
         }
+        
+        if (host.getCreateDirs()) {
+            File[] dirs = new File[] {appBase(),configBase()};
+            for (int i=0; i<dirs.length; i++) {
+                if ( (!dirs[i].exists()) && (!dirs[i].mkdirs())) {
+                    log.error(sm.getString("hostConfig.createDirs",dirs[i]));
+                }
+            }
+        }
 
         if (host.getDeployOnStartup())
             deployApps();
index 66ae056..a91e01c 100644 (file)
@@ -97,3 +97,4 @@ userConfig.error=Error deploying web application for user {0}
 userConfig.start=UserConfig: Processing START
 userConfig.stop=UserConfig: Processing STOP
 catalina.stopServer=No shutdown port configured. Shut down server through OS signal. Server not shut down.
+hostConfig.createDirs=Unable to create directory for deployment: {0}
index 90f9a3e..851ca3f 100644 (file)
         Deployment</a> for more information on automatic recognition and
         deployment of web applications to be deployed automatically.</p>
       </attribute>
+      
+      <attribute name="createDirs" required="false">
+        <p>If set to true, Tomcat will attempt to create the directories defined by the 
+        attributes <code>appBase</code> and <code>xmlBase</code> during the startup phase.
+        The default value is <code>true</code>.
+        If set to true, and directory creation fails, an error message will be printed out but will not halt 
+        the startup sequence.</p>
+      </attribute>
 
       <attribute name="autoDeploy" required="false">
         <p>This flag value indicates if new web applications, dropped in to