From: markt
Date: Mon, 10 Jan 2011 16:48:25 +0000 (+0000)
Subject: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50205
X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=21673b31e918979d1373a55c497fe2e3e2f00932;p=tomcat7.0
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50205
Add deployIgnore to Host
Based on a patch by Jim Riggs
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1057275 13f79535-47bb-0310-9956-ffa450edef68
---
diff --git a/java/org/apache/catalina/Host.java b/java/org/apache/catalina/Host.java
index b2e78796a..37b1f9846 100644
--- a/java/org/apache/catalina/Host.java
+++ b/java/org/apache/catalina/Host.java
@@ -14,12 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.catalina;
-
/**
* A Host 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
diff --git a/java/org/apache/catalina/core/StandardHost.java b/java/org/apache/catalina/core/StandardHost.java
index 1d7422ce2..d7a60552a 100644
--- a/java/org/apache/catalina/core/StandardHost.java
+++ b/java/org/apache/catalina/core/StandardHost.java
@@ -168,6 +168,14 @@ public class StandardHost extends ContainerBase implements Host {
new WeakHashMap();
+ /**
+ * 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 ContainerBase implements Host {
this.errorReportValveClass);
}
-
-
+
+
/**
* Return the canonical, fully qualified, name of the virtual host
* this Container represents.
@@ -500,6 +508,32 @@ public class StandardHost extends ContainerBase implements Host {
}
+ /**
+ * 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
diff --git a/java/org/apache/catalina/core/mbeans-descriptors.xml b/java/org/apache/catalina/core/mbeans-descriptors.xml
index 864770aad..b9253c2c2 100644
--- a/java/org/apache/catalina/core/mbeans-descriptors.xml
+++ b/java/org/apache/catalina/core/mbeans-descriptors.xml
@@ -1164,6 +1164,10 @@
description="Should we create directories upon startup for appBase and xmlBase? "
type="boolean"/>
+
+
diff --git a/java/org/apache/catalina/startup/HostConfig.java b/java/org/apache/catalina/startup/HostConfig.java
index 66596dd60..696d47473 100644
--- a/java/org/apache/catalina/startup/HostConfig.java
+++ b/java/org/apache/catalina/startup/HostConfig.java
@@ -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 filteredList = new ArrayList();
+ 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.
*/
diff --git a/java/org/apache/catalina/startup/LocalStrings.properties b/java/org/apache/catalina/startup/LocalStrings.properties
index 67a5b8ad7..cac771b69 100644
--- a/java/org/apache/catalina/startup/LocalStrings.properties
+++ b/java/org/apache/catalina/startup/LocalStrings.properties
@@ -88,6 +88,7 @@ hostConfig.deploying=Deploying discovered web applications
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
diff --git a/webapps/docs/config/host.xml b/webapps/docs/config/host.xml
index 57d93be65..36069fb41 100644
--- a/webapps/docs/config/host.xml
+++ b/webapps/docs/config/host.xml
@@ -144,6 +144,22 @@
If not specified, the standard value (defined below) will be used.
+
+ A regular expression defining paths to ignore when
+ autoDeploy and deployOnStartup 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
+ appBase.
+ This regular expression is relative to appBase. It is
+ also anchored, meaning the match is performed against the
+ entire file/directory name. So, foo matches only a file or
+ directory named foo but not foo.war,
+ foobar, or myfooapp. To match anything with
+ "foo", you could use .*foo.*.
+ See Automatic Application
+ Deployment for more information.
+
+
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 @@
ROOT.xml.
Any web application archive file within the Host's appBase
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 /. Multi-level contexts may
- be defined by using #, e.g. use a WAR named foo#bar.war for
- a context path of /foo/bar.
+ XML descriptor, does not have a corresponding directory of the same
+ name (without the ".war" extension), and is not excluded by
+ deployIgnore 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 /. Multi-level contexts may be defined by
+ using #, e.g. use a WAR named foo#bar.war for a context
+ path of /foo/bar.
If the unpackWARs attribute is true, the web
application archive file will be expanded to a directory of the same
name (without the ".war" extension".
@@ -363,11 +380,12 @@
Finally, any sub-directory within the Host's appBase 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 /. Multi-level contexts
- may be defined by using #, e.g. use a directory named
- foo#bar for a context path of /foo/bar.
+ and is not excluded by deployIgnore 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 /. Multi-level contexts may be defined by
+ using #, e.g. use a directory named foo#bar for a context
+ path of /foo/bar.
If copyXml is true (it is false
by default), any directory within the Hosts's appBase
directory that does not have a corresponding context XML descriptor in
@@ -420,15 +438,16 @@
When using automatic deployment, the docBase defined by
an XML Context file should be outside of the
- appBase directory. If this is not the case difficulties
+ appBase directory. If this is not the case, difficulties
may be experienced deploying the web application or the application may
- be deployed twice.
+ be deployed twice. The deployIgnore attribute can be used
+ to avoid this situation.
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.
-
+ you should probably turn off automatic application deployment or specify
+ deployIgnore carefully. Otherwise, the web applications
+ will each be deployed twice, and that may cause problems for the
+ applications.