/** * Add to the provided propertyMap any properties available from this source * * Where the map already contains property values under a given key, extra property values should be * appended to the List * @return propertyMap, with parsed properties added */ public Map<ConfigurationProperty, List<String>> parseProperties(Map<ConfigurationProperty, List<String>> propertyMap, String... args) { for ( ConfigurationProperty p : getProperties()) { String value = System.getProperty(p.getSystemProperty()); if ( value != null ) { addValues(propertyMap, p, value); } } return propertyMap; }
private void addValues(Map<ConfigurationProperty, List<String>> propertyMap, ConfigurationProperty property, String value) { StringTokenizer st = new StringTokenizer(value, " "); List<String> tokens = getOrCreatePropertyList(propertyMap, property); while(st.hasMoreElements()) { tokens.add(st.nextToken()); } }
/** * Create a configuration using process arguments, System Properties and defaults */ public ConfigReader(List<ConfigurationProperty> properties, String[] args) { this.properties = properties; this.args = args; //where a property is in PropertySourceMode.OVERRIDE the ordering of sources here is important //sys props are last since it is useful to be able to use a sys prop to override command line //parameters for test suites which run as part of a component build which is checked in to source control - //otherwise it is necessary to commit changes to files to achieve something simple like increasing logging //to debug level. Continuous integration tools such as team city let you set a sys prop easily to do this. propertySources = new ConfigSource[] { new DefaultsConfigSource(properties), new CommandLineParser(properties), new SystemPropertyParser(properties) }; }