Author: markt
Date: Tue Jan 18 17:01:07 2011
New Revision: 1060467

URL: http://svn.apache.org/viewvc?rev=1060467&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 (markt/kkolinko)

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

Modified: tomcat/tc6.0.x/trunk/STATUS.txt
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=1060467&r1=1060466&r2=1060467&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/STATUS.txt (original)
+++ tomcat/tc6.0.x/trunk/STATUS.txt Tue Jan 18 17:01:07 2011
@@ -145,15 +145,3 @@ PATCHES PROPOSED TO BACKPORT:
   http://svn.apache.org/viewvc?rev=1056889&view=rev
   +1: kkolinko, markt, kfujino
   -1:
-
-* Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50205
-  Add deployIgnore to Host
-  Based on a patch by Jim Riggs
-  http://svn.apache.org/viewvc?rev=1057275&view=rev
-  +1: markt
-  -1:
-
-  Updated patch (merge of revs.1057275,1057788,1057990):
-  http://people.apache.org/~kkolinko/patches/2011-01-17_tc6_50205.patch
-  +1: kkolinko, kfujino
-  -1:

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/Host.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/Host.java?rev=1060467&r1=1060466&r2=1060467&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/Host.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/Host.java Tue Jan 18 17:01:07 
2011
@@ -14,10 +14,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-
 package org.apache.catalina;
 
+import java.util.regex.Pattern;
 
 
 /**
@@ -181,6 +180,30 @@ public interface Host extends Container 
     public void setXmlNamespaceAware(boolean xmlNamespaceAware);
 
 
+    /**
+     * 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();
+
+
+    /**
+     * Return the compiled regular expression that defines the files and
+     * directories in the host's {@link #appBase} that will be ignored by the
+     * automatic deployment process.
+     */
+    public Pattern getDeployIgnorePattern();
+
+
+    /**
+     * 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/tc6.0.x/trunk/java/org/apache/catalina/core/StandardHost.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardHost.java?rev=1060467&r1=1060466&r2=1060467&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardHost.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardHost.java Tue 
Jan 18 17:01:07 2011
@@ -23,6 +23,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.WeakHashMap;
+import java.util.regex.Pattern;
 
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
@@ -180,6 +181,14 @@ public class StandardHost
      private Map<ClassLoader, String> childClassLoaders =
          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 Pattern deployIgnore = null;
+
+
     // ------------------------------------------------------------- Properties
 
 
@@ -384,8 +393,8 @@ public class StandardHost
                                    this.errorReportValveClass);
 
     }
-
-
+    
+    
     /**
      * Return the canonical, fully qualified, name of the virtual host
      * this Container represents.
@@ -496,6 +505,52 @@ public class StandardHost
     }
 
 
+    /**
+     * 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() {
+        if (deployIgnore == null) {
+            return null;
+        } 
+        return this.deployIgnore.toString();
+    }
+
+
+    /**
+     * Return the compiled regular expression that defines the files and
+     * directories in the host's {@link #appBase} that will be ignored by the
+     * automatic deployment process.
+     */
+    public Pattern getDeployIgnorePattern() {
+        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.
+     */
+    public void setDeployIgnore(String deployIgnore) {
+        String oldDeployIgnore;
+        if (this.deployIgnore == null) {
+            oldDeployIgnore = null;
+        } else {
+            oldDeployIgnore = this.deployIgnore.toString();
+        }
+        if (deployIgnore == null) {
+            this.deployIgnore = null;
+        } else {
+            this.deployIgnore = Pattern.compile(deployIgnore);
+        }
+        support.firePropertyChange("deployIgnore",
+                                   oldDeployIgnore, 
+                                   deployIgnore);
+    }
+
+
     // --------------------------------------------------------- Public Methods
 
 

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml?rev=1060467&r1=1060466&r2=1060467&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml 
Tue Jan 18 17:01:07 2011
@@ -466,6 +466,10 @@
                description="The configuration class for contexts"
                type="java.lang.String"/>
       
+    <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/tc6.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java?rev=1060467&r1=1060466&r2=1060467&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java Tue 
Jan 18 17:01:07 2011
@@ -30,9 +30,12 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Set;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.management.ObjectName;
 
@@ -494,17 +497,52 @@ 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) {
+        Pattern filter = host.getDeployIgnorePattern();
+        if (filter == null) {
+            return unfilteredAppPaths;
+        }
+
+        List<String> filteredList = new ArrayList<String>();
+        Matcher matcher = null;
+        for (String appPath : unfilteredAppPaths) {
+            if (matcher == null) {
+                matcher = filter.matcher(appPath);
+            } else {
+                matcher.reset(appPath);
+            }
+            if (matcher.matches()) {
+                if (log.isDebugEnabled()) {
+                    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/tc6.0.x/trunk/java/org/apache/catalina/startup/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/LocalStrings.properties?rev=1060467&r1=1060466&r2=1060467&view=diff
==============================================================================
--- 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/LocalStrings.properties 
(original)
+++ 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/LocalStrings.properties 
Tue Jan 18 17:01:07 2011
@@ -80,6 +80,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/tc6.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=1060467&r1=1060466&r2=1060467&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Tue Jan 18 17:01:07 2011
@@ -44,6 +44,14 @@
  General, Catalina, Coyote, Jasper, Cluster, Webapps, Other
 -->
 <section name="Tomcar 6.0.31 (jfclere)">
+  <subsection name="Catalina">
+    <changelog>
+      <add>
+        <bug>50205</bug>: Add the deployIgnorePaths attribute to the Host
+        element. Based on a patch by Jim Riggs. (markt/kkolinko)
+      </add>
+    </changelog>
+  </subsection>
   <subsection name="Cluster">
     <changelog>
       <fix>

Modified: tomcat/tc6.0.x/trunk/webapps/docs/config/host.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/config/host.xml?rev=1060467&r1=1060466&r2=1060467&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/config/host.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/config/host.xml Tue Jan 18 17:01:07 2011
@@ -125,6 +125,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
@@ -306,14 +322,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/>
@@ -333,11 +350,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/>
         Any directory within the Hosts's <code>appBase</code> directory that
         does not have a corresponding context XML descriptor in
         <code>$CATALINA_BASE/conf/[engine_name]/[host_name]</code> will be
@@ -390,15 +408,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