Index: java/org/apache/catalina/startup/Bootstrap.java =================================================================== --- java/org/apache/catalina/startup/Bootstrap.java (revision 1061812) +++ java/org/apache/catalina/startup/Bootstrap.java (working copy) @@ -56,13 +56,6 @@ private static final Log log = LogFactory.getLog(Bootstrap.class); - // -------------------------------------------------------------- Constants - - - protected static final String CATALINA_HOME_TOKEN = "${" + Globals.CATALINA_HOME_PROP + "}"; - protected static final String CATALINA_BASE_TOKEN = "${" + Globals.CATALINA_BASE_PROP + "}"; - - // ------------------------------------------------------- Static Variables @@ -115,38 +108,11 @@ ArrayList repositoryLocations = new ArrayList(); ArrayList repositoryTypes = new ArrayList(); - int i; StringTokenizer tokenizer = new StringTokenizer(value, ","); while (tokenizer.hasMoreElements()) { String repository = tokenizer.nextToken(); - // Local repository - boolean replace = false; - String before = repository; - while ((i=repository.indexOf(CATALINA_HOME_TOKEN))>=0) { - replace=true; - if (i>0) { - repository = repository.substring(0,i) + getCatalinaHome() - + repository.substring(i+CATALINA_HOME_TOKEN.length()); - } else { - repository = getCatalinaHome() - + repository.substring(CATALINA_HOME_TOKEN.length()); - } - } - while ((i=repository.indexOf(CATALINA_BASE_TOKEN))>=0) { - replace=true; - if (i>0) { - repository = repository.substring(0,i) + getCatalinaBase() - + repository.substring(i+CATALINA_BASE_TOKEN.length()); - } else { - repository = getCatalinaBase() - + repository.substring(CATALINA_BASE_TOKEN.length()); - } - } - if (replace && log.isDebugEnabled()) - log.debug("Expanded " + before + " to " + repository); - // Check for a JAR URL repository try { new URL(repository); Index: java/org/apache/catalina/startup/CatalinaProperties.java =================================================================== --- java/org/apache/catalina/startup/CatalinaProperties.java (revision 1061812) +++ java/org/apache/catalina/startup/CatalinaProperties.java (working copy) @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,6 +24,8 @@ import java.net.URL; import java.util.Enumeration; import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.apache.catalina.Globals; @@ -53,6 +55,33 @@ } + // ------------------------------------------------------ Protected Methods + + + /** + * Returns the provided string with all property variables (in the form + * ${property.name}) replaced with their respective values. + * + * @param value The String in which property expansion should + * be performed. + * @return The provided value with all property variables replaced. + */ + protected static String expandPropertyVariables(String value) { + + final Matcher matcher = Pattern.compile("\\$\\{(.*?)\\}").matcher(value); + + if (matcher.find()) { + return value.substring(0, matcher.start()) + + System.getProperty(matcher.group(1), matcher.group()) + + expandPropertyVariables(value.substring(matcher.end())); + } + else { + return value; + } + + } + + // --------------------------------------------------------- Public Methods @@ -60,7 +89,7 @@ * Return specified property value. */ public static String getProperty(String name) { - + return properties.getProperty(name); } @@ -140,7 +169,15 @@ String name = (String) enumeration.nextElement(); String value = properties.getProperty(name); if (value != null) { - System.setProperty(name, value); + String result = expandPropertyVariables(value); + + properties.setProperty(name, result); + System.setProperty(name, result); + + if (log.isDebugEnabled() && !value.equals(result)) { + log.debug("Expanded Catalina property \"" + name + "\" from \"" + + value + "\" to \"" + result + "\""); + } } } @@ -154,8 +191,8 @@ return System.getProperty(Globals.CATALINA_HOME_PROP, System.getProperty("user.dir")); } - - + + /** * Get the value of the catalina.base environment variable. */