*/
package org.apache.catalina;
+import java.io.File;
import java.util.regex.Pattern;
*/
public void setXmlBase(String xmlBase);
- /**
+ /**
* Return the application root for this Host. This can be an absolute
* pathname, a relative pathname, or a URL.
*/
/**
+ * 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.
*
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 {
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;
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;
* The application root for this Host.
*/
private String appBase = "webapps";
+ private volatile File appBaseFile = null;
/**
* The XML root for this 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.
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.
}
+
/**
* Returns true if the Host will attempt to create directories for appBase and xmlBase
* unless they already exist.
}
/**
- * 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 {
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()) {
// 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",
// 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;
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);
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 {
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
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(
/**
- * 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)
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) {
File file = new File(docBase);
if (!file.isAbsolute()) {
- docBase = (new File(canonicalAppBase, docBase)).getPath();
+ docBase = (new File(appBase, docBase)).getPath();
} else {
docBase = file.getCanonicalPath();
}
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) {
}
}
- 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);
&& ((StandardContext) context).getAntiResourceLocking()) {
Host host = (Host) context.getParent();
- String appBase = host.getAppBase();
String docBase = context.getDocBase();
if (docBase == null)
return;
}
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();
// 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);
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;
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());
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();
/**
- * App base.
- */
- protected File appBase = null;
-
-
- /**
* Config base.
*/
protected File configBase = null;
/**
- * 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.
*/
*/
protected void deployApps() {
- File appBase = appBase();
+ File appBase = host.getAppBaseFile();
File configBase = configBase();
String[] filteredAppPaths = filterAppPaths(appBase.list());
// Deploy XML descriptors from configBase
*/
protected void deployApps(String name) {
- File appBase = appBase();
+ File appBase = host.getAppBaseFile();
File configBase = configBase();
ContextName cn = new ContextName(name);
String baseName = cn.getBaseName();
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(),
// 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
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");
}
// 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(),
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();
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()))) {
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())
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"))))) {
}
if (host.getCreateDirs()) {
- File[] dirs = new File[] {appBase(),configBase()};
+ File[] dirs = new File[] {host.getAppBaseFile(),configBase()};
for (int i=0; i<dirs.length; i++) {
if ( (!dirs[i].isDirectory()) && (!dirs[i].mkdirs())) {
log.error(sm.getString("hostConfig.createDirs",dirs[i]));
}
}
- if (!appBase().isDirectory()) {
- log.error(sm.getString(
- "hostConfig.appBase", host.getName(), appBase().getPath()));
+ if (!host.getAppBaseFile().isDirectory()) {
+ log.error(sm.getString("hostConfig.appBase", host.getName(),
+ host.getAppBaseFile().getPath()));
host.setDeployOnStartup(false);
host.setAutoDeploy(false);
}
}
}
oname = null;
- appBase = null;
configBase = null;
}
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());
}
deployedApp.redeployResources.put(docBase.getAbsolutePath(),
Long.valueOf(docBase.lastModified()));
// Add the eventual unpacked WAR and all the resources which will be
// watched inside it
if (isWar && unpackWARs) {
- File docBase = new File(appBase(), context.getBaseName());
+ File docBase = new File(host.getAppBaseFile(), context.getBaseName());
deployedApp.redeployResources.put(docBase.getAbsolutePath(),
Long.valueOf(docBase.lastModified()));
addWatchedResources(deployedApp, docBase.getAbsolutePath(), context);
// Set up a container
Tomcat tomcat = getTomcatInstance();
- File docBase = new File(tomcat.getHost().getAppBase(), "ROOT");
+ File docBase = new File(tomcat.getHost().getAppBaseFile(), "ROOT");
if (!docBase.exists() && !docBase.mkdirs()) {
fail("Unable to create docBase");
}
should be listed here.
-->
<section name="Tomcat 8.0.0">
+ <subsection name="Catalina">
+ <changelog>
+ <scode>
+ Remove duplicate code that converted a Host's appBase attribute to
+ a canonical file. (markt)
+ </scode>
+ </changelog>
+ </subsection>
</section>
</body>
</document>