Author: markt
Date: Mon Jan 10 16:48:25 2011
New Revision: 1057275

URL: http://svn.apache.org/viewvc?rev=1057275&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50205
Add deployIgnore to Host
Based on a patch by Jim Riggs

Modified:
    tomcat/trunk/java/org/apache/catalina/Host.java
    tomcat/trunk/java/org/apache/catalina/core/StandardHost.java
    tomcat/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml
    tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java
    tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties
    tomcat/trunk/webapps/docs/config/host.xml

Modified: tomcat/trunk/java/org/apache/catalina/Host.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Host.java?rev=1057275&r1=1057274&r2=1057275&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Host.java (original)
+++ tomcat/trunk/java/org/apache/catalina/Host.java Mon Jan 10 16:48:25 2011
@@ -14,12 +14,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-
 package org.apache.catalina;
 
 
-
 /**
  * A <b>Host</b> is a Container that represents a virtual host in the
  * Catalina servlet engine.  It is useful in the following types of scenarios:
@@ -148,6 +145,22 @@ public interface Host extends Container 
     public void setDeployOnStartup(boolean deployOnStartup);
 
 
+    /**
+     * Return the regular expression that defines the files and directories in
+     * the host's {...@link #appBase} that will be ignored by the automatic
+     * deployment process.
+     */
+    public String getDeployIgnore();
+
+
+    /**
+     * Set the regular expression that defines the files and directories in
+     * the host's {...@link #appBase} that will be ignored by the automatic
+     * deployment process.
+     */
+    public void setDeployIgnore(String deployIgnore);
+
+
     // --------------------------------------------------------- Public Methods
 
 

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardHost.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardHost.java?rev=1057275&r1=1057274&r2=1057275&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardHost.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardHost.java Mon Jan 10 
16:48:25 2011
@@ -168,6 +168,14 @@ public class StandardHost extends Contai
          new WeakHashMap<ClassLoader, String>();
      
      
+     /**
+      * Any file or directory in {...@link #appBase} that this pattern matches 
will
+      * be ignored by the automatic deployment process (both
+      * {...@link #deployOnStartup} and {...@link #autoDeploy}).
+      */
+     private String deployIgnore = null;
+
+
     // ------------------------------------------------------------- Properties
 
 
@@ -424,8 +432,8 @@ public class StandardHost extends Contai
                                    this.errorReportValveClass);
 
     }
-
-
+    
+    
     /**
      * Return the canonical, fully qualified, name of the virtual host
      * this Container represents.
@@ -500,6 +508,32 @@ public class StandardHost extends Contai
     }
 
 
+    /**
+     * Return the regular expression that defines the files and directories in
+     * the host's {...@link #appBase} that will be ignored by the automatic
+     * deployment process.
+     */
+    @Override
+    public String getDeployIgnore() {
+        return this.deployIgnore;
+    }
+
+
+    /**
+     * Set the regular expression that defines the files and directories in
+     * the host's {...@link #appBase} that will be ignored by the automatic
+     * deployment process.
+     */
+    @Override
+    public void setDeployIgnore(String deployIgnore) {
+        String oldDeployIgnore = this.deployIgnore;
+        this.deployIgnore = deployIgnore;
+        support.firePropertyChange("deployIgnore",
+                                   oldDeployIgnore, 
+                                   this.deployIgnore);
+    }
+
+
     // --------------------------------------------------------- Public Methods
 
 

Modified: tomcat/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml?rev=1057275&r1=1057274&r2=1057275&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml (original)
+++ tomcat/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml Mon Jan 
10 16:48:25 2011
@@ -1164,6 +1164,10 @@
                description="Should we create directories upon startup for 
appBase and xmlBase? "
                type="boolean"/>
       
+    <attribute name="deployIgnore"
+               description="Paths within appBase ignored for automatic 
deployment"
+               type="java.lang.String"/>
+
     <attribute name="deployOnStartup"
                description="The deploy on startup flag for this Host"
                type="boolean"/>

Modified: tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java?rev=1057275&r1=1057274&r2=1057275&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java Mon Jan 10 
16:48:25 2011
@@ -31,10 +31,12 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Locale;
 import java.util.Set;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
+import java.util.regex.Pattern;
 
 import javax.management.ObjectName;
 
@@ -460,17 +462,45 @@ public class HostConfig
 
         File appBase = appBase();
         File configBase = configBase();
+        String[] filteredAppPaths = filterAppPaths(appBase.list());
         // Deploy XML descriptors from configBase
         deployDescriptors(configBase, configBase.list());
         // Deploy WARs, and loop if additional descriptors are found
-        deployWARs(appBase, appBase.list());
+        deployWARs(appBase, filteredAppPaths);
         // Deploy expanded folders
-        deployDirectories(appBase, appBase.list());
+        deployDirectories(appBase, filteredAppPaths);
         
     }
 
 
     /**
+     * Filter the list of application file paths to remove those that match
+     * the regular expression defined by {...@link Host#getDeployIgnore()}.
+     *  
+     * @param unfilteredAppPaths    The list of application paths to filtert
+     * 
+     * @return  The filtered list of application paths
+     */
+    protected String[] filterAppPaths(String[] unfilteredAppPaths) {
+        if (host.getDeployIgnore() == null) {
+            return unfilteredAppPaths;
+        }
+        
+        Pattern filter = Pattern.compile(host.getDeployIgnore());
+
+        List<String> filteredList = new ArrayList<String>();
+        for (String appPath : unfilteredAppPaths) {
+            if (filter.matcher(appPath).matches()) {
+                log.debug(sm.getString("hostConfig.ignorePath", appPath));
+            } else {
+                filteredList.add(appPath);
+            }
+        }
+        return filteredList.toArray(new String[filteredList.size()]);
+    }
+
+
+    /**
      * Deploy applications for any directories or WAR files that are found
      * in our "application root" directory.
      */

Modified: tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties?rev=1057275&r1=1057274&r2=1057275&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties 
(original)
+++ tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties Mon 
Jan 10 16:48:25 2011
@@ -88,6 +88,7 @@ hostConfig.deploying=Deploying discovere
 hostConfig.expand=Expanding web application archive {0}
 hostConfig.expand.error=Exception while expanding web application archive {0}
 hostConfig.expanding=Expanding discovered web application archives
+hostConfig.ignorePath=Ignoring path [{0}] in appBase for automatic deployment
 hostConfig.illegalWarName=The war name [{0}] is invalid. The archive will be 
ignored.
 hostConfig.jmx.register=Register context [{0}] failed
 hostConfig.jmx.unregister=Unregister context [{0}] failed

Modified: tomcat/trunk/webapps/docs/config/host.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/host.xml?rev=1057275&r1=1057274&r2=1057275&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/host.xml (original)
+++ tomcat/trunk/webapps/docs/config/host.xml Mon Jan 10 16:48:25 2011
@@ -144,6 +144,22 @@
         If not specified, the standard value (defined below) will be used.</p>
       </attribute>
 
+      <attribute name="deployIgnore" required="false">
+        <p>A regular expression defining paths to ignore when
+        <code>autoDeploy</code> and <code>deployOnStartup</code> are set. This
+        allows you to keep your configuration in a version control system, for
+        example, and not deploy a .svn or CVS folder that happens to be in the
+        <code>appBase</code>.</p>
+        <p>This regular expression is relative to <code>appBase</code>. It is
+        also <em>anchored</em>, meaning the match is performed against the
+        entire file/directory name. So, <code>foo</code> matches only a file or
+        directory named <code>foo</code> but not <code>foo.war</code>,
+        <code>foobar</code>, or <code>myfooapp</code>. To match anything with
+        &quot;foo&quot;, you could use <code>.*foo.*</code>.</p>
+        <p>See <a href="#Automatic Application Deployment">Automatic 
Application
+        Deployment</a> for more information.</p>
+      </attribute>
+
       <attribute name="deployOnStartup" required="false">
         <p>This flag value indicates if web applications from this host should
         be automatically deployed when Tomcat starts. The flag's value defaults
@@ -337,14 +353,15 @@
         <code>ROOT.xml</code>.</li>
     <li>Any web application archive file within the Host's <code>appBase</code>
         directory that has not already been deployed as a result of a context
-        XML descriptor and does not have a corresponding directory of the same
-        name (without the ".war" extension) will be deployed next. The context
-        path used will be a slash character ("/") followed by the web
-        application archive name less the ".war" extension. The one exception 
to
-        this rule is that a web application archive named "ROOT.war" will be
-        deployed with a context path of <code>/</code>. Multi-level contexts 
may
-        be defined by using #, e.g. use a WAR named <code>foo#bar.war</code> 
for
-        a context path of <code>/foo/bar</code>.<br/>
+        XML descriptor, does not have a corresponding directory of the same
+        name (without the ".war" extension), and is not excluded by
+        <code>deployIgnore</code> will be deployed next. The context path
+        used will be a slash character ("/") followed by the web application
+        archive name less the ".war" extension. The one exception to this rule
+        is that a web application archive named "ROOT.war" will be deployed 
with
+        a context path of <code>/</code>. Multi-level contexts may be defined 
by
+        using #, e.g. use a WAR named <code>foo#bar.war</code> for a context
+        path of <code>/foo/bar</code>.<br/>
         If the <code>unpackWARs</code> attribute is <code>true</code>, the web
         application archive file will be expanded to a directory of the same
         name (without the ".war" extension".<br/>
@@ -363,11 +380,12 @@
         </li>
     <li>Finally, any sub-directory within the Host's <code>appBase</code> that
         has not already been deployed as a result of a context XML descriptor
-        will be deployed. The context path used will be a slash character
-        ("/") followed by the directory name, unless the directory name is 
ROOT,
-        in which case the context path will <code>/</code>. Multi-level 
contexts
-        may be defined by using #, e.g. use a directory named
-        <code>foo#bar</code> for a context path of <code>/foo/bar</code>.<br/>
+        and is not excluded by <code>deployIgnore</code> will be deployed.
+        The context path used will be a slash character ("/") followed by the
+        directory name, unless the directory name is ROOT, in which case the
+        context path will <code>/</code>. Multi-level contexts may be defined 
by
+        using #, e.g. use a directory named <code>foo#bar</code> for a context
+        path of <code>/foo/bar</code>.<br/>
         If <code>copyXml</code> is <code>true</code> (it is <code>false</code>
         by default), any directory within the Hosts's <code>appBase</code>
         directory that does not have a corresponding context XML descriptor in
@@ -420,15 +438,16 @@
 
     <p>When using automatic deployment, the <code>docBase</code> defined by
     an XML <a href="context.html">Context</a> file should be outside of the
-    <code>appBase</code> directory. If this is not the case difficulties
+    <code>appBase</code> directory. If this is not the case, difficulties
     may be experienced deploying the web application or the application may
-    be deployed twice.</p>
+    be deployed twice. The <code>deployIgnore</code> attribute can be used
+    to avoid this situation.</p>
 
     <p>Finally, note that if you are defining contexts explicitly in 
server.xml,
-    you should probably turn off automatic application deployment.  Otherwise,
-    the web applications will each be deployed twice, and that may cause
-    problems for the applications.
-    </p>
+    you should probably turn off automatic application deployment or specify
+    <code>deployIgnore</code> carefully. Otherwise, the web applications
+    will each be deployed twice, and that may cause problems for the
+    applications.</p>
 
   </subsection>
 



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

Reply via email to