commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r240432 - in /jakarta/commons/proper/configuration/trunk: conf/ conf/config/deep/ src/java/org/apache/commons/configuration/ src/test/org/apache/commons/configuration/ xdocs/
Date Sat, 27 Aug 2005 15:59:47 GMT
Author: oheger
Date: Sat Aug 27 08:59:16 2005
New Revision: 240432

URL: http://svn.apache.org/viewcvs?rev=240432&view=rev
Log:
Updated PropertiesConfiguration to search for include files based on its own location, too

Added:
    jakarta/commons/proper/configuration/trunk/conf/config/deep/deepinclude.properties   (with
props)
    jakarta/commons/proper/configuration/trunk/conf/config/deep/deeptest.properties   (with
props)
    jakarta/commons/proper/configuration/trunk/conf/config/deep/deeptestinvalid.properties
  (with props)
    jakarta/commons/proper/configuration/trunk/conf/testFactoryPropertiesInclude.xml   (with
props)
Modified:
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
    jakarta/commons/proper/configuration/trunk/xdocs/changes.xml

Added: jakarta/commons/proper/configuration/trunk/conf/config/deep/deepinclude.properties
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/conf/config/deep/deepinclude.properties?rev=240432&view=auto
==============================================================================
--- jakarta/commons/proper/configuration/trunk/conf/config/deep/deepinclude.properties (added)
+++ jakarta/commons/proper/configuration/trunk/conf/config/deep/deepinclude.properties Sat
Aug 27 08:59:16 2005
@@ -0,0 +1 @@
+deepinclude=true

Propchange: jakarta/commons/proper/configuration/trunk/conf/config/deep/deepinclude.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/configuration/trunk/conf/config/deep/deepinclude.properties
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/commons/proper/configuration/trunk/conf/config/deep/deepinclude.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/commons/proper/configuration/trunk/conf/config/deep/deeptest.properties
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/conf/config/deep/deeptest.properties?rev=240432&view=auto
==============================================================================
--- jakarta/commons/proper/configuration/trunk/conf/config/deep/deeptest.properties (added)
+++ jakarta/commons/proper/configuration/trunk/conf/config/deep/deeptest.properties Sat Aug
27 08:59:16 2005
@@ -0,0 +1,3 @@
+include=deepinclude.properties
+
+deeptest=true

Propchange: jakarta/commons/proper/configuration/trunk/conf/config/deep/deeptest.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/configuration/trunk/conf/config/deep/deeptest.properties
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/commons/proper/configuration/trunk/conf/config/deep/deeptest.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/commons/proper/configuration/trunk/conf/config/deep/deeptestinvalid.properties
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/conf/config/deep/deeptestinvalid.properties?rev=240432&view=auto
==============================================================================
--- jakarta/commons/proper/configuration/trunk/conf/config/deep/deeptestinvalid.properties
(added)
+++ jakarta/commons/proper/configuration/trunk/conf/config/deep/deeptestinvalid.properties
Sat Aug 27 08:59:16 2005
@@ -0,0 +1,4 @@
+# Tries to include a non existing file
+include=nonexisting.properties
+
+deeptestinvalid=true

Propchange: jakarta/commons/proper/configuration/trunk/conf/config/deep/deeptestinvalid.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/configuration/trunk/conf/config/deep/deeptestinvalid.properties
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/commons/proper/configuration/trunk/conf/config/deep/deeptestinvalid.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/commons/proper/configuration/trunk/conf/testFactoryPropertiesInclude.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/conf/testFactoryPropertiesInclude.xml?rev=240432&view=auto
==============================================================================
--- jakarta/commons/proper/configuration/trunk/conf/testFactoryPropertiesInclude.xml (added)
+++ jakarta/commons/proper/configuration/trunk/conf/testFactoryPropertiesInclude.xml Sat Aug
27 08:59:16 2005
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!-- Tests embedding properties in a deep directory structure, which in turn
+     include another property file.
+-->
+<configuration>
+  <properties fileName="config/deep/deeptest.properties"/>
+  <properties fileName="config/deep/deeptestinvalid.properties" optional="true"/>
+</configuration>

Propchange: jakarta/commons/proper/configuration/trunk/conf/testFactoryPropertiesInclude.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/configuration/trunk/conf/testFactoryPropertiesInclude.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/commons/proper/configuration/trunk/conf/testFactoryPropertiesInclude.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java?rev=240432&r1=240431&r2=240432&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
Sat Aug 27 08:59:16 2005
@@ -322,7 +322,7 @@
                         String [] files = StringUtils.split(value, getDelimiter());
                         for (int i = 0; i < files.length; i++)
                         {
-                            load(ConfigurationUtils.locate(getBasePath(), files[i].trim()));
+                            loadIncludeFile(files[i].trim());
                         }
                     }
                 }
@@ -788,4 +788,33 @@
         return result;
     }
 
+    /**
+     * Helper method for loading an included properties file. This method is
+     * called by <code>load()</code> when an <code>include</code>
property
+     * is encountered. It tries to resolve relative file names based on the
+     * current base path. If this fails, a resolution based on the location of
+     * this properties file is tried.
+     * 
+     * @param fileName the name of the file to load
+     * @throws ConfigurationException if loading fails
+     */
+    private void loadIncludeFile(String fileName) throws ConfigurationException
+    {
+        URL url = ConfigurationUtils.locate(getBasePath(), fileName);
+        if (url == null)
+        {
+            URL baseURL = getURL();
+            if (baseURL != null)
+            {
+                url = ConfigurationUtils.locate(baseURL.toString(), fileName);
+            }
+        }
+
+        if (url == null)
+        {
+            throw new ConfigurationException("Cannot resolve include file "
+                    + fileName);
+        }
+        load(url);
+    }
 }

Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java?rev=240432&r1=240431&r2=240432&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
Sat Aug 27 08:59:16 2005
@@ -394,4 +394,17 @@
         assertEquals("formfeed separator not properly parsed",   "foo", conf.getProperty("test.separator.formfeed"));
         assertEquals("whitespace separator not properly parsed", "foo", conf.getProperty("test.separator.whitespace"));
     }
+    
+    /**
+     * Tests including properties when they are loaded from a nested directory
+     * structure.
+     */
+    public void testIncludeInSubDir() throws ConfigurationException
+    {
+        ConfigurationFactory factory = new ConfigurationFactory("conf/testFactoryPropertiesInclude.xml");
+        Configuration config = factory.getConfiguration();
+        assertEquals(true, config.getBoolean("deeptest"));
+        assertEquals(true, config.getBoolean("deepinclude"));
+        assertFalse(config.containsKey("deeptestinvalid"));
+    }
 }

Modified: jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/xdocs/changes.xml?rev=240432&r1=240431&r2=240432&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Sat Aug 27 08:59:16 2005
@@ -23,6 +23,11 @@
   <body>
 
     <release version="1.2-dev" date="in SVN">
+      <action dev="oheger" type="add" issue="36383">
+        If an include file with a relative path cannot be found in the base
+        path, PropertiesConfiguration now also tries to resolve it based on its
+        own location.
+      </action>
       <action dev="ebourg" type="update" issue="35945" due-to="Steve Bate">
         Fixed MapConfiguration to store the list of values added under a same
         key instead of the last value added.



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message