Author: kfujino Date: Mon May 28 07:11:43 2012 New Revision: 1343153 URL: http://svn.apache.org/viewvc?rev=1343153&view=rev Log: fix for Konstantin's review. Add new calculation method of host's default config path to Host(StanderdHost).
Modified: tomcat/trunk/java/org/apache/catalina/Host.java tomcat/trunk/java/org/apache/catalina/core/StandardHost.java tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java Modified: tomcat/trunk/java/org/apache/catalina/Host.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Host.java?rev=1343153&r1=1343152&r2=1343153&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/Host.java (original) +++ tomcat/trunk/java/org/apache/catalina/Host.java Mon May 28 07:11:43 2012 @@ -86,6 +86,12 @@ public interface Host extends Container public void setXmlBase(String xmlBase); /** + * Return a default configuration path of this Host. The file will be + * canonical if possible. + */ + public File getConfigBaseFile(); + + /** * Return the application root for this Host. This can be an absolute * pathname, a relative pathname, or a URL. */ Modified: tomcat/trunk/java/org/apache/catalina/core/StandardHost.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardHost.java?rev=1343153&r1=1343152&r2=1343153&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/core/StandardHost.java (original) +++ tomcat/trunk/java/org/apache/catalina/core/StandardHost.java Mon May 28 07:11:43 2012 @@ -30,6 +30,7 @@ import javax.management.ObjectName; import org.apache.catalina.Container; import org.apache.catalina.Context; +import org.apache.catalina.Engine; import org.apache.catalina.Host; import org.apache.catalina.JmxEnabled; import org.apache.catalina.Lifecycle; @@ -92,6 +93,11 @@ public class StandardHost extends Contai private String xmlBase = null; /** + * host's default config path + */ + private volatile File hostConfigBase = null; + + /** * The auto deploy flag for this Host. */ private boolean autoDeploy = true; @@ -270,6 +276,40 @@ public class StandardHost extends Contai /** + * ({@inheritDoc} + */ + @Override + public File getConfigBaseFile() { + if (hostConfigBase != null) { + return hostConfigBase; + } + String path = null; + if (getXmlBase()!=null) { + path = getXmlBase(); + } else { + StringBuilder xmlDir = new StringBuilder("conf"); + Container parent = getParent(); + if (parent instanceof Engine) { + xmlDir.append('/'); + xmlDir.append(parent.getName()); + } + xmlDir.append('/'); + xmlDir.append(getName()); + path = xmlDir.toString(); + } + File file = new File(path); + if (!file.isAbsolute()) + file = new File(getCatalinaBase(), path); + try { + file = file.getCanonicalFile(); + } catch (IOException e) {// ignore + } + this.hostConfigBase = file; + return file; + } + + + /** * Returns true if the Host will attempt to create directories for appBase and xmlBase * unless they already exist. */ Modified: tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java?rev=1343153&r1=1343152&r2=1343153&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java (original) +++ tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java Mon May 28 07:11:43 2012 @@ -1106,38 +1106,10 @@ public class ContextConfig implements Li protected File getHostConfigBase() { File file = null; - Container container = context; - Host host = null; - Engine engine = null; - while (container != null) { - if (container instanceof Host) { - host = (Host)container; - } - if (container instanceof Engine) { - engine = (Engine)container; - } - container = container.getParent(); - } - if (host != null && host.getXmlBase()!=null) { - String xmlBase = host.getXmlBase(); - file = new File(xmlBase); - if (!file.isAbsolute()) - file = new File(context.getCatalinaBase(), xmlBase); - } else { - StringBuilder result = new StringBuilder(); - if (engine != null) { - result.append(engine.getName()).append('/'); - } - if (host != null) { - result.append(host.getName()).append('/'); - } - file = new File (getConfigBase(), result.toString()); - } - try { - return file.getCanonicalFile(); - } catch (IOException e) { - return file; + if (context.getParent() instanceof Host) { + file = ((Host)context.getParent()).getConfigBaseFile(); } + return file; } /** @@ -1653,15 +1625,11 @@ public class ContextConfig implements Li * it. */ protected InputSource getHostWebXmlSource() { - String basePath = null; - try { - basePath = getHostConfigBase().getCanonicalPath(); - } catch (IOException e) { - log.error(sm.getString("contextConfig.baseError"), e); + File hostConfigBase = getHostConfigBase(); + if (hostConfigBase == null) return null; - } - return getWebXmlSource(Constants.HostWebXml, basePath); + return getWebXmlSource(Constants.HostWebXml, hostConfigBase.getPath()); } /** Modified: tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java?rev=1343153&r1=1343152&r2=1343153&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java (original) +++ tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java Mon May 28 07:11:43 2012 @@ -77,12 +77,6 @@ public class HostConfig /** - * Config base. - */ - protected File configBase = null; - - - /** * The Java class name of the Context configuration class we should use. */ protected String configClass = "org.apache.catalina.startup.ContextConfig"; @@ -396,38 +390,11 @@ public class HostConfig /** - * Return a File object representing the "configuration root" directory - * for our associated Host. - */ - protected File configBase() { - - if (configBase != null) { - return configBase; - } - - if (host.getXmlBase()!=null) { - configBase = returnCanonicalPath(host.getXmlBase()); - } else { - StringBuilder xmlDir = new StringBuilder("conf"); - Container parent = host.getParent(); - if (parent instanceof Engine) { - xmlDir.append('/'); - xmlDir.append(parent.getName()); - } - xmlDir.append('/'); - xmlDir.append(host.getName()); - configBase = returnCanonicalPath(xmlDir.toString()); - } - return (configBase); - - } - - /** * Get the name of the configBase. * For use with JMX management. */ public String getConfigBaseName() { - return configBase().getAbsolutePath(); + return host.getConfigBaseFile().getAbsolutePath(); } @@ -438,7 +405,7 @@ public class HostConfig protected void deployApps() { File appBase = host.getAppBaseFile(); - File configBase = configBase(); + File configBase = host.getConfigBaseFile(); String[] filteredAppPaths = filterAppPaths(appBase.list()); // Deploy XML descriptors from configBase deployDescriptors(configBase, configBase.list()); @@ -491,7 +458,7 @@ public class HostConfig protected void deployApps(String name) { File appBase = host.getAppBaseFile(); - File configBase = configBase(); + File configBase = host.getConfigBaseFile(); ContextName cn = new ContextName(name); String baseName = cn.getBaseName(); @@ -782,7 +749,7 @@ public class HostConfig BufferedOutputStream ostream = null; File xml; if (copyXML) { - xml = new File(configBase(), cn.getBaseName() + ".xml"); + xml = new File(host.getConfigBaseFile(), cn.getBaseName() + ".xml"); } else { xml = new File(host.getAppBaseFile(), cn.getBaseName() + "/META-INF/context.xml"); @@ -1034,7 +1001,7 @@ public class HostConfig } } if (copyXML) { - xmlCopy = new File(configBase(), cn.getBaseName() + ".xml"); + xmlCopy = new File(host.getConfigBaseFile(), cn.getBaseName() + ".xml"); InputStream is = null; OutputStream os = null; try { @@ -1213,7 +1180,7 @@ public class HostConfig host.getAppBaseFile().getAbsolutePath() + File.separator)) || (current.getAbsolutePath().startsWith( - configBase().getAbsolutePath()))) { + host.getConfigBaseFile().getAbsolutePath()))) { if (log.isDebugEnabled()) log.debug("Delete " + current); ExpandWar.delete(current); @@ -1269,7 +1236,7 @@ public class HostConfig if ((current.getAbsolutePath().startsWith( host.getAppBaseFile().getAbsolutePath() + File.separator)) || (current.getAbsolutePath().startsWith( - configBase().getAbsolutePath()))) { + host.getConfigBaseFile().getAbsolutePath()))) { if (log.isDebugEnabled()) log.debug("Delete " + current); ExpandWar.delete(current); @@ -1297,7 +1264,7 @@ public class HostConfig if ((current.getAbsolutePath().startsWith( host.getAppBaseFile().getAbsolutePath() + File.separator)) || ((current.getAbsolutePath().startsWith( - configBase().getAbsolutePath()) + host.getConfigBaseFile().getAbsolutePath()) && (current.getAbsolutePath().endsWith(".xml"))))) { if (log.isDebugEnabled()) log.debug("Delete " + current); @@ -1368,7 +1335,7 @@ public class HostConfig } if (host.getCreateDirs()) { - File[] dirs = new File[] {host.getAppBaseFile(),configBase()}; + File[] dirs = new File[] {host.getAppBaseFile(),host.getConfigBaseFile()}; for (int i=0; i<dirs.length; i++) { if (!dirs[i].mkdirs() && !dirs[i].isDirectory()) { log.error(sm.getString("hostConfig.createDirs",dirs[i])); @@ -1405,8 +1372,6 @@ public class HostConfig } } oname = null; - configBase = null; - } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org