You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by eb...@apache.org on 2008/02/15 00:13:43 UTC

svn commit: r627906 - in /commons/proper/configuration/branches/configuration2_experimental: ./ src/main/java/org/apache/commons/configuration2/ src/test/java/org/apache/commons/configuration2/

Author: ebourg
Date: Thu Feb 14 15:13:41 2008
New Revision: 627906

URL: http://svn.apache.org/viewvc?rev=627906&view=rev
Log:
Removed the JDK 1.4 specific code in EnvironmentConfiguration and dropped the dependency on Ant

Modified:
    commons/proper/configuration/branches/configuration2_experimental/build.xml
    commons/proper/configuration/branches/configuration2_experimental/gump.xml
    commons/proper/configuration/branches/configuration2_experimental/pom.xml
    commons/proper/configuration/branches/configuration2_experimental/project.xml
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/EnvironmentConfiguration.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestEnvironmentConfiguration.java

Modified: commons/proper/configuration/branches/configuration2_experimental/build.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/build.xml?rev=627906&r1=627905&r2=627906&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/build.xml (original)
+++ commons/proper/configuration/branches/configuration2_experimental/build.xml Thu Feb 14 15:13:41 2008
@@ -277,8 +277,6 @@
     </get>
     <get dest="${libdir}/mail-1.4.jar" usetimestamp="true" ignoreerrors="true" src="http://repo1.maven.org/maven2/javax/mail/mail/1.4/mail-1.4.jar">
     </get>
-    <get dest="${libdir}/ant-1.6.5.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/ant/jars/ant-1.6.5.jar">
-    </get>
   </target>
   <target name="install-maven">
     <get dest="${user.home}/maven-install-latest.jar" usetimestamp="true" src="${repo}/maven/maven-install-latest.jar">

Modified: commons/proper/configuration/branches/configuration2_experimental/gump.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/gump.xml?rev=627906&r1=627905&r2=627906&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/gump.xml (original)
+++ commons/proper/configuration/branches/configuration2_experimental/gump.xml Thu Feb 14 15:13:41 2008
@@ -26,8 +26,6 @@
     </depend>
     <depend project="dom4j">
     </depend>
-    <depend project="jakarta-ant">
-    </depend>
     <depend project="junit">
     </depend>
     <depend project="xml-apis">

Modified: commons/proper/configuration/branches/configuration2_experimental/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/pom.xml?rev=627906&r1=627905&r2=627906&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/pom.xml (original)
+++ commons/proper/configuration/branches/configuration2_experimental/pom.xml Thu Feb 14 15:13:41 2008
@@ -278,12 +278,6 @@
       <scope>provided</scope>
     </dependency>
 
-    <dependency>
-      <groupId>ant</groupId>
-      <artifactId>ant</artifactId>
-      <version>1.6.5</version>
-      <optional>true</optional>
-    </dependency>
 
     <!-- Needed for testing -->
 

Modified: commons/proper/configuration/branches/configuration2_experimental/project.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/project.xml?rev=627906&r1=627905&r2=627906&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/project.xml (original)
+++ commons/proper/configuration/branches/configuration2_experimental/project.xml Thu Feb 14 15:13:41 2008
@@ -350,15 +350,6 @@
       </properties>
     </dependency>
 
-    <dependency>
-      <groupId>ant</groupId>
-      <artifactId>ant</artifactId>
-      <version>1.6.5</version>
-      <properties>
-	    <optional>true</optional>
-      </properties>
-    </dependency>
-
     <!-- Needed for testing -->
 
     <dependency>

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/EnvironmentConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/EnvironmentConfiguration.java?rev=627906&r1=627905&r2=627906&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/EnvironmentConfiguration.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/EnvironmentConfiguration.java Thu Feb 14 15:13:41 2008
@@ -14,68 +14,40 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.commons.configuration2;
-
-import java.lang.reflect.Method;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
 
-import org.apache.commons.lang.SystemUtils;
-import org.apache.tools.ant.taskdefs.Execute;
+package org.apache.commons.configuration2;
 
 /**
- * <p>
- * A Configuration implementation that reads the platform specific environment
- * variables. On pre java5 JRE it uses Ant Execute task to read the environment.
- * (in this case ant must be present in classpath). On java >= 5 JRE it uses
- * {@link java.lang.System#getenv()} and ant is not required.
- * </p>
- * <p>
- * This configuration implementation is read-only. It allows read access to the
- * defined OS environment variables, but their values cannot be changed.
- * </p>
- * <p>
- * Usage of this class is easy: After an instance has been created the get
+ * <p>A Configuration implementation that reads the platform specific
+ * environment variables using the map returned by {@link System#getenv()}.</p>
+ *
+ * <p>This configuration implementation is read-only. It allows read access to the
+ * defined OS environment variables, but their values cannot be changed. Any
+ * attempts to add or remove a property will throw an
+ * {@link UnsupportedOperationException}</p>
+ *
+ * <p>Usage of this class is easy: After an instance has been created the get
  * methods provided by the <code>Configuration</code> interface can be used
- * for querying environment variables, e.g.:
+ * for querying environment variables, e.g.:</p>
  *
  * <pre>
  * Configuration envConfig = new EnvironmentConfiguration();
  * System.out.println("JAVA_HOME=" + envConfig.getString("JAVA_HOME");
  * </pre>
  *
- * </p>
- *
  * @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
- * @see org.apache.tools.ant.taskdefs.Execute#getProcEnvironment()
  * @since 1.5
  */
-public class EnvironmentConfiguration extends AbstractConfiguration
+public class EnvironmentConfiguration extends MapConfiguration
 {
-    /** Constant for the name of the getenv() method. */
-    private static final String METHOD_NAME = "getenv";
-
-    /** Constant for the Java version 1.5. */
-    private static final int VERSION_1_5 = 150;
-
-    /** Stores the environment properties. */
-    private Map environment;
-
     /**
-     * Constructor.
+     * Create a Configuration based on the environment variables.
+     *
+     * @see System#getenv()
      */
     public EnvironmentConfiguration()
     {
-        if (SystemUtils.isJavaVersionAtLeast(VERSION_1_5))
-        {
-            extractProperties15();
-        }
-        else
-        {
-            extractProperties14();
-        }
+        super(System.getenv());
     }
 
     /**
@@ -87,47 +59,7 @@
      */
     protected void addPropertyDirect(String key, Object value)
     {
-        throw new UnsupportedOperationException("Configuration is read-only!");
-    }
-
-    /**
-     * {@inheritDoc}
-     *
-     * @see org.apache.commons.configuration2.AbstractConfiguration#containsKey(java.lang.String)
-     */
-    public boolean containsKey(String key)
-    {
-        return environment.containsKey(key);
-    }
-
-    /**
-     * {@inheritDoc}
-     *
-     * @see org.apache.commons.configuration2.AbstractConfiguration#getKeys()
-     */
-    public Iterator getKeys()
-    {
-        return environment.keySet().iterator();
-    }
-
-    /**
-     * {@inheritDoc}
-     *
-     * @see org.apache.commons.configuration2.AbstractConfiguration#getProperty(java.lang.String)
-     */
-    public Object getProperty(String key)
-    {
-        return environment.get(key);
-    }
-
-    /**
-     * {@inheritDoc}
-     *
-     * @see org.apache.commons.configuration2.AbstractConfiguration#isEmpty()
-     */
-    public boolean isEmpty()
-    {
-        return environment.isEmpty();
+        throw new UnsupportedOperationException("EnvironmentConfiguration is read-only!");
     }
 
     /**
@@ -138,7 +70,7 @@
      */
     public void clearProperty(String key)
     {
-        throw new UnsupportedOperationException("Configuration is read-only!");
+        throw new UnsupportedOperationException("EnvironmentConfiguration is read-only!");
     }
 
     /**
@@ -148,62 +80,6 @@
      */
     public void clear()
     {
-        throw new UnsupportedOperationException("Configuration is read-only!");
-    }
-
-    /**
-     * Extracts environment properties on a JRE &lt; 1.5. This implementation
-     * uses ant for this purpose.
-     */
-    void extractProperties14()
-    {
-        extractPropertiesFromCollection(Execute.getProcEnvironment());
-    }
-
-    /**
-     * An internally used method for processing a collection with environment
-     * entries. The collection must contain strings like
-     * <code>property=value</code>. Such a collection is returned by ant.
-     *
-     * @param env the collection with the properties
-     */
-    void extractPropertiesFromCollection(Collection env)
-    {
-        environment = new HashMap();
-        for (Iterator it = env.iterator(); it.hasNext();)
-        {
-            String entry = (String) it.next();
-            int pos = entry.indexOf('=');
-            if (pos == -1)
-            {
-                getLogger().warn("Ignoring: " + entry);
-            }
-            else
-            {
-                environment.put(entry.substring(0, pos), entry
-                        .substring(pos + 1));
-            }
-        }
-    }
-
-    /**
-     * Extracts environment properties on a JR &gt;= 1.5. From this Java version
-     * on, there is an official way of doing this. However because the code
-     * should compile on lower Java versions, too, we have to invoke the method
-     * using reflection.
-     */
-    void extractProperties15()
-    {
-        try
-        {
-            Method method = System.class.getMethod(METHOD_NAME, null);
-            environment = (Map) method.invoke(null, null);
-        }
-        catch (Exception ex)
-        {
-            // this should normally not happen on a JRE >= 1.5
-            throw new ConfigurationRuntimeException(
-                    "Error when accessing environment properties", ex);
-        }
+        throw new UnsupportedOperationException("EnvironmentConfiguration is read-only!");
     }
 }

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestEnvironmentConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestEnvironmentConfiguration.java?rev=627906&r1=627905&r2=627906&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestEnvironmentConfiguration.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestEnvironmentConfiguration.java Thu Feb 14 15:13:41 2008
@@ -16,13 +16,7 @@
  */
 package org.apache.commons.configuration2;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
 import java.util.Iterator;
-import java.util.Map;
-
-import org.apache.commons.configuration2.EnvironmentConfiguration;
 
 import junit.framework.TestCase;
 
@@ -69,49 +63,6 @@
     public void testInit()
     {
         checkProperties();
-    }
-
-    /**
-     * Tests extracting properties for JDK before 1.5. This method should work
-     * on later JDKs, too, so we can test it always.
-     */
-    public void testExtractProperties14()
-    {
-        config.extractProperties14();
-        checkProperties();
-    }
-
-    /**
-     * Tests whether a collection with properties is correctly processed.
-     */
-    public void testExtractPropertiesFromCollection()
-    {
-        final int count = 8;
-        final String prop = "property";
-        final String value = "value";
-
-        Collection env = new ArrayList(count);
-        for (int i = 0; i < count; i++)
-        {
-            env.add(prop + i + "=" + value + i);
-        }
-        env.add("irregularProperty");
-        config.extractPropertiesFromCollection(env);
-
-        Map props = new HashMap();
-        for (Iterator it = config.getKeys(); it.hasNext();)
-        {
-            String key = (String) it.next();
-            props.put(key, config.getString(key));
-        }
-        assertEquals("Wrong number of properties", count, props.size());
-        for (int i = 0; i < count; i++)
-        {
-            assertEquals("Wrong value for property " + i, value + i, props
-                    .get(prop + i));
-        }
-        assertFalse("Irregular property found", config
-                .containsKey("irregularProperty"));
     }
 
     /**



Re: svn commit: r627906 - in /commons/proper/configuration/branches/configuration2_experimental: ./ src/main/java/org/apache/commons/configuration2/ src/test/java/org/apache/commons/configuration2/

Posted by simon <si...@chello.at>.
Yeah, and maven1 is pretty much dead. Providing Ant + maven2 should make
the vast majority of users happy.

On Sat, 2008-02-16 at 22:02 +0100, Emmanuel Bourg wrote:
> I agree, it's a burden to maintain otherwise.
> 
> Emmanuel Bourg
> 
> 
> Oliver Heger a écrit :
> > With regards to the build files: I was thinking about dropping the maven 
> > 1 build at all and make maven 2 to the default build tool. An ant build 
> > could still be provided, but hopefully it is possible to generate 
> > build.xml from the pom.
> > 
> > Oliver
> > 
> > ebourg@apache.org schrieb:
> >> Author: ebourg
> >> Date: Thu Feb 14 15:13:41 2008
> >> New Revision: 627906
> >>
> >> URL: http://svn.apache.org/viewvc?rev=627906&view=rev
> >> Log:
> >> Removed the JDK 1.4 specific code in EnvironmentConfiguration and 
> >> dropped the dependency on Ant
> >>
> >> Modified:
> >>     
> >> commons/proper/configuration/branches/configuration2_experimental/build.xml 
> >>
> >>     
> >> commons/proper/configuration/branches/configuration2_experimental/gump.xml 
> >>
> >>     
> >> commons/proper/configuration/branches/configuration2_experimental/pom.xml
> >>     
> >> commons/proper/configuration/branches/configuration2_experimental/project.xml 
> >>
> >>     
> >> commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/EnvironmentConfiguration.java 
> >>
> >>     
> >> commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestEnvironmentConfiguration.java 
> >>
> >>
> > <snip/>
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> > For additional commands, e-mail: dev-help@commons.apache.org
> > 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
> 


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


Re: svn commit: r627906 - in /commons/proper/configuration/branches/configuration2_experimental: ./ src/main/java/org/apache/commons/configuration2/ src/test/java/org/apache/commons/configuration2/

Posted by Emmanuel Bourg <eb...@apache.org>.
I agree, it's a burden to maintain otherwise.

Emmanuel Bourg


Oliver Heger a écrit :
> With regards to the build files: I was thinking about dropping the maven 
> 1 build at all and make maven 2 to the default build tool. An ant build 
> could still be provided, but hopefully it is possible to generate 
> build.xml from the pom.
> 
> Oliver
> 
> ebourg@apache.org schrieb:
>> Author: ebourg
>> Date: Thu Feb 14 15:13:41 2008
>> New Revision: 627906
>>
>> URL: http://svn.apache.org/viewvc?rev=627906&view=rev
>> Log:
>> Removed the JDK 1.4 specific code in EnvironmentConfiguration and 
>> dropped the dependency on Ant
>>
>> Modified:
>>     
>> commons/proper/configuration/branches/configuration2_experimental/build.xml 
>>
>>     
>> commons/proper/configuration/branches/configuration2_experimental/gump.xml 
>>
>>     
>> commons/proper/configuration/branches/configuration2_experimental/pom.xml
>>     
>> commons/proper/configuration/branches/configuration2_experimental/project.xml 
>>
>>     
>> commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/EnvironmentConfiguration.java 
>>
>>     
>> commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestEnvironmentConfiguration.java 
>>
>>
> <snip/>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
> 

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


Re: svn commit: r627906 - in /commons/proper/configuration/branches/configuration2_experimental: ./ src/main/java/org/apache/commons/configuration2/ src/test/java/org/apache/commons/configuration2/

Posted by Oliver Heger <ol...@oliver-heger.de>.
With regards to the build files: I was thinking about dropping the maven 
1 build at all and make maven 2 to the default build tool. An ant build 
could still be provided, but hopefully it is possible to generate 
build.xml from the pom.

Oliver

ebourg@apache.org schrieb:
> Author: ebourg
> Date: Thu Feb 14 15:13:41 2008
> New Revision: 627906
> 
> URL: http://svn.apache.org/viewvc?rev=627906&view=rev
> Log:
> Removed the JDK 1.4 specific code in EnvironmentConfiguration and dropped the dependency on Ant
> 
> Modified:
>     commons/proper/configuration/branches/configuration2_experimental/build.xml
>     commons/proper/configuration/branches/configuration2_experimental/gump.xml
>     commons/proper/configuration/branches/configuration2_experimental/pom.xml
>     commons/proper/configuration/branches/configuration2_experimental/project.xml
>     commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/EnvironmentConfiguration.java
>     commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestEnvironmentConfiguration.java
> 
<snip/>

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