Bug 333771 - System properties are not available inside XML configuration

file by using the 'property' tag.

* Made lookups of Properties by the Start Config use Jetty Property then
  System Properties, and lastly default values when requested.
* Made XmlConfiguration use layered property lookup from Start Config,
  benefitting XmlConfiguration of the same logic.
* Made all use of Start Config.getProperty() use static references
  per the method signature.

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2646 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Joakim Erdfelt 2011-01-10 18:10:15 +00:00
parent 9cd55e8ba5
commit 892bd690e0
6 changed files with 49 additions and 34 deletions

View File

@ -13,7 +13,8 @@ jetty-7.3.0-SNAPSHOT
+ 333415 wired up HttpInput.available and added test harnesses
+ 333481 Handle UTF-32 codepoints
+ 333608 tlds defined in web.xml are not picked up
+ 333679 Refactored jetty-jmx. Moved mbeans to modules.
+ 333679 Refactored jetty-jmx. Moved mbeans to modules
+ 333771 System properties are not available inside XML configuration file by using the 'property' tag
+ 333875 Monitor public constructor
jetty-7.2.2.v20101205 5 December 2010

View File

@ -50,7 +50,7 @@
# and /opt/jetty. The java system property "jetty.home" will be
# set to this value for use by configure.xml files, f.e.:
#
# <Arg><SystemProperty name="jetty.home" default="."/>/webapps/jetty.war</Arg>
# <Arg><Property name="jetty.home" default="."/>/webapps/jetty.war</Arg>
#
# JETTY_PORT
# Override the default port for Jetty servers. If not set then the
@ -60,7 +60,7 @@
# used in the demo config files to respect this property in Listener
# configuration elements:
#
# <Set name="Port"><SystemProperty name="jetty.port" default="8080"/></Set>
# <Set name="Port"><Property name="jetty.port" default="8080"/></Set>
#
# Note: that the config file could ignore this property simply by saying:
#

View File

@ -35,6 +35,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@ -334,7 +335,7 @@ public class Config
if (i2 < 0)
break;
String name = s.substring(i1 + 2,i2);
String property = getSystemProperty(name);
String property = getProperty(name);
s = s.substring(0,i1) + property + s.substring(i2 + 1);
}
@ -418,24 +419,39 @@ public class Config
public static Properties getProperties()
{
Properties properties = new Properties();
for (String key : __properties.keySet())
// Add System Properties First
Enumeration<?> ensysprop = System.getProperties().propertyNames();
while(ensysprop.hasMoreElements()) {
String name = (String)ensysprop.nextElement();
properties.put(name, System.getProperty(name));
}
// Add Config Properties Next (overwriting any System Properties that exist)
for (String key : __properties.keySet()) {
properties.put(key,__properties.get(key));
}
return properties;
}
public static String getProperty(String name)
{
if ("version".equalsIgnoreCase(name))
if ("version".equalsIgnoreCase(name)) {
return _version;
}
// Search Config Properties First
if (__properties.containsKey(name)) {
return __properties.get(name);
}
// Return what exists in System.Properties otherwise.
return System.getProperty(name);
}
public static String getProperty(String name, String dftValue)
public static String getProperty(String name, String defaultValue)
{
// Search Config Properties First
if (__properties.containsKey(name))
return __properties.get(name);
return dftValue;
// Return what exists in System.Properties otherwise.
return System.getProperty(name, defaultValue);
}
/**
@ -461,15 +477,6 @@ public class Config
return ids;
}
private String getSystemProperty(String name)
{
if ("version".equalsIgnoreCase(name))
return _version;
if (__properties.containsKey(name))
return __properties.get(name);
return System.getProperty(name);
}
public List<String> getXmlConfigs()
{
return _xml;

View File

@ -131,8 +131,8 @@ public class Main
if ("--stop".equals(arg))
{
int port = Integer.parseInt(_config.getProperty("STOP.PORT",System.getProperty("STOP.PORT","-1")));
String key = _config.getProperty("STOP.KEY",System.getProperty("STOP.KEY",null));
int port = Integer.parseInt(Config.getProperty("STOP.PORT","-1"));
String key = Config.getProperty("STOP.KEY",null);
stop(port,key);
return;
}
@ -498,8 +498,8 @@ public class Main
public void start(List<String> xmls) throws FileNotFoundException, IOException, InterruptedException
{
// Setup Start / Stop Monitoring
int port = Integer.parseInt(_config.getProperty("STOP.PORT",System.getProperty("STOP.PORT","-1")));
String key = _config.getProperty("STOP.KEY",System.getProperty("STOP.KEY",null));
int port = Integer.parseInt(Config.getProperty("STOP.PORT","-1"));
String key = Config.getProperty("STOP.KEY",null);
Monitor monitor=new Monitor(port,key);
@ -536,7 +536,7 @@ public class Main
System.err.println("java.class.path=" + classpath);
System.err.println("classloader=" + cl);
System.err.println("classloader.parent=" + cl.getParent());
System.err.println("properties="+_config.getProperties());
System.err.println("properties=" + Config.getProperties());
}
// Show the usage information and return
@ -1017,7 +1017,7 @@ public class Main
// parse the config
_config.parse(cfgstream);
_jettyHome = _config.getProperty("jetty.home");
_jettyHome = Config.getProperty("jetty.home");
if (_jettyHome != null)
{
_jettyHome = new File(_jettyHome).getCanonicalPath();

View File

@ -113,7 +113,7 @@ public class ConfigTest
Config cfg = new Config();
cfg.parse(buf);
Assert.assertEquals(getTestResourcesDir().getCanonicalPath(),cfg.getProperty("test.resources.dir"));
Assert.assertEquals(getTestResourcesDir().getCanonicalPath(),Config.getProperty("test.resources.dir"));
}
/*
@ -129,8 +129,8 @@ public class ConfigTest
Config options = new Config();
options.parse(buf);
Assert.assertEquals("foo",options.getProperty("test.jetty.start.text"));
Assert.assertEquals("Eatagramovabits",options.getProperty("test.jetty.start.quote"));
Assert.assertEquals("foo",Config.getProperty("test.jetty.start.text"));
Assert.assertEquals("Eatagramovabits",Config.getProperty("test.jetty.start.quote"));
}
/*

View File

@ -28,13 +28,12 @@ import java.net.UnknownHostException;
import java.security.AccessControlException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
@ -174,7 +173,7 @@ public class XmlConfiguration
/* ------------------------------------------------------------ */
/**
* @deprecated use {@link #getProperties()}.put(...)
* @deprecated use {@link #getProperties()}.putAll(...)
*/
public void setProperties (Map<String,String> map)
{
@ -1021,8 +1020,15 @@ public class XmlConfiguration
}
// If no start.config properties, use clean slate
if (properties==null)
if (properties==null) {
properties = new Properties();
// Add System Properties
Enumeration<?> ensysprop = System.getProperties().propertyNames();
while(ensysprop.hasMoreElements()) {
String name = (String)ensysprop.nextElement();
properties.put(name, System.getProperty(name));
}
}
// For all arguments, load properties or parse XMLs
XmlConfiguration last = null;
@ -1042,8 +1048,9 @@ public class XmlConfiguration
if ( properties.size() > 0 )
{
Map<String,String> props = new HashMap<String,String>();
for (Object key:properties.keySet())
for (Object key:properties.keySet()) {
props.put(key.toString(),String.valueOf(properties.get(key)));
}
configuration.setProperties( props );
}
obj[i] = configuration.configure();