git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270320 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -14,6 +14,8 @@ import java.io.FileNotFoundException; | |||
| import java.io.FileOutputStream; | |||
| import java.io.IOException; | |||
| import java.io.StringReader; | |||
| import java.util.Iterator; | |||
| import java.util.Properties; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.Task; | |||
| @@ -392,19 +394,20 @@ public class ExecTask extends Task | |||
| // show the command | |||
| log( cmdl.toString(), Project.MSG_VERBOSE ); | |||
| Execute exe = new Execute( createHandler(), createWatchdog() ); | |||
| final Execute exe = new Execute( createHandler(), createWatchdog() ); | |||
| exe.setWorkingDirectory( dir ); | |||
| exe.setVMLauncher( vmLauncher ); | |||
| String[] environment = env.getVariables(); | |||
| if( environment != null ) | |||
| exe.setNewenvironment( newEnvironment ); | |||
| final Properties environment = env.getVariables(); | |||
| final Iterator keys = environment.keySet().iterator(); | |||
| while( keys.hasNext() ) | |||
| { | |||
| for( int i = 0; i < environment.length; i++ ) | |||
| { | |||
| log( "Setting environment variable: " + environment[ i ], | |||
| Project.MSG_VERBOSE ); | |||
| } | |||
| final String key = (String)keys.next(); | |||
| final String value = environment.getProperty( key ); | |||
| log( "Setting environment variable: " + key + "=" + value, | |||
| Project.MSG_VERBOSE ); | |||
| } | |||
| exe.setNewenvironment( newEnvironment ); | |||
| exe.setEnvironment( environment ); | |||
| return exe; | |||
| } | |||
| @@ -33,13 +33,8 @@ import org.apache.tools.ant.types.Commandline; | |||
| */ | |||
| public class Execute | |||
| { | |||
| /** | |||
| * Invalid exit code. | |||
| */ | |||
| public final static int INVALID = Integer.MAX_VALUE; | |||
| private static final CommandLauncher c_launcher = new DefaultCommandLauncher(); | |||
| private static CommandLauncher c_shellLauncher; | |||
| private static final CommandLauncher c_shellLauncher = createShellLauncher(); | |||
| /** | |||
| * Used to destroy processes when the VM exits. | |||
| @@ -49,7 +44,7 @@ public class Execute | |||
| private ExecMetaData m_metaData; | |||
| private String[] m_command; | |||
| private Properties m_environment; | |||
| private int m_exitValue = INVALID; | |||
| private int m_exitValue; | |||
| private File m_workingDirectory = new File( "." ); | |||
| private Project m_project; | |||
| private boolean m_newEnvironment; | |||
| @@ -61,14 +56,6 @@ public class Execute | |||
| private ExecuteStreamHandler m_streamHandler; | |||
| private ExecuteWatchdog m_watchdog; | |||
| /** | |||
| * Builds a command launcher for the OS and JVM we are running under | |||
| */ | |||
| static | |||
| { | |||
| c_shellLauncher = createShellLauncher(); | |||
| } | |||
| private static CommandLauncher createShellLauncher() | |||
| { | |||
| CommandLauncher launcher = null; | |||
| @@ -12,6 +12,7 @@ import java.util.Iterator; | |||
| import java.util.Properties; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.framework.Os; | |||
| import org.apache.myrmidon.framework.exec.Environment; | |||
| import org.apache.tools.ant.Project; | |||
| /** | |||
| @@ -136,7 +137,7 @@ public class CommandlineJava implements Cloneable | |||
| // properties are part of the vm options... | |||
| if( sysProperties.size() > 0 ) | |||
| { | |||
| System.arraycopy( sysProperties.getVariables(), 0, | |||
| System.arraycopy( sysProperties.getJavaVariables(), 0, | |||
| result, pos, sysProperties.size() ); | |||
| pos += sysProperties.size(); | |||
| } | |||
| @@ -338,7 +339,7 @@ public class CommandlineJava implements Cloneable | |||
| { | |||
| Properties p = new Properties( sys = System.getProperties() ); | |||
| for( Iterator e = variables.iterator(); e.hasNext(); ) | |||
| for( Iterator e = m_variables.iterator(); e.hasNext(); ) | |||
| { | |||
| EnvironmentData.Variable v = (EnvironmentData.Variable)e.next(); | |||
| p.put( v.getKey(), v.getValue() ); | |||
| @@ -351,10 +352,10 @@ public class CommandlineJava implements Cloneable | |||
| } | |||
| } | |||
| public String[] getVariables() | |||
| public String[] getJavaVariables() | |||
| throws TaskException | |||
| { | |||
| String props[] = super.getVariables(); | |||
| String props[] = Environment.toNativeFormat( super.getVariables() ); | |||
| if( props == null ) | |||
| return null; | |||
| @@ -371,7 +372,7 @@ public class CommandlineJava implements Cloneable | |||
| try | |||
| { | |||
| SysProperties c = (SysProperties)super.clone(); | |||
| c.variables = (ArrayList)variables.clone(); | |||
| c.m_variables.addAll( (ArrayList)m_variables.clone() ); | |||
| return c; | |||
| } | |||
| catch( CloneNotSupportedException e ) | |||
| @@ -399,7 +400,7 @@ public class CommandlineJava implements Cloneable | |||
| public int size() | |||
| { | |||
| return variables.size(); | |||
| return m_variables.size(); | |||
| } | |||
| } | |||
| @@ -8,6 +8,8 @@ | |||
| package org.apache.tools.ant.types; | |||
| import java.util.ArrayList; | |||
| import java.util.Properties; | |||
| import java.io.File; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| /** | |||
| @@ -17,82 +19,59 @@ import org.apache.myrmidon.api.TaskException; | |||
| */ | |||
| public class EnvironmentData | |||
| { | |||
| protected ArrayList variables; | |||
| protected final ArrayList m_variables = new ArrayList(); | |||
| public EnvironmentData() | |||
| { | |||
| variables = new ArrayList(); | |||
| } | |||
| public String[] getVariables() | |||
| public Properties getVariables() | |||
| throws TaskException | |||
| { | |||
| if( variables.size() == 0 ) | |||
| final Properties environment = new Properties(); | |||
| final int size = m_variables.size(); | |||
| for( int i = 0; i < size; i++ ) | |||
| { | |||
| return null; | |||
| final Variable variable = (Variable)m_variables.get( i ); | |||
| environment.setProperty( variable.getKey(), variable.getValue() ); | |||
| } | |||
| String[] result = new String[ variables.size() ]; | |||
| for( int i = 0; i < result.length; i++ ) | |||
| { | |||
| result[ i ] = ( (Variable)variables.get( i ) ).getContent(); | |||
| } | |||
| return result; | |||
| return environment; | |||
| } | |||
| public void addVariable( Variable var ) | |||
| { | |||
| variables.add( var ); | |||
| m_variables.add( var ); | |||
| } | |||
| public static class Variable | |||
| { | |||
| private String key, value; | |||
| public Variable() | |||
| { | |||
| super(); | |||
| } | |||
| public void setFile( java.io.File file ) | |||
| { | |||
| this.value = file.getAbsolutePath(); | |||
| } | |||
| private String m_key; | |||
| private String m_value; | |||
| public void setKey( String key ) | |||
| public void setFile( final File file ) | |||
| { | |||
| this.key = key; | |||
| m_value = file.getAbsolutePath(); | |||
| } | |||
| public void setPath( Path path ) | |||
| public void setKey( final String key ) | |||
| { | |||
| this.value = path.toString(); | |||
| m_key = key; | |||
| } | |||
| public void setValue( String value ) | |||
| public void setPath( final Path path ) | |||
| { | |||
| this.value = value; | |||
| m_value = path.toString(); | |||
| } | |||
| public String getContent() | |||
| throws TaskException | |||
| public void setValue( final String value ) | |||
| { | |||
| if( key == null || value == null ) | |||
| { | |||
| throw new TaskException( "key and value must be specified for environment variables." ); | |||
| } | |||
| StringBuffer sb = new StringBuffer( key.trim() ); | |||
| sb.append( "=" ).append( value.trim() ); | |||
| return sb.toString(); | |||
| m_value = value; | |||
| } | |||
| public String getKey() | |||
| { | |||
| return this.key; | |||
| return m_key; | |||
| } | |||
| public String getValue() | |||
| { | |||
| return this.value; | |||
| return m_value; | |||
| } | |||
| } | |||
| } | |||
| @@ -14,6 +14,8 @@ import java.io.FileNotFoundException; | |||
| import java.io.FileOutputStream; | |||
| import java.io.IOException; | |||
| import java.io.StringReader; | |||
| import java.util.Iterator; | |||
| import java.util.Properties; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.Task; | |||
| @@ -392,19 +394,20 @@ public class ExecTask extends Task | |||
| // show the command | |||
| log( cmdl.toString(), Project.MSG_VERBOSE ); | |||
| Execute exe = new Execute( createHandler(), createWatchdog() ); | |||
| final Execute exe = new Execute( createHandler(), createWatchdog() ); | |||
| exe.setWorkingDirectory( dir ); | |||
| exe.setVMLauncher( vmLauncher ); | |||
| String[] environment = env.getVariables(); | |||
| if( environment != null ) | |||
| exe.setNewenvironment( newEnvironment ); | |||
| final Properties environment = env.getVariables(); | |||
| final Iterator keys = environment.keySet().iterator(); | |||
| while( keys.hasNext() ) | |||
| { | |||
| for( int i = 0; i < environment.length; i++ ) | |||
| { | |||
| log( "Setting environment variable: " + environment[ i ], | |||
| Project.MSG_VERBOSE ); | |||
| } | |||
| final String key = (String)keys.next(); | |||
| final String value = environment.getProperty( key ); | |||
| log( "Setting environment variable: " + key + "=" + value, | |||
| Project.MSG_VERBOSE ); | |||
| } | |||
| exe.setNewenvironment( newEnvironment ); | |||
| exe.setEnvironment( environment ); | |||
| return exe; | |||
| } | |||
| @@ -33,13 +33,8 @@ import org.apache.tools.ant.types.Commandline; | |||
| */ | |||
| public class Execute | |||
| { | |||
| /** | |||
| * Invalid exit code. | |||
| */ | |||
| public final static int INVALID = Integer.MAX_VALUE; | |||
| private static final CommandLauncher c_launcher = new DefaultCommandLauncher(); | |||
| private static CommandLauncher c_shellLauncher; | |||
| private static final CommandLauncher c_shellLauncher = createShellLauncher(); | |||
| /** | |||
| * Used to destroy processes when the VM exits. | |||
| @@ -49,7 +44,7 @@ public class Execute | |||
| private ExecMetaData m_metaData; | |||
| private String[] m_command; | |||
| private Properties m_environment; | |||
| private int m_exitValue = INVALID; | |||
| private int m_exitValue; | |||
| private File m_workingDirectory = new File( "." ); | |||
| private Project m_project; | |||
| private boolean m_newEnvironment; | |||
| @@ -61,14 +56,6 @@ public class Execute | |||
| private ExecuteStreamHandler m_streamHandler; | |||
| private ExecuteWatchdog m_watchdog; | |||
| /** | |||
| * Builds a command launcher for the OS and JVM we are running under | |||
| */ | |||
| static | |||
| { | |||
| c_shellLauncher = createShellLauncher(); | |||
| } | |||
| private static CommandLauncher createShellLauncher() | |||
| { | |||
| CommandLauncher launcher = null; | |||
| @@ -12,6 +12,7 @@ import java.util.Iterator; | |||
| import java.util.Properties; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.framework.Os; | |||
| import org.apache.myrmidon.framework.exec.Environment; | |||
| import org.apache.tools.ant.Project; | |||
| /** | |||
| @@ -136,7 +137,7 @@ public class CommandlineJava implements Cloneable | |||
| // properties are part of the vm options... | |||
| if( sysProperties.size() > 0 ) | |||
| { | |||
| System.arraycopy( sysProperties.getVariables(), 0, | |||
| System.arraycopy( sysProperties.getJavaVariables(), 0, | |||
| result, pos, sysProperties.size() ); | |||
| pos += sysProperties.size(); | |||
| } | |||
| @@ -338,7 +339,7 @@ public class CommandlineJava implements Cloneable | |||
| { | |||
| Properties p = new Properties( sys = System.getProperties() ); | |||
| for( Iterator e = variables.iterator(); e.hasNext(); ) | |||
| for( Iterator e = m_variables.iterator(); e.hasNext(); ) | |||
| { | |||
| EnvironmentData.Variable v = (EnvironmentData.Variable)e.next(); | |||
| p.put( v.getKey(), v.getValue() ); | |||
| @@ -351,10 +352,10 @@ public class CommandlineJava implements Cloneable | |||
| } | |||
| } | |||
| public String[] getVariables() | |||
| public String[] getJavaVariables() | |||
| throws TaskException | |||
| { | |||
| String props[] = super.getVariables(); | |||
| String props[] = Environment.toNativeFormat( super.getVariables() ); | |||
| if( props == null ) | |||
| return null; | |||
| @@ -371,7 +372,7 @@ public class CommandlineJava implements Cloneable | |||
| try | |||
| { | |||
| SysProperties c = (SysProperties)super.clone(); | |||
| c.variables = (ArrayList)variables.clone(); | |||
| c.m_variables.addAll( (ArrayList)m_variables.clone() ); | |||
| return c; | |||
| } | |||
| catch( CloneNotSupportedException e ) | |||
| @@ -399,7 +400,7 @@ public class CommandlineJava implements Cloneable | |||
| public int size() | |||
| { | |||
| return variables.size(); | |||
| return m_variables.size(); | |||
| } | |||
| } | |||
| @@ -8,6 +8,8 @@ | |||
| package org.apache.tools.ant.types; | |||
| import java.util.ArrayList; | |||
| import java.util.Properties; | |||
| import java.io.File; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| /** | |||
| @@ -17,82 +19,59 @@ import org.apache.myrmidon.api.TaskException; | |||
| */ | |||
| public class EnvironmentData | |||
| { | |||
| protected ArrayList variables; | |||
| protected final ArrayList m_variables = new ArrayList(); | |||
| public EnvironmentData() | |||
| { | |||
| variables = new ArrayList(); | |||
| } | |||
| public String[] getVariables() | |||
| public Properties getVariables() | |||
| throws TaskException | |||
| { | |||
| if( variables.size() == 0 ) | |||
| final Properties environment = new Properties(); | |||
| final int size = m_variables.size(); | |||
| for( int i = 0; i < size; i++ ) | |||
| { | |||
| return null; | |||
| final Variable variable = (Variable)m_variables.get( i ); | |||
| environment.setProperty( variable.getKey(), variable.getValue() ); | |||
| } | |||
| String[] result = new String[ variables.size() ]; | |||
| for( int i = 0; i < result.length; i++ ) | |||
| { | |||
| result[ i ] = ( (Variable)variables.get( i ) ).getContent(); | |||
| } | |||
| return result; | |||
| return environment; | |||
| } | |||
| public void addVariable( Variable var ) | |||
| { | |||
| variables.add( var ); | |||
| m_variables.add( var ); | |||
| } | |||
| public static class Variable | |||
| { | |||
| private String key, value; | |||
| public Variable() | |||
| { | |||
| super(); | |||
| } | |||
| public void setFile( java.io.File file ) | |||
| { | |||
| this.value = file.getAbsolutePath(); | |||
| } | |||
| private String m_key; | |||
| private String m_value; | |||
| public void setKey( String key ) | |||
| public void setFile( final File file ) | |||
| { | |||
| this.key = key; | |||
| m_value = file.getAbsolutePath(); | |||
| } | |||
| public void setPath( Path path ) | |||
| public void setKey( final String key ) | |||
| { | |||
| this.value = path.toString(); | |||
| m_key = key; | |||
| } | |||
| public void setValue( String value ) | |||
| public void setPath( final Path path ) | |||
| { | |||
| this.value = value; | |||
| m_value = path.toString(); | |||
| } | |||
| public String getContent() | |||
| throws TaskException | |||
| public void setValue( final String value ) | |||
| { | |||
| if( key == null || value == null ) | |||
| { | |||
| throw new TaskException( "key and value must be specified for environment variables." ); | |||
| } | |||
| StringBuffer sb = new StringBuffer( key.trim() ); | |||
| sb.append( "=" ).append( value.trim() ); | |||
| return sb.toString(); | |||
| m_value = value; | |||
| } | |||
| public String getKey() | |||
| { | |||
| return this.key; | |||
| return m_key; | |||
| } | |||
| public String getValue() | |||
| { | |||
| return this.value; | |||
| return m_value; | |||
| } | |||
| } | |||
| } | |||