Author: henning
Date: Mon Oct 21 22:12:36 2013
New Revision: 1534396

URL: http://svn.apache.org/r1534396
Log:
Backport CONFIGURATION-534 from r1457498,

Modified:
    
commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/RELEASE-NOTES.txt
    
commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/changes/changes.xml
    
commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/main/java/org/apache/commons/configuration/PropertiesConfiguration.java
    
commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/test/java/org/apache/commons/configuration/TestPropertiesConfiguration.java

Modified: 
commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/RELEASE-NOTES.txt
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/RELEASE-NOTES.txt?rev=1534396&r1=1534395&r2=1534396&view=diff
==============================================================================
--- 
commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/RELEASE-NOTES.txt
 (original)
+++ 
commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/RELEASE-NOTES.txt
 Mon Oct 21 22:12:36 2013
@@ -74,6 +74,12 @@ BUG FIXES IN 1.10
 IMPROVEMENTS AND NEW FEATURES IN 1.10
 =====================================
 
+* [CONFIGURATION-534] PropertyConfiguration's handling of includes depends on 
the
+                      existence of a base path
+
+  The includesAllowed property of PropertyConfiguration is now independent
+  from the existence of a base path.
+
 * [CONFIGURATION-550] Missing conversion to char
 
   Conversion to Character is now supported.

Modified: 
commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/changes/changes.xml?rev=1534396&r1=1534395&r2=1534396&view=diff
==============================================================================
--- 
commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/changes/changes.xml
 (original)
+++ 
commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/changes/changes.xml
 Mon Oct 21 22:12:36 2013
@@ -31,6 +31,10 @@
         XMLConfiguration now adds attributes of elements defining a list to
         all list nodes.
       </action>
+      <action dev="oheger" type="update" issue="CONFIGURATION-534">
+        The includesAllowed property of PropertyConfiguration is now 
independent
+        from the existence of a base path.
+      </action>
       <action dev="oheger" type="update" issue="CONFIGURATION-546" 
due-to="Justin Couch">
         BeanHelper can now process BeanDefinitions initializing properties of
         collection types of their target beans.

Modified: 
commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/main/java/org/apache/commons/configuration/PropertiesConfiguration.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/main/java/org/apache/commons/configuration/PropertiesConfiguration.java?rev=1534396&r1=1534395&r2=1534396&view=diff
==============================================================================
--- 
commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/main/java/org/apache/commons/configuration/PropertiesConfiguration.java
 (original)
+++ 
commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/main/java/org/apache/commons/configuration/PropertiesConfiguration.java
 Mon Oct 21 22:12:36 2013
@@ -227,7 +227,7 @@ public class PropertiesConfiguration ext
     private volatile IOFactory ioFactory;
 
     /** Allow file inclusion or not */
-    private boolean includesAllowed;
+    private boolean includesAllowed = true;
 
     /**
      * Creates an empty PropertyConfiguration object which can be
@@ -237,7 +237,6 @@ public class PropertiesConfiguration ext
     public PropertiesConfiguration()
     {
         layout = createLayout();
-        setIncludesAllowed(false);
     }
 
     /**
@@ -309,12 +308,11 @@ public class PropertiesConfiguration ext
 
     /**
      * Controls whether additional files can be loaded by the include = <xxx>
-     * statement or not. Base rule is, that objects created by the empty
-     * C'tor can not have included files.
+     * statement or not. This is <b>true</b> per default.
      *
-     * @param includesAllowed includesAllowed True if Includes are allowed.
+     * @param includesAllowed True if Includes are allowed.
      */
-    protected void setIncludesAllowed(boolean includesAllowed)
+    public void setIncludesAllowed(boolean includesAllowed)
     {
         this.includesAllowed = includesAllowed;
     }
@@ -323,9 +321,25 @@ public class PropertiesConfiguration ext
      * Reports the status of file inclusion.
      *
      * @return True if include files are loaded.
+     *
+     * @see isIncludedAllowed()
+     *
+     * @deprecated Only exists to not break backwards compatibility.
+     * Use {@link isIncludesAllowed()} instead.
      */
+    @Deprecated
     public boolean getIncludesAllowed()
     {
+        return isIncludesAllowed();
+    }
+
+    /**
+     * Reports the status of file inclusion.
+     *
+     * @return True if include files are loaded.
+     */
+    public boolean isIncludesAllowed()
+    {
         return this.includesAllowed;
     }
 
@@ -552,7 +566,7 @@ public class PropertiesConfiguration ext
         if (StringUtils.isNotEmpty(getInclude())
                 && key.equalsIgnoreCase(getInclude()))
         {
-            if (getIncludesAllowed())
+            if (isIncludesAllowed())
             {
                 String[] files;
                 if (!isDelimiterParsingDisabled())

Modified: 
commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/test/java/org/apache/commons/configuration/TestPropertiesConfiguration.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/test/java/org/apache/commons/configuration/TestPropertiesConfiguration.java?rev=1534396&r1=1534395&r2=1534396&view=diff
==============================================================================
--- 
commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/test/java/org/apache/commons/configuration/TestPropertiesConfiguration.java
 (original)
+++ 
commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/test/java/org/apache/commons/configuration/TestPropertiesConfiguration.java
 Mon Oct 21 22:12:36 2013
@@ -153,6 +153,41 @@ public class TestPropertiesConfiguration
         assertEquals("true", loaded);
     }
 
+    /**
+     * Tests whether include files can be resolved if a configuration file is
+     * read from a reader.
+     */
+    @Test
+    public void testLoadIncludeFromReader() throws ConfigurationException,
+            IOException
+    {
+        StringReader in =
+                new StringReader(PropertiesConfiguration.getInclude() + " = "
+                        + 
ConfigurationAssert.getTestURL("include.properties"));
+        conf = new PropertiesConfiguration();
+        conf.read(in);
+        assertEquals("Include file not loaded", "true",
+                conf.getString("include.loaded"));
+    }
+
+    /**
+     * Tests whether include files can be disabled.
+     */
+    @Test
+    public void testDisableIncludes() throws ConfigurationException,
+            IOException
+    {
+        String content =
+                PropertiesConfiguration.getInclude()
+                        + " = nonExistingIncludeFile" + CR + PROP_NAME + " = "
+                        + PROP_VALUE + CR;
+        StringReader in = new StringReader(content);
+        conf = new PropertiesConfiguration();
+        conf.setIncludesAllowed(false);
+        conf.read(in);
+        assertEquals("Data not loaded", PROP_VALUE, conf.getString(PROP_NAME));
+    }
+
     @Test
     public void testSetInclude() throws Exception
     {


Reply via email to