You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2012/12/09 16:56:28 UTC
svn commit: r1419010 - in /commons/proper/configuration/trunk/src:
main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java
test/resources/testCCSystemProperties.xml
Author: oheger
Date: Sun Dec 9 15:56:28 2012
New Revision: 1419010
URL: http://svn.apache.org/viewvc?rev=1419010&view=rev
Log:
Added support for the <system> tag to include system properties.
Added:
commons/proper/configuration/trunk/src/test/resources/testCCSystemProperties.xml (with props)
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java?rev=1419010&r1=1419009&r2=1419010&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java Sun Dec 9 15:56:28 2012
@@ -32,6 +32,7 @@ import org.apache.commons.configuration.
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration.SubnodeConfiguration;
+import org.apache.commons.configuration.SystemConfiguration;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.configuration.beanutils.BeanDeclaration;
import org.apache.commons.configuration.beanutils.BeanHelper;
@@ -368,6 +369,10 @@ public class CombinedConfigurationBuilde
/** Constant for the XML file extension. */
static final String EXT_XML = "xml";
+ /** Constant for the basic configuration builder class. */
+ private static final String BASIC_BUILDER =
+ "org.apache.commons.configuration.builder.BasicConfigurationBuilder";
+
/** Constant for the file-based configuration builder class. */
private static final String FILE_BUILDER =
"org.apache.commons.configuration.builder.FileBasedConfigurationBuilder";
@@ -400,8 +405,12 @@ public class CombinedConfigurationBuilde
JNDIConfiguration.class);*/
/** Constant for the provider for system properties. */
- private static final BaseConfigurationBuilderProvider SYSTEM_PROVIDER = null;/*new BaseConfigurationBuilderProvider(
- SystemConfiguration.class);*/
+ private static final BaseConfigurationBuilderProvider SYSTEM_PROVIDER =
+ new BaseConfigurationBuilderProvider(
+ BASIC_BUILDER,
+ null,
+ "org.apache.commons.configuration.SystemConfiguration",
+ Arrays.asList("org.apache.commons.configuration.builder.BasicBuilderParameters"));
/** Constant for the provider for ini files. */
private static final BaseConfigurationBuilderProvider INI_PROVIDER =
@@ -428,13 +437,13 @@ public class CombinedConfigurationBuilde
/** An array with the names of the default tags. */
private static final String[] DEFAULT_TAGS = {
"properties", "xml", "hierarchicalXml", "plist",
- "ini"/*, "configuration", "env", "jndi", "system"*/
+ "ini", "system"/*, "configuration", "env", "jndi"*/
};
/** An array with the providers for the default tags. */
private static final ConfigurationBuilderProvider[] DEFAULT_PROVIDERS = {
- PROPERTIES_PROVIDER, XML_PROVIDER, XML_PROVIDER, PLIST_PROVIDER, INI_PROVIDER/*, JNDI_PROVIDER,
- SYSTEM_PROVIDER, BUILDER_PROVIDER,
+ PROPERTIES_PROVIDER, XML_PROVIDER, XML_PROVIDER, PLIST_PROVIDER, INI_PROVIDER,
+ SYSTEM_PROVIDER/*, JNDI_PROVIDER, BUILDER_PROVIDER,
ENV_PROVIDER*/
};
@@ -554,7 +563,6 @@ public class CombinedConfigurationBuilde
throws ConfigurationException
{
initFileSystem();
- initSystemProperties();
configureEntityResolver();
registerConfiguredLookups();
@@ -741,6 +749,7 @@ public class CombinedConfigurationBuilde
setUpCurrentParameters();
initNodeCombinerListNodes(result, config, KEY_OVERRIDE_LIST);
registerConfiguredProviders(config);
+ initSystemProperties(config);
ConfigurationSourceData data = getSourceData();
createAndAddConfigurations(result, data.getOverrideBuilders(), data);
@@ -809,24 +818,31 @@ public class CombinedConfigurationBuilde
}
/**
- * If a property file is configured add the properties to the System properties.
+ * Handles a file with system properties that may be defined in the
+ * definition configuration. If such property file is configured, all of its
+ * properties are added to the system properties.
+ *
+ * @param config the definition configuration
* @throws ConfigurationException if an error occurs.
*/
- protected void initSystemProperties() throws ConfigurationException
+ protected void initSystemProperties(HierarchicalConfiguration config)
+ throws ConfigurationException
{
-// String fileName = getString(KEY_SYSTEM_PROPS);
-// if (fileName != null)
-// {
-// try
-// {
-// SystemConfiguration.setSystemProperties(getConfigurationBasePath(), fileName);
-// }
-// catch (Exception ex)
-// {
-// throw new ConfigurationException("Error setting system properties from " + fileName, ex);
-// }
-//
-// }
+ String fileName = config.getString(KEY_SYSTEM_PROPS);
+ if (fileName != null)
+ {
+ try
+ {
+ SystemConfiguration.setSystemProperties(
+ getConfigurationBasePath(), fileName);
+ }
+ catch (Exception ex)
+ {
+ throw new ConfigurationException(
+ "Error setting system properties from " + fileName, ex);
+ }
+
+ }
}
protected void configureEntityResolver() throws ConfigurationException
Added: commons/proper/configuration/trunk/src/test/resources/testCCSystemProperties.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/resources/testCCSystemProperties.xml?rev=1419010&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/test/resources/testCCSystemProperties.xml (added)
+++ commons/proper/configuration/trunk/src/test/resources/testCCSystemProperties.xml Sun Dec 9 15:56:28 2012
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!-- Test configuration definition file that sets system properties from an XML file -->
+<configuration systemProperties="test.properties.xml">
+ <system/>
+</configuration>
\ No newline at end of file
Propchange: commons/proper/configuration/trunk/src/test/resources/testCCSystemProperties.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/test/resources/testCCSystemProperties.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/test/resources/testCCSystemProperties.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml