Browse Source

Reworked the ExecManager service so that the Execute adapter object becomes responsible for combining supplied env vars with native env vars if required

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271466 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 23 years ago
parent
commit
da8ec4fa38
5 changed files with 21 additions and 59 deletions
  1. +1
    -21
      proposal/myrmidon/src/java/org/apache/aut/nativelib/ExecMetaData.java
  2. +2
    -27
      proposal/myrmidon/src/java/org/apache/aut/nativelib/impl/DefaultExecManager.java
  3. +1
    -1
      proposal/myrmidon/src/java/org/apache/aut/nativelib/impl/Environment.java
  4. +1
    -2
      proposal/myrmidon/src/java/org/apache/aut/nativelib/impl/launchers/ExecUtil.java
  5. +16
    -8
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/Execute.java

+ 1
- 21
proposal/myrmidon/src/java/org/apache/aut/nativelib/ExecMetaData.java View File

@@ -45,14 +45,6 @@ public class ExecMetaData
*/
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.
* Note that it is invalid to specify a <code>null</code>
@@ -61,13 +53,11 @@ public class ExecMetaData
*/
public ExecMetaData( final String[] command,
final Properties environment,
final File workingDirectory,
final boolean environmentAdditive )
final File workingDirectory )
{
m_command = command;
m_environment = environment;
m_workingDirectory = workingDirectory;
m_isEnvironmentAdditive = environmentAdditive;

if( null == m_workingDirectory )
{
@@ -78,11 +68,6 @@ public class ExecMetaData
{
throw new NullPointerException( "command" );
}

if( null == m_environment && m_isEnvironmentAdditive )
{
throw new IllegalArgumentException( "isEnvironmentAdditive" );
}
}

public File getWorkingDirectory()
@@ -99,9 +84,4 @@ public class ExecMetaData
{
return m_environment;
}

public boolean isEnvironmentAdditive()
{
return m_isEnvironmentAdditive;
}
}

+ 2
- 27
proposal/myrmidon/src/java/org/apache/aut/nativelib/impl/DefaultExecManager.java View File

@@ -112,9 +112,8 @@ public class DefaultExecManager
final long timeout )
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 =
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 )
{
CommandLauncher launcher = m_launcher;


+ 1
- 1
proposal/myrmidon/src/java/org/apache/aut/nativelib/impl/Environment.java View File

@@ -154,7 +154,7 @@ final class Environment
{
final String[] command = getEnvCommand();
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 int retval = m_execManager.execute( metaData, null, output, output, 0 );


+ 1
- 2
proposal/myrmidon/src/java/org/apache/aut/nativelib/impl/launchers/ExecUtil.java View File

@@ -64,8 +64,7 @@ class ExecUtil

return new ExecMetaData( command,
metaData.getEnvironment(),
metaData.getWorkingDirectory(),
metaData.isEnvironmentAdditive() );
metaData.getWorkingDirectory() );
}

/**


+ 16
- 8
proposal/myrmidon/src/java/org/apache/myrmidon/framework/Execute.java View File

@@ -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;
}
@@ -137,9 +138,9 @@ public class Execute
private int executeNativeProcess()
throws TaskException
{
final ExecMetaData metaData = buildExecMetaData();
try
{
final ExecMetaData metaData = buildExecMetaData();
if( null != m_handler )
{
return m_execManager.execute( metaData, m_handler, m_timeout );
@@ -168,12 +169,19 @@ public class Execute
* to pass to the ExecManager service.
*/
private ExecMetaData buildExecMetaData()
throws ExecException
{
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,
m_environment,
m_workingDirectory,
m_newEnvironment );
newEnvironment,
m_workingDirectory );
}
}

Loading…
Cancel
Save