Browse Source

Made sure that setting of environment variables for the native exec calls occurs accoridng to epectations.

If no properties are specified then null is passed to underlying exec call.

if some properties are set and environment is additive then the native environment is added to environment object


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270518 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 23 years ago
parent
commit
65a74dfc9e
2 changed files with 35 additions and 4 deletions
  1. +34
    -4
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/DefaultCommandLauncher.java
  2. +1
    -0
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/Resources.properties

+ 34
- 4
proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/DefaultCommandLauncher.java View File

@@ -11,7 +11,11 @@ import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.framework.exec.CommandLauncher;
import org.apache.myrmidon.framework.exec.Environment;
import org.apache.myrmidon.framework.exec.ExecException;
import org.apache.myrmidon.framework.exec.ExecMetaData;

@@ -27,6 +31,9 @@ import org.apache.myrmidon.framework.exec.ExecMetaData;
public class DefaultCommandLauncher
implements CommandLauncher
{
private static final Resources REZ =
ResourceManager.getPackageResources( DefaultCommandLauncher.class );

private static final Method c_execWithCWD;

static
@@ -64,13 +71,12 @@ public class DefaultCommandLauncher
{
if( ExecUtil.isCwd( metaData.getWorkingDirectory() ) )
{
final String[] env = ExecUtil.toNativeEnvironment( metaData.getEnvironment() );
final String[] env = getEnvironmentSpec( metaData );
return Runtime.getRuntime().exec( metaData.getCommand(), env );
}
else if( null == c_execWithCWD )
{
final String message = "Unable to launch native command in a " +
"working directory other than \".\"";
final String message = REZ.getString( "default.bad-dir.error" );
throw new ExecException( message );
}
else
@@ -79,6 +85,30 @@ public class DefaultCommandLauncher
}
}

private String[] getEnvironmentSpec( final ExecMetaData metaData )
throws ExecException, IOException
{
final Properties environment = metaData.getEnvironment();
if( 0 == environment.size() )
{
return null;
}
else
{
if( metaData.isEnvironmentAdditive() )
{
final Properties newEnvironment = new Properties();
newEnvironment.putAll( environment );
newEnvironment.putAll( Environment.getNativeEnvironment() );
return ExecUtil.toNativeEnvironment( newEnvironment );
}
else
{
return ExecUtil.toNativeEnvironment( environment );
}
}
}

/**
* Execute the Java1.3 Runtime.exec() 3 parame method that sets working
* directory. This needs to be done via reflection so that it can compile
@@ -87,7 +117,7 @@ public class DefaultCommandLauncher
private Process execJava13( final ExecMetaData metaData )
throws IOException, ExecException
{
final String[] env = ExecUtil.toNativeEnvironment( metaData.getEnvironment() );
final String[] env = getEnvironmentSpec( metaData );
final Object[] args =
{metaData.getCommand(),
env,


+ 1
- 0
proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/Resources.properties View File

@@ -0,0 +1 @@
default.bad-dir.error=Unable to launch native command in a working directory other than "." on Java 1.2 JVMs.

Loading…
Cancel
Save