From b8a71bf8463f8c38c404467a5aef7c451569ad50 Mon Sep 17 00:00:00 2001 From: Peter Donald Date: Sat, 22 Dec 2001 13:00:02 +0000 Subject: [PATCH] load environment data from new Environment class. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270313 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/taskdefs/Property.java | 40 +++++++++++-------- .../apache/tools/ant/taskdefs/Property.java | 40 +++++++++++-------- 2 files changed, 48 insertions(+), 32 deletions(-) diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Property.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Property.java index eda9c8e25..e64d5c181 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Property.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Property.java @@ -11,15 +11,14 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.util.Enumeration; import java.util.Iterator; import java.util.Properties; -import java.util.ArrayList; -import java.util.Enumeration; import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.framework.exec.Environment; import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; -import org.apache.tools.ant.taskdefs.exec.Execute; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Reference; @@ -210,25 +209,34 @@ public class Property extends Task protected void loadEnvironment( String prefix ) throws TaskException { - Properties props = new Properties(); + final Properties props = new Properties(); if( !prefix.endsWith( "." ) ) prefix += "."; - log( "Loading Environment " + prefix, Project.MSG_VERBOSE ); - ArrayList osEnv = Execute.getProcEnvironment(); - for( Iterator e = osEnv.iterator(); e.hasNext(); ) + + log( "Loading EnvironmentData " + prefix, Project.MSG_VERBOSE ); + try { - String entry = (String)e.next(); - int pos = entry.indexOf( '=' ); - if( pos == -1 ) - { - log( "Ignoring: " + entry, Project.MSG_WARN ); - } - else + final Properties environment = Environment.getNativeEnvironment(); + for( Iterator e = environment.keySet().iterator(); e.hasNext(); ) { - props.put( prefix + entry.substring( 0, pos ), - entry.substring( pos + 1 ) ); + final String key = (String)e.next(); + final String value = environment.getProperty( key ); + + if( value.equals( "" ) ) + { + log( "Ignoring: " + key, Project.MSG_WARN ); + } + else + { + props.put( prefix + key, value ); + } } } + catch( final IOException ioe ) + { + throw new TaskException( ioe.getMessage(), ioe ); + } + addProperties( props ); } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Property.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Property.java index eda9c8e25..e64d5c181 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Property.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Property.java @@ -11,15 +11,14 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.util.Enumeration; import java.util.Iterator; import java.util.Properties; -import java.util.ArrayList; -import java.util.Enumeration; import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.framework.exec.Environment; import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; -import org.apache.tools.ant.taskdefs.exec.Execute; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Reference; @@ -210,25 +209,34 @@ public class Property extends Task protected void loadEnvironment( String prefix ) throws TaskException { - Properties props = new Properties(); + final Properties props = new Properties(); if( !prefix.endsWith( "." ) ) prefix += "."; - log( "Loading Environment " + prefix, Project.MSG_VERBOSE ); - ArrayList osEnv = Execute.getProcEnvironment(); - for( Iterator e = osEnv.iterator(); e.hasNext(); ) + + log( "Loading EnvironmentData " + prefix, Project.MSG_VERBOSE ); + try { - String entry = (String)e.next(); - int pos = entry.indexOf( '=' ); - if( pos == -1 ) - { - log( "Ignoring: " + entry, Project.MSG_WARN ); - } - else + final Properties environment = Environment.getNativeEnvironment(); + for( Iterator e = environment.keySet().iterator(); e.hasNext(); ) { - props.put( prefix + entry.substring( 0, pos ), - entry.substring( pos + 1 ) ); + final String key = (String)e.next(); + final String value = environment.getProperty( key ); + + if( value.equals( "" ) ) + { + log( "Ignoring: " + key, Project.MSG_WARN ); + } + else + { + props.put( prefix + key, value ); + } } } + catch( final IOException ioe ) + { + throw new TaskException( ioe.getMessage(), ioe ); + } + addProperties( props ); }