ASF Bugzilla – Attachment 26251 Details for
Bug 50205
Add deployIgnorePaths attribute to StandardHost
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
deployIgnorePaths v1
deployIgnorePaths.patch (text/plain), 12.09 KB, created by
Jim Riggs
on 2010-11-03 13:20:27 UTC
(
hide
)
Description:
deployIgnorePaths v1
Filename:
MIME Type:
Creator:
Jim Riggs
Created:
2010-11-03 13:20:27 UTC
Size:
12.09 KB
patch
obsolete
>Index: java/org/apache/catalina/core/StandardHost.java >=================================================================== >--- java/org/apache/catalina/core/StandardHost.java (revision 1030113) >+++ java/org/apache/catalina/core/StandardHost.java (working copy) >@@ -18,10 +18,13 @@ > > > import java.util.ArrayList; >+import java.util.Arrays; > import java.util.List; >+import java.util.ListIterator; > import java.util.Locale; > import java.util.Map; > import java.util.WeakHashMap; >+import java.util.regex.Pattern; > > import org.apache.catalina.Container; > import org.apache.catalina.Context; >@@ -110,6 +113,18 @@ > > > /** >+ * The ignored deploy paths for this Host. >+ */ >+ private String deployIgnorePaths = ""; >+ >+ >+ /** >+ * The ignored deploy path Patterns for this Host. >+ */ >+ private ArrayList<Pattern> deployIgnorePathPatterns = new ArrayList<Pattern>(); >+ >+ >+ /** > * The deploy on startup flag for this Host. > */ > private boolean deployOnStartup = true; >@@ -327,6 +342,53 @@ > > > /** >+ * Return the list of regular expressions for files/directories >+ * excluded from automatic deployment. >+ */ >+ public String getDeployIgnorePaths() { >+ >+ return (this.deployIgnorePaths); >+ >+ } >+ >+ >+ /** >+ * Set the list of regular expressions for files/directories >+ * excluded from automatic deployment. >+ * >+ * @param ignorePaths A comma-separated list of regular >+ * expression strings. >+ */ >+ public void setDeployIgnorePaths(String ignorePaths) { >+ >+ String oldDeployIgnorePaths = this.deployIgnorePaths; >+ List<String> newPaths = Arrays.asList(ignorePaths.split("\\s*,\\s*")); >+ ArrayList<Pattern> newPatterns = new ArrayList<Pattern>(newPaths.size()); >+ >+ for (ListIterator<String> i = newPaths.listIterator(); i.hasNext(); ) { >+ newPatterns.add(Pattern.compile(i.next())); >+ } >+ >+ this.deployIgnorePaths = ignorePaths; >+ this.deployIgnorePathPatterns = newPatterns; >+ support.firePropertyChange("deployIgnorePaths", oldDeployIgnorePaths, >+ this.deployIgnorePaths); >+ >+ } >+ >+ >+ /** >+ * Return the list of Patterns for files/directories excluded from >+ * automatic deployment. >+ */ >+ public ArrayList<Pattern> getDeployIgnorePathPatterns() { >+ >+ return (this.deployIgnorePathPatterns); >+ >+ } >+ >+ >+ /** > * Return the value of the deploy on startup flag. If true, it indicates > * that this host's child webapps should be discovered and automatically > * deployed at startup time. >Index: java/org/apache/catalina/core/mbeans-descriptors.xml >=================================================================== >--- java/org/apache/catalina/core/mbeans-descriptors.xml (revision 1030113) >+++ java/org/apache/catalina/core/mbeans-descriptors.xml (working copy) >@@ -1160,6 +1160,10 @@ > description="Should we create directories upon startup for appBase and xmlBase? " > type="boolean"/> > >+ <attribute name="deployIgnorePaths" >+ description="Paths within appBase ignored for deployment" >+ type="java.lang.String"/> >+ > <attribute name="deployOnStartup" > description="The deploy on startup flag for this Host" > type="boolean"/> >Index: java/org/apache/catalina/startup/HostConfig.java >=================================================================== >--- java/org/apache/catalina/startup/HostConfig.java (revision 1030113) >+++ java/org/apache/catalina/startup/HostConfig.java (working copy) >@@ -28,13 +28,16 @@ > import java.io.OutputStream; > import java.net.URL; > import java.util.ArrayList; >+import java.util.Arrays; > import java.util.HashMap; > import java.util.HashSet; > import java.util.LinkedHashMap; >+import java.util.ListIterator; > 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 +463,65 @@ > > File appBase = appBase(); > File configBase = configBase(); >+ String[] fileList = validAppPaths(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, fileList); > // Deploy expanded folders >- deployDirectories(appBase, appBase.list()); >+ deployDirectories(appBase, fileList); > > } > > > /** >+ * Return the provided array of paths after removing those matching regular >+ * expressions configured via the Host's deployIgnorePaths. >+ * >+ * @param paths The file paths to be checked, presumably those within >+ * appBase. >+ * @return A String array containing the path list after excluding ignored >+ * paths. >+ */ >+ protected String[] validAppPaths(String[] paths) { >+ >+ if (!(host instanceof StandardHost)) { >+ return paths; >+ } >+ >+ ArrayList<Pattern> ignorePatterns = ((StandardHost) host).getDeployIgnorePathPatterns(); >+ >+ if ((ignorePatterns == null) || (ignorePatterns.size() == 0)) { >+ return paths; >+ } >+ >+ ArrayList<String> goodPaths = new ArrayList<String>(Arrays.asList(paths)); >+ >+ for (ListIterator<String> i = goodPaths.listIterator(); i.hasNext(); ) { >+ String path = i.next(); >+ >+ for (ListIterator<Pattern> j = ignorePatterns.listIterator(); j.hasNext(); ) { >+ Pattern ignorePattern = j.next(); >+ >+ if (ignorePattern.matcher(path).matches()) { >+ if(log.isDebugEnabled()) { >+ log.debug("Ignoring application path \"" >+ + path + "\" (matches pattern \"" >+ + ignorePattern.pattern() + "\")."); >+ } >+ >+ i.remove(); >+ break; >+ } >+ } >+ } >+ >+ return goodPaths.toArray(new String[0]); >+ >+ } >+ >+ >+ /** > * Deploy applications for any directories or WAR files that are found > * in our "application root" directory. > */ >Index: webapps/docs/config/host.xml >=================================================================== >--- webapps/docs/config/host.xml (revision 1030113) >+++ webapps/docs/config/host.xml (working copy) >@@ -189,6 +189,27 @@ > is <code>false</code>, this attribute will have no effect.</p> > </attribute> > >+ <attribute name="deployIgnorePaths" required="false"> >+ <p>A comma-separated list of regular expressions of paths to >+ <em>ignore</em> for <code>autoDeploy</code> and >+ <code>deployOnStartup</code>. 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 <code>appBase</code>.</p> >+ <p>These regular expressions are relative to <code>appBase</code>. They >+ are 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 >+ "foo", you would use something like <code>.*foo.*</code>.</p> >+ <p>From a performance standpoint, a single regular expression using >+ alternation will be more efficient than separate regular expressions. >+ For example, <code>deployIgnorePaths</code> set to >+ <code>foo\.war|bar</code> has the same effect as >+ <code>foo\.war,bar</code>, but the former is more efficient.</p> >+ <p>See <a href="#Automatic Application Deployment">Automatic Application >+ Deployment</a> for more information.</p> >+ </attribute> >+ > <attribute name="deployXML" required="false"> > <p>Set to <code>false</code> if you want to disable parsing the context > XML descriptor embedded inside the application (located at >@@ -337,14 +358,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>deployIgnorePaths</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 +385,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>deployIgnorePaths</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 +443,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>deployIgnorePaths</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>deployIgnorePaths</code> carefully. Otherwise, the web applications >+ will each be deployed twice, and that may cause problems for the >+ applications.</p> > > </subsection> >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 50205
: 26251 |
26258