git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271466 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -45,14 +45,6 @@ public class ExecMetaData | |||||
| */ | */ | ||||
| private Properties m_environment; | private Properties m_environment; | ||||
| /** | |||||
| * If this variable is true then then the environment specified is | |||||
| * added to the environment variables for current process. If this | |||||
| * value is false then the specified environment replaces the environment | |||||
| * for the command. | |||||
| */ | |||||
| private boolean m_isEnvironmentAdditive; | |||||
| /** | /** | ||||
| * Construct the meta data for executable as appropriate. | * Construct the meta data for executable as appropriate. | ||||
| * Note that it is invalid to specify a <code>null</code> | * Note that it is invalid to specify a <code>null</code> | ||||
| @@ -61,13 +53,11 @@ public class ExecMetaData | |||||
| */ | */ | ||||
| public ExecMetaData( final String[] command, | public ExecMetaData( final String[] command, | ||||
| final Properties environment, | final Properties environment, | ||||
| final File workingDirectory, | |||||
| final boolean environmentAdditive ) | |||||
| final File workingDirectory ) | |||||
| { | { | ||||
| m_command = command; | m_command = command; | ||||
| m_environment = environment; | m_environment = environment; | ||||
| m_workingDirectory = workingDirectory; | m_workingDirectory = workingDirectory; | ||||
| m_isEnvironmentAdditive = environmentAdditive; | |||||
| if( null == m_workingDirectory ) | if( null == m_workingDirectory ) | ||||
| { | { | ||||
| @@ -78,11 +68,6 @@ public class ExecMetaData | |||||
| { | { | ||||
| throw new NullPointerException( "command" ); | throw new NullPointerException( "command" ); | ||||
| } | } | ||||
| if( null == m_environment && m_isEnvironmentAdditive ) | |||||
| { | |||||
| throw new IllegalArgumentException( "isEnvironmentAdditive" ); | |||||
| } | |||||
| } | } | ||||
| public File getWorkingDirectory() | public File getWorkingDirectory() | ||||
| @@ -99,9 +84,4 @@ public class ExecMetaData | |||||
| { | { | ||||
| return m_environment; | return m_environment; | ||||
| } | } | ||||
| public boolean isEnvironmentAdditive() | |||||
| { | |||||
| return m_isEnvironmentAdditive; | |||||
| } | |||||
| } | } | ||||
| @@ -112,9 +112,8 @@ public class DefaultExecManager | |||||
| final long timeout ) | final long timeout ) | ||||
| throws IOException, ExecException | throws IOException, ExecException | ||||
| { | { | ||||
| final ExecMetaData metaData = prepareExecMetaData( command ); | |||||
| final CommandLauncher launcher = getLauncher( metaData ); | |||||
| final Process process = launcher.exec( metaData ); | |||||
| final CommandLauncher launcher = getLauncher( command ); | |||||
| final Process process = launcher.exec( command ); | |||||
| final ProcessMonitor monitor = | final ProcessMonitor monitor = | ||||
| new ProcessMonitor( process, input, output, error, timeout ); | new ProcessMonitor( process, input, output, error, timeout ); | ||||
| @@ -160,30 +159,6 @@ public class DefaultExecManager | |||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * Utility method to preapre a metaData object. | |||||
| * This involves adding the native environment to the metaData if the | |||||
| * metaData is specified as being additive. | |||||
| */ | |||||
| private ExecMetaData prepareExecMetaData( final ExecMetaData metaData ) | |||||
| throws ExecException | |||||
| { | |||||
| if( !metaData.isEnvironmentAdditive() ) | |||||
| { | |||||
| return metaData; | |||||
| } | |||||
| else | |||||
| { | |||||
| final Properties newEnvironment = new Properties(); | |||||
| newEnvironment.putAll( getNativeEnvironment() ); | |||||
| newEnvironment.putAll( metaData.getEnvironment() ); | |||||
| return new ExecMetaData( metaData.getCommand(), | |||||
| newEnvironment, | |||||
| metaData.getWorkingDirectory(), | |||||
| false ); | |||||
| } | |||||
| } | |||||
| private CommandLauncher getLauncher( final ExecMetaData metaData ) | private CommandLauncher getLauncher( final ExecMetaData metaData ) | ||||
| { | { | ||||
| CommandLauncher launcher = m_launcher; | CommandLauncher launcher = m_launcher; | ||||
| @@ -154,7 +154,7 @@ final class Environment | |||||
| { | { | ||||
| final String[] command = getEnvCommand(); | final String[] command = getEnvCommand(); | ||||
| final File workingDirectory = new File( "." ); | final File workingDirectory = new File( "." ); | ||||
| final ExecMetaData metaData = new ExecMetaData( command, null, workingDirectory, false ); | |||||
| final ExecMetaData metaData = new ExecMetaData( command, null, workingDirectory ); | |||||
| final ByteArrayOutputStream output = new ByteArrayOutputStream(); | final ByteArrayOutputStream output = new ByteArrayOutputStream(); | ||||
| final int retval = m_execManager.execute( metaData, null, output, output, 0 ); | final int retval = m_execManager.execute( metaData, null, output, output, 0 ); | ||||
| @@ -64,8 +64,7 @@ class ExecUtil | |||||
| return new ExecMetaData( command, | return new ExecMetaData( command, | ||||
| metaData.getEnvironment(), | metaData.getEnvironment(), | ||||
| metaData.getWorkingDirectory(), | |||||
| metaData.isEnvironmentAdditive() ); | |||||
| metaData.getWorkingDirectory() ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -80,11 +80,12 @@ public class Execute | |||||
| } | } | ||||
| /** | /** | ||||
| * Set whether to propagate the default environment or not. | |||||
| * | |||||
| * @param newEnvironment whether to propagate the process environment. | |||||
| * If this variable is false then then the environment specified is | |||||
| * added to the environment variables for current process. If this | |||||
| * value is true then the specified environment replaces the environment | |||||
| * for the command. | |||||
| */ | */ | ||||
| public void setNewenvironment( boolean newEnvironment ) | |||||
| public void setNewenvironment( final boolean newEnvironment ) | |||||
| { | { | ||||
| m_newEnvironment = newEnvironment; | m_newEnvironment = newEnvironment; | ||||
| } | } | ||||
| @@ -137,9 +138,9 @@ public class Execute | |||||
| private int executeNativeProcess() | private int executeNativeProcess() | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| final ExecMetaData metaData = buildExecMetaData(); | |||||
| try | try | ||||
| { | { | ||||
| final ExecMetaData metaData = buildExecMetaData(); | |||||
| if( null != m_handler ) | if( null != m_handler ) | ||||
| { | { | ||||
| return m_execManager.execute( metaData, m_handler, m_timeout ); | return m_execManager.execute( metaData, m_handler, m_timeout ); | ||||
| @@ -168,12 +169,19 @@ public class Execute | |||||
| * to pass to the ExecManager service. | * to pass to the ExecManager service. | ||||
| */ | */ | ||||
| private ExecMetaData buildExecMetaData() | private ExecMetaData buildExecMetaData() | ||||
| throws ExecException | |||||
| { | { | ||||
| final String[] command = m_command.getCommandline(); | final String[] command = m_command.getCommandline(); | ||||
| final Properties newEnvironment = new Properties(); | |||||
| if( !m_newEnvironment ) | |||||
| { | |||||
| newEnvironment.putAll( m_execManager.getNativeEnvironment() ); | |||||
| } | |||||
| newEnvironment.putAll( m_environment ); | |||||
| return new ExecMetaData( command, | return new ExecMetaData( command, | ||||
| m_environment, | |||||
| m_workingDirectory, | |||||
| m_newEnvironment ); | |||||
| newEnvironment, | |||||
| m_workingDirectory ); | |||||
| } | } | ||||
| } | } | ||||