From: markt Date: Mon, 15 Aug 2011 18:50:25 +0000 (+0000) Subject: Clean-up I do not intend to back-port (non-critical and changes the Host API) X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=ed84edc0b5c56689e8b321524e1172425fe4112c;p=tomcat7.0 Clean-up I do not intend to back-port (non-critical and changes the Host API) git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1157943 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/Host.java b/java/org/apache/catalina/Host.java index e410762e3..72f5dc2e4 100644 --- a/java/org/apache/catalina/Host.java +++ b/java/org/apache/catalina/Host.java @@ -16,6 +16,7 @@ */ package org.apache.catalina; +import java.io.File; import java.util.regex.Pattern; @@ -83,7 +84,7 @@ public interface Host extends Container { */ public void setXmlBase(String xmlBase); - /** + /** * Return the application root for this Host. This can be an absolute * pathname, a relative pathname, or a URL. */ @@ -91,6 +92,14 @@ public interface Host extends Container { /** + * Return an absolute {@link File} for the appBase of this Host. The file + * will be canonical if possible. There is no guarantee that that the + * appBase exists. + */ + public File getAppBaseFile(); + + + /** * Set the application root for this Host. This can be an absolute * pathname, a relative pathname, or a URL. * diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java index 4e68f4e06..5d98b9b10 100644 --- a/java/org/apache/catalina/core/StandardContext.java +++ b/java/org/apache/catalina/core/StandardContext.java @@ -5857,10 +5857,7 @@ public class StandardContext extends ContainerBase docBase = (new File(engineBase(), getDocBase())).getPath(); } else { // Use the "appBase" property of this container - String appBase = ((Host) container).getAppBase(); - file = new File(appBase); - if (!file.isAbsolute()) - file = new File(engineBase(), appBase); + file = ((Host) container).getAppBaseFile(); docBase = (new File(file, getDocBase())).getPath(); } } else { diff --git a/java/org/apache/catalina/core/StandardHost.java b/java/org/apache/catalina/core/StandardHost.java index c78dbe9cb..3b1fb50cc 100644 --- a/java/org/apache/catalina/core/StandardHost.java +++ b/java/org/apache/catalina/core/StandardHost.java @@ -17,6 +17,8 @@ package org.apache.catalina.core; +import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -26,6 +28,7 @@ import java.util.regex.Pattern; import org.apache.catalina.Container; import org.apache.catalina.Context; +import org.apache.catalina.Globals; import org.apache.catalina.Host; import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleEvent; @@ -82,6 +85,7 @@ public class StandardHost extends ContainerBase implements Host { * The application root for this Host. */ private String appBase = "webapps"; + private volatile File appBaseFile = null; /** * The XML root for this Host. @@ -186,23 +190,41 @@ public class StandardHost extends ContainerBase implements Host { */ @Override public String getAppBase() { - return (this.appBase); - } + /** - * Return the XML root for this Host. This can be an absolute - * pathname, a relative pathname, or a URL. - * If null, defaults to ${catalina.base}/conf/ directory + * ({@inheritDoc} */ @Override - public String getXmlBase() { + public File getAppBaseFile() { + + if (appBaseFile != null) { + return appBaseFile; + } - return (this.xmlBase); + File file = new File(getAppBase()); + + // If not absolute, make it absolute + if (!file.isAbsolute()) { + // This system property should always be set + file = new File(System.getProperty(Globals.CATALINA_BASE_PROP), + file.getPath()); + } + + // Make it canonical if possible + try { + file = file.getCanonicalFile(); + } catch (IOException ioe) { + // Ignore + } + this.appBaseFile = file; + return file; } + /** * Set the application root for this Host. This can be an absolute * pathname, a relative pathname, or a URL. @@ -215,9 +237,23 @@ public class StandardHost extends ContainerBase implements Host { String oldAppBase = this.appBase; this.appBase = appBase; support.firePropertyChange("appBase", oldAppBase, this.appBase); + this.appBaseFile = null; + } + + + /** + * Return the XML root for this Host. This can be an absolute + * pathname, a relative pathname, or a URL. + * If null, defaults to ${catalina.base}/conf/ directory + */ + @Override + public String getXmlBase() { + + return (this.xmlBase); } - + + /** * Set the Xml root for this Host. This can be an absolute * pathname, a relative pathname, or a URL. @@ -234,6 +270,7 @@ public class StandardHost extends ContainerBase implements Host { } + /** * Returns true if the Host will attempt to create directories for appBase and xmlBase * unless they already exist. diff --git a/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java b/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java index f4d872993..ca82b6468 100644 --- a/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java +++ b/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java @@ -495,29 +495,6 @@ public class FarmWarDeployer extends ClusterListener } /** - * Return a File object representing the "application root" directory for - * our associated Host. - */ - protected File getAppBase() { - - if (appBase != null) { - return appBase; - } - - File file = new File(host.getAppBase()); - if (!file.isAbsolute()) - file = new File(System.getProperty(Globals.CATALINA_BASE_PROP), host - .getAppBase()); - try { - appBase = file.getCanonicalFile(); - } catch (IOException e) { - appBase = file; - } - return (appBase); - - } - - /** * Invoke the remove method on the deployer. */ protected void remove(String contextName) throws Exception { @@ -530,8 +507,8 @@ public class FarmWarDeployer extends ClusterListener contextName)); context.stop(); String baseName = context.getBaseName(); - File war = new File(getAppBase(), baseName + ".war"); - File dir = new File(getAppBase(), baseName); + File war = new File(host.getAppBaseFile(), baseName + ".war"); + File dir = new File(host.getAppBaseFile(), baseName); File xml = new File(configBase, baseName + ".xml"); if (war.exists()) { if (!war.delete()) { diff --git a/java/org/apache/catalina/manager/HTMLManagerServlet.java b/java/org/apache/catalina/manager/HTMLManagerServlet.java index eb4ca9760..57ff35356 100644 --- a/java/org/apache/catalina/manager/HTMLManagerServlet.java +++ b/java/org/apache/catalina/manager/HTMLManagerServlet.java @@ -308,7 +308,7 @@ public final class HTMLManagerServlet extends ManagerServlet { // Identify the appBase of the owning Host of this Context // (if any) - File file = new File(getAppBase(), filename); + File file = new File(host.getAppBaseFile(), filename); if (file.exists()) { message = smClient.getString( "htmlManagerServlet.deployUploadWarExists", diff --git a/java/org/apache/catalina/manager/ManagerServlet.java b/java/org/apache/catalina/manager/ManagerServlet.java index 12bcb6083..c8e82e199 100644 --- a/java/org/apache/catalina/manager/ManagerServlet.java +++ b/java/org/apache/catalina/manager/ManagerServlet.java @@ -473,12 +473,7 @@ public class ManagerServlet extends HttpServlet implements ContainerServlet { // Identify the appBase of the owning Host of this Context // (if any) - String appBase = ((Host) context.getParent()).getAppBase(); - deployed = new File(appBase); - if (!deployed.isAbsolute()) { - deployed = new File(System.getProperty(Globals.CATALINA_BASE_PROP), - appBase); - } + deployed = ((Host) context.getParent()).getAppBaseFile(); configBase = new File(System.getProperty(Globals.CATALINA_BASE_PROP), "conf"); Container container = context; Container host = null; @@ -667,7 +662,7 @@ public class ManagerServlet extends HttpServlet implements ContainerServlet { File localWarCopy = new File(deployedPath, baseName + ".war"); copy(localWar, localWarCopy); localWar = localWarCopy; - copy(localWar, new File(getAppBase(), baseName + ".war")); + copy(localWar, new File(host.getAppBaseFile(), baseName + ".war")); } // Perform new deployment check(name); @@ -735,7 +730,7 @@ public class ManagerServlet extends HttpServlet implements ContainerServlet { if (!isServiced(name)) { addServiced(name); try { - copy(localWar, new File(getAppBase(), baseName + ".war")); + copy(localWar, new File(host.getAppBaseFile(), baseName + ".war")); // Perform new deployment check(name); } finally { @@ -846,10 +841,10 @@ public class ManagerServlet extends HttpServlet implements ContainerServlet { if (war != null) { if (war.endsWith(".war")) { copy(new File(war), - new File(getAppBase(), baseName + ".war")); + new File(host.getAppBaseFile(), baseName + ".war")); } else { copy(new File(war), - new File(getAppBase(), baseName)); + new File(host.getAppBaseFile(), baseName)); } } // Perform new deployment @@ -1352,8 +1347,8 @@ public class ManagerServlet extends HttpServlet implements ContainerServlet { ExceptionUtils.handleThrowable(t); } try { - File war = new File(getAppBase(), baseName + ".war"); - File dir = new File(getAppBase(), baseName); + File war = new File(host.getAppBaseFile(), baseName + ".war"); + File dir = new File(host.getAppBaseFile(), baseName); File xml = new File(configBase, baseName + ".xml"); if (war.exists() && !war.delete()) { writer.println(smClient.getString( @@ -1390,30 +1385,6 @@ public class ManagerServlet extends HttpServlet implements ContainerServlet { /** - * Return a File object representing the "application root" directory - * for our associated Host. - */ - protected File getAppBase() { - - if (appBase != null) { - return appBase; - } - - File file = new File(host.getAppBase()); - if (!file.isAbsolute()) - file = new File(System.getProperty(Globals.CATALINA_BASE_PROP), - host.getAppBase()); - try { - appBase = file.getCanonicalFile(); - } catch (IOException e) { - appBase = file; - } - return (appBase); - - } - - - /** * Invoke the isDeployed method on the deployer. */ protected boolean isDeployed(String name) diff --git a/java/org/apache/catalina/startup/ContextConfig.java b/java/org/apache/catalina/startup/ContextConfig.java index 334f3cb71..bb1740658 100644 --- a/java/org/apache/catalina/startup/ContextConfig.java +++ b/java/org/apache/catalina/startup/ContextConfig.java @@ -688,16 +688,7 @@ public class ContextConfig throws IOException { Host host = (Host) context.getParent(); - String appBase = host.getAppBase(); - - File canonicalAppBase = new File(appBase); - if (canonicalAppBase.isAbsolute()) { - canonicalAppBase = canonicalAppBase.getCanonicalFile(); - } else { - canonicalAppBase = - new File(System.getProperty(Globals.CATALINA_BASE_PROP), appBase) - .getCanonicalFile(); - } + File appBase = host.getAppBaseFile(); String docBase = context.getDocBase(); if (docBase == null) { @@ -712,7 +703,7 @@ public class ContextConfig File file = new File(docBase); if (!file.isAbsolute()) { - docBase = (new File(canonicalAppBase, docBase)).getPath(); + docBase = (new File(appBase, docBase)).getPath(); } else { docBase = file.getCanonicalPath(); } @@ -727,7 +718,7 @@ public class ContextConfig if (host instanceof StandardHost) { unpackWARs = ((StandardHost) host).isUnpackWARs() && ((StandardContext) context).getUnpackWAR() && - (docBase.startsWith(canonicalAppBase.getPath())); + (docBase.startsWith(host.getAppBaseFile().getPath())); } if (docBase.toLowerCase(Locale.ENGLISH).endsWith(".war") && !file.isDirectory() && unpackWARs) { @@ -765,8 +756,8 @@ public class ContextConfig } } - if (docBase.startsWith(canonicalAppBase.getPath() + File.separatorChar)) { - docBase = docBase.substring(canonicalAppBase.getPath().length()); + if (docBase.startsWith(appBase.getPath() + File.separatorChar)) { + docBase = docBase.substring(appBase.getPath().length()); docBase = docBase.replace(File.separatorChar, '/'); if (docBase.startsWith("/")) { docBase = docBase.substring(1); @@ -786,7 +777,6 @@ public class ContextConfig && ((StandardContext) context).getAntiResourceLocking()) { Host host = (Host) context.getParent(); - String appBase = host.getAppBase(); String docBase = context.getDocBase(); if (docBase == null) return; @@ -797,11 +787,7 @@ public class ContextConfig } File docBaseFile = new File(docBase); if (!docBaseFile.isAbsolute()) { - File file = new File(appBase); - if (!file.isAbsolute()) { - file = new File(System.getProperty(Globals.CATALINA_BASE_PROP), appBase); - } - docBaseFile = new File(file, docBase); + docBaseFile = new File(host.getAppBaseFile(), docBase); } String path = context.getPath(); @@ -1077,12 +1063,11 @@ public class ContextConfig // Remove (partially) folders and files created by antiLocking Host host = (Host) context.getParent(); - String appBase = host.getAppBase(); String docBase = context.getDocBase(); if ((docBase != null) && (originalDocBase != null)) { File docBaseFile = new File(docBase); if (!docBaseFile.isAbsolute()) { - docBaseFile = new File(appBase, docBase); + docBaseFile = new File(host.getAppBaseFile(), docBase); } // No need to log failure - it is expected in this case ExpandWar.delete(docBaseFile, false); diff --git a/java/org/apache/catalina/startup/ExpandWar.java b/java/org/apache/catalina/startup/ExpandWar.java index 43f34d3f5..4bdd6f606 100644 --- a/java/org/apache/catalina/startup/ExpandWar.java +++ b/java/org/apache/catalina/startup/ExpandWar.java @@ -31,7 +31,6 @@ import java.util.Enumeration; import java.util.jar.JarEntry; import java.util.jar.JarFile; -import org.apache.catalina.Globals; import org.apache.catalina.Host; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; @@ -77,18 +76,7 @@ public class ExpandWar { throws IOException { // Make sure that there is no such directory already existing - File appBase = new File(host.getAppBase()); - if (!appBase.isAbsolute()) { - appBase = new File(System.getProperty(Globals.CATALINA_BASE_PROP), - host.getAppBase()); - } - if (!appBase.exists() || !appBase.isDirectory()) { - throw new IOException - (sm.getString("hostConfig.appBase", - appBase.getAbsolutePath())); - } - - File docBase = new File(appBase, pathname); + File docBase = new File(host.getAppBaseFile(), pathname); if (docBase.exists()) { // War file is already installed return (docBase.getAbsolutePath()); @@ -193,14 +181,7 @@ public class ExpandWar { public static void validate(Host host, URL war, String pathname) throws IOException { - // Make the appBase absolute - File appBase = new File(host.getAppBase()); - if (!appBase.isAbsolute()) { - appBase = new File(System.getProperty(Globals.CATALINA_BASE_PROP), - host.getAppBase()); - } - - File docBase = new File(appBase, pathname); + File docBase = new File(host.getAppBaseFile(), pathname); // Calculate the document base directory String canonicalDocBasePrefix = docBase.getCanonicalPath(); diff --git a/java/org/apache/catalina/startup/HostConfig.java b/java/org/apache/catalina/startup/HostConfig.java index a52bccc20..2cefbb985 100644 --- a/java/org/apache/catalina/startup/HostConfig.java +++ b/java/org/apache/catalina/startup/HostConfig.java @@ -78,12 +78,6 @@ public class HostConfig /** - * App base. - */ - protected File appBase = null; - - - /** * Config base. */ protected File configBase = null; @@ -404,22 +398,6 @@ public class HostConfig /** - * Return a File object representing the "application root" directory - * for our associated Host. - */ - protected File appBase() { - - if (appBase != null) { - return appBase; - } - - appBase = returnCanonicalPath(host.getAppBase()); - return appBase; - - } - - - /** * Return a File object representing the "configuration root" directory * for our associated Host. */ @@ -461,7 +439,7 @@ public class HostConfig */ protected void deployApps() { - File appBase = appBase(); + File appBase = host.getAppBaseFile(); File configBase = configBase(); String[] filteredAppPaths = filterAppPaths(appBase.list()); // Deploy XML descriptors from configBase @@ -514,7 +492,7 @@ public class HostConfig */ protected void deployApps(String name) { - File appBase = appBase(); + File appBase = host.getAppBaseFile(); File configBase = configBase(); ContextName cn = new ContextName(name); String baseName = cn.getBaseName(); @@ -609,11 +587,11 @@ public class HostConfig if (context.getDocBase() != null) { File docBase = new File(context.getDocBase()); if (!docBase.isAbsolute()) { - docBase = new File(appBase(), context.getDocBase()); + docBase = new File(host.getAppBaseFile(), context.getDocBase()); } // If external docBase, register .xml as redeploy first if (!docBase.getCanonicalPath().startsWith( - appBase().getAbsolutePath() + File.separator)) { + host.getAppBaseFile().getAbsolutePath() + File.separator)) { isExternal = true; deployedApp.redeployResources.put( contextXml.getAbsolutePath(), @@ -634,13 +612,13 @@ public class HostConfig // Get paths for WAR and expanded WAR in appBase // default to appBase dir + name - File expandedDocBase = new File(appBase(), cn.getBaseName()); + File expandedDocBase = new File(host.getAppBaseFile(), cn.getBaseName()); if (context.getDocBase() != null) { // first assume docBase is absolute expandedDocBase = new File(context.getDocBase()); if (!expandedDocBase.isAbsolute()) { // if docBase specified and relative, it must be relative to appBase - expandedDocBase = new File(appBase(), context.getDocBase()); + expandedDocBase = new File(host.getAppBaseFile(), context.getDocBase()); } } // Add the eventual unpacked WAR and all the resources which will be @@ -782,7 +760,7 @@ public class HostConfig xml = new File(configBase(), file.substring(0, file.lastIndexOf(".")) + ".xml"); } else { - xml = new File(appBase(), + xml = new File(host.getAppBaseFile(), file.substring(0, file.lastIndexOf(".")) + "/META-INF/context.xml"); } @@ -933,7 +911,7 @@ public class HostConfig // If we're unpacking WARs, the docBase will be mutated after // starting the context if (unpackWARs && (context.getDocBase() != null)) { - File docBase = new File(appBase(), cn.getBaseName()); + File docBase = new File(host.getAppBaseFile(), cn.getBaseName()); deployedApp.redeployResources.put(docBase.getAbsolutePath(), Long.valueOf(docBase.lastModified())); addWatchedResources(deployedApp, docBase.getAbsolutePath(), @@ -1102,7 +1080,7 @@ public class HostConfig if (docBase != null) { docBaseFile = new File(docBase); if (!docBaseFile.isAbsolute()) { - docBaseFile = new File(appBase(), docBase); + docBaseFile = new File(host.getAppBaseFile(), docBase); } } String[] watchedResources = context.findWatchedResources(); @@ -1161,7 +1139,7 @@ public class HostConfig File current = new File(resources[j]); current = current.getCanonicalFile(); if ((current.getAbsolutePath().startsWith( - appBase().getAbsolutePath() + + host.getAppBaseFile().getAbsolutePath() + File.separator)) || (current.getAbsolutePath().startsWith( configBase().getAbsolutePath()))) { @@ -1212,7 +1190,7 @@ public class HostConfig File current = new File(resources[j]); current = current.getCanonicalFile(); if ((current.getAbsolutePath().startsWith( - appBase().getAbsolutePath() + File.separator)) + host.getAppBaseFile().getAbsolutePath() + File.separator)) || (current.getAbsolutePath().startsWith( configBase().getAbsolutePath()))) { if (log.isDebugEnabled()) @@ -1233,7 +1211,7 @@ public class HostConfig File current = new File(resources2[j]); current = current.getCanonicalFile(); if ((current.getAbsolutePath().startsWith( - appBase().getAbsolutePath() + File.separator)) + host.getAppBaseFile().getAbsolutePath() + File.separator)) || ((current.getAbsolutePath().startsWith( configBase().getAbsolutePath()) && (current.getAbsolutePath().endsWith(".xml"))))) { @@ -1310,7 +1288,7 @@ public class HostConfig } if (host.getCreateDirs()) { - File[] dirs = new File[] {appBase(),configBase()}; + File[] dirs = new File[] {host.getAppBaseFile(),configBase()}; for (int i=0; i
+ + + + Remove duplicate code that converted a Host's appBase attribute to + a canonical file. (markt) + + +