commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r234275 - in /jakarta/commons/proper/configuration/trunk: conf/ src/java/org/apache/commons/configuration/ src/test/org/apache/commons/configuration/ xdocs/
Date Sun, 21 Aug 2005 17:13:29 GMT
Author: oheger
Date: Sun Aug 21 10:13:01 2005
New Revision: 234275

URL: http://svn.apache.org/viewcvs?rev=234275&view=rev
Log:
Fixed a bug in the handling of relative file names in ConfigurationFactory (issue 35316)

Modified:
    jakarta/commons/proper/configuration/trunk/conf/testDigesterConfiguration.xml
    jakarta/commons/proper/configuration/trunk/conf/testDigesterConfigurationNamespaceAware.xml
    jakarta/commons/proper/configuration/trunk/conf/testDigesterConfigurationReverseOrder.xml
    jakarta/commons/proper/configuration/trunk/conf/testDigesterConfigurationWJNDI.xml
    jakarta/commons/proper/configuration/trunk/conf/testEqualDigester.xml
    jakarta/commons/proper/configuration/trunk/conf/testSequenceDigester.xml
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationFactory.java
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationFactory.java
    jakarta/commons/proper/configuration/trunk/xdocs/changes.xml

Modified: jakarta/commons/proper/configuration/trunk/conf/testDigesterConfiguration.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/conf/testDigesterConfiguration.xml?rev=234275&r1=234274&r2=234275&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/conf/testDigesterConfiguration.xml (original)
+++ jakarta/commons/proper/configuration/trunk/conf/testDigesterConfiguration.xml Sun Aug
21 10:13:01 2005
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="ISO-8859-1" ?>
 
 <configuration>
-  <properties fileName="conf/test.properties"/>
-  <properties fileName="conf/test.properties.xml"/>
-  <xml fileName="conf/test.xml"/>
+  <properties fileName="test.properties"/>
+  <properties fileName="test.properties.xml"/>
+  <xml fileName="test.xml"/>
 </configuration>

Modified: jakarta/commons/proper/configuration/trunk/conf/testDigesterConfigurationNamespaceAware.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/conf/testDigesterConfigurationNamespaceAware.xml?rev=234275&r1=234274&r2=234275&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/conf/testDigesterConfigurationNamespaceAware.xml
(original)
+++ jakarta/commons/proper/configuration/trunk/conf/testDigesterConfigurationNamespaceAware.xml
Sun Aug 21 10:13:01 2005
@@ -2,6 +2,6 @@
 
 <configuration xmlns:foo="namespace-one"
                xmlns:bar="namespace-two">
-  <foo:properties fileName="conf/test.properties"/>
-  <bar:xml fileName="conf/test.xml"/>
+  <foo:properties fileName="test.properties"/>
+  <bar:xml fileName="test.xml"/>
 </configuration>

Modified: jakarta/commons/proper/configuration/trunk/conf/testDigesterConfigurationReverseOrder.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/conf/testDigesterConfigurationReverseOrder.xml?rev=234275&r1=234274&r2=234275&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/conf/testDigesterConfigurationReverseOrder.xml
(original)
+++ jakarta/commons/proper/configuration/trunk/conf/testDigesterConfigurationReverseOrder.xml
Sun Aug 21 10:13:01 2005
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="ISO-8859-1" ?>
 
 <configuration>
-  <xml fileName="conf/test.xml"/>
-  <properties fileName="conf/test.properties"/>
+  <xml fileName="test.xml"/>
+  <properties fileName="test.properties"/>
 </configuration>

Modified: jakarta/commons/proper/configuration/trunk/conf/testDigesterConfigurationWJNDI.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/conf/testDigesterConfigurationWJNDI.xml?rev=234275&r1=234274&r2=234275&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/conf/testDigesterConfigurationWJNDI.xml (original)
+++ jakarta/commons/proper/configuration/trunk/conf/testDigesterConfigurationWJNDI.xml Sun
Aug 21 10:13:01 2005
@@ -2,6 +2,6 @@
 
 <configuration>
   <jndi prefix="java:comp/env"/>
-  <properties fileName="conf/test.properties"/>
-  <xml fileName="conf/test.xml"/>
+  <properties fileName="test.properties"/>
+  <xml fileName="test.xml"/>
 </configuration>

Modified: jakarta/commons/proper/configuration/trunk/conf/testEqualDigester.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/conf/testEqualDigester.xml?rev=234275&r1=234274&r2=234275&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/conf/testEqualDigester.xml (original)
+++ jakarta/commons/proper/configuration/trunk/conf/testEqualDigester.xml Sun Aug 21 10:13:01
2005
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="ISO-8859-1" ?>
 
 <configuration>
-  <properties fileName="conf/testEqual.properties"/>
+  <properties fileName="testEqual.properties"/>
 </configuration>

Modified: jakarta/commons/proper/configuration/trunk/conf/testSequenceDigester.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/conf/testSequenceDigester.xml?rev=234275&r1=234274&r2=234275&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/conf/testSequenceDigester.xml (original)
+++ jakarta/commons/proper/configuration/trunk/conf/testSequenceDigester.xml Sun Aug 21 10:13:01
2005
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="ISO-8859-1" ?>
 
 <configuration>
-  <properties fileName="conf/testSequence.properties"/>
+  <properties fileName="testSequence.properties"/>
 </configuration>

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationFactory.java?rev=234275&r1=234274&r2=234275&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationFactory.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationFactory.java
Sun Aug 21 10:13:01 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License")
  * you may not use this file except in compliance with the License.
@@ -108,14 +108,14 @@
      */
     public ConfigurationFactory(String configurationFileName)
     {
-        this.configurationFileName = configurationFileName;
+        setConfigurationFileName(configurationFileName);
     }
 
     /**
      * Return the configuration provided by this factory. It loads the
      * configuration file which is a XML description of the actual
      * configurations to load. It can contain various different types of
-     * configuration, currently Properties, XML and JNDI.
+     * configuration, e.g. Properties, XML and JNDI.
      *
      * @return A Configuration object
      * @throws ConfigurationException A generic exception that we had trouble during the
@@ -220,15 +220,6 @@
     {
         configurationURL = url;
         implicitBasePath = url.toString();
-
-        // The following is a hack caused by the need to keep backwards
-        // compatibility: Per default the base path is set to the current
-        // directory. For loading from a URL this makes no sense. So
-        // unless no specific base path was set we clear it.
-        if (DEF_BASE_PATH.equals(getBasePath()))
-        {
-            setBasePath(null);
-        }
     }
 
     /**
@@ -421,8 +412,9 @@
      */
     public String getBasePath()
     {
-        String path = StringUtils.isEmpty(basePath) ? implicitBasePath : basePath;
-        return StringUtils.isEmpty(path) ? "." : path;
+        String path = StringUtils.isEmpty(basePath)
+                || DEF_BASE_PATH.equals(basePath) ? implicitBasePath : basePath;
+        return StringUtils.isEmpty(path) ? DEF_BASE_PATH : path;
     }
 
     /**

Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationFactory.java?rev=234275&r1=234274&r2=234275&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationFactory.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationFactory.java
Sun Aug 21 10:13:01 2005
@@ -166,6 +166,19 @@
     {
         factory.setConfigurationURL(testDigesterFileEnhanced.toURL());
         checkUnionConfig();
+        
+        factory = new ConfigurationFactory();
+        File nonExistingFile = new File("conf/nonexisting.xml");
+        factory.setConfigurationURL(nonExistingFile.toURL());
+        try
+        {
+            factory.getConfiguration();
+            fail("Could load non existing file!");
+        }
+        catch(ConfigurationException cex)
+        {
+            //ok
+        }
     }
 
     public void testLoadingFromJAR() throws Exception
@@ -278,6 +291,33 @@
                 testAbsConfig.delete();
             }
         }
+    }
+    
+    public void testBasePath() throws Exception
+    {
+        assertEquals(".", factory.getBasePath());
+        factory.setConfigurationFileName(testDigesterFile.getAbsolutePath());
+        // if no specific base path has been set, the base is determined
+        // from the file name
+        assertEquals(testDigesterFile.getParentFile().getAbsolutePath(),
+                factory.getBasePath());
+
+        String homeDir = System.getProperty("user.home");
+        factory = new ConfigurationFactory();
+        factory.setBasePath(homeDir);
+        factory.setConfigurationFileName(testDigesterFile.getAbsolutePath());
+        // if a base path was set, the file name does not play a role
+        assertEquals(homeDir, factory.getBasePath());
+        
+        factory = new ConfigurationFactory(testDigesterFile.getAbsolutePath());
+        assertEquals(testDigesterFile.getParentFile().getAbsolutePath(),
+                factory.getBasePath());
+        factory.setBasePath(homeDir);
+        assertEquals(homeDir, factory.getBasePath());
+        
+        factory = new ConfigurationFactory();
+        factory.setConfigurationURL(testDigesterFile.toURL());
+        assertEquals(testDigesterFile.toURL().toString(), factory.getBasePath());
     }
 
     private void checkUnionConfig() throws Exception

Modified: jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/xdocs/changes.xml?rev=234275&r1=234274&r2=234275&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Sun Aug 21 10:13:01 2005
@@ -23,6 +23,14 @@
   <body>
 
     <release version="1.2-dev" date="in SVN">
+      <action dev="oheger" type="update" issue="35316">
+        Fixed a bug in the handling of relative file names in ConfigurationFactory:
+        In most cases relative file names were not resolved relative to the
+        location of the configuration definition file as stated in the documentation.
+        This behavior was now changed to always be in sync with the documentation.
+        This may have an impact on existing code which uses workarounds for
+        the erroneous resolving mechanism.
+      </action>
       <action dev="oheger" type="update" issue="35963">
         Empty elements or elements whose content consists only of comments or
         whitespace are now taken into account by XMLConfiguration. They are



---------------------------------------------------------------------
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