Browse Source

Made ExecMetaData take a Properties object for environment data rather than native format.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270341 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 23 years ago
parent
commit
cdd8484f39
8 changed files with 40 additions and 72 deletions
  1. +4
    -3
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/ExecMetaData.java
  2. +4
    -3
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/DefaultCommandLauncher.java
  3. +10
    -0
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/ExecUtil.java
  4. +4
    -4
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/MacCommandLauncher.java
  5. +2
    -2
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/ScriptCommandLauncher.java
  6. +2
    -2
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/WinNTCommandLauncher.java
  7. +7
    -29
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/Execute.java
  8. +7
    -29
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/Execute.java

+ 4
- 3
proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/ExecMetaData.java View File

@@ -8,6 +8,7 @@
package org.apache.myrmidon.framework.exec;

import java.io.File;
import java.util.Properties;

/**
* This class holds meta data that is used to launch a native executable.
@@ -40,7 +41,7 @@ public class ExecMetaData
* process if <code>isEnvironmentAdditive=true</code> else it specifies
* full environment.
*/
private String[] m_environment;
private Properties m_environment;

/**
* If this variable is true then then the environment specified is
@@ -57,7 +58,7 @@ public class ExecMetaData
* a null environment and an additive environment.
*/
public ExecMetaData( final String[] command,
final String[] environment,
final Properties environment,
final File workingDirectory,
final boolean environmentAdditive )
{
@@ -92,7 +93,7 @@ public class ExecMetaData
return m_command;
}

public String[] getEnvironment()
public Properties getEnvironment()
{
return m_environment;
}


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

@@ -64,8 +64,8 @@ public class DefaultCommandLauncher
{
if( ExecUtil.isCwd( metaData.getWorkingDirectory() ) )
{
return Runtime.getRuntime().
exec( metaData.getCommand(), metaData.getEnvironment() );
final String[] env = ExecUtil.toNativeEnvironment( metaData.getEnvironment() );
return Runtime.getRuntime().exec( metaData.getCommand(), env );
}
else if( null == c_execWithCWD )
{
@@ -87,9 +87,10 @@ public class DefaultCommandLauncher
private Process execJava13( final ExecMetaData metaData )
throws IOException, ExecException
{
final String[] env = ExecUtil.toNativeEnvironment( metaData.getEnvironment() );
final Object[] args =
{metaData.getCommand(),
metaData.getEnvironment(),
env,
metaData.getWorkingDirectory()};
try
{


+ 10
- 0
proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/ExecUtil.java View File

@@ -9,6 +9,9 @@ package org.apache.myrmidon.framework.exec.launchers;

import java.io.File;
import java.io.IOException;
import java.util.Properties;
import org.apache.myrmidon.framework.exec.Environment;
import org.apache.myrmidon.framework.exec.ExecException;
import org.apache.myrmidon.framework.exec.ExecMetaData;

/**
@@ -74,6 +77,13 @@ class ExecUtil
return file.getCanonicalFile().equals( getCwd() );
}

protected static String[] toNativeEnvironment( final Properties environment )
throws ExecException
{
if( null == environment ) return null;
else { return Environment.toNativeFormat( environment ); }
}

/**
* Return the current working directory of the JVM.
* This value is initialized when this class is first loaded.


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

@@ -36,8 +36,8 @@ public class MacCommandLauncher
final File directory = metaData.getWorkingDirectory().getCanonicalFile();
if( ExecUtil.isCwd( directory ) )
{
return Runtime.getRuntime().
exec( metaData.getCommand(), metaData.getEnvironment() );
final String[] env = ExecUtil.toNativeEnvironment( metaData.getEnvironment() );
return Runtime.getRuntime().exec( metaData.getCommand(), env );
}

//WARNING: This is an ugly hack and not thread safe in the slightest way
@@ -46,8 +46,8 @@ public class MacCommandLauncher
try
{
System.setProperty( "user.dir", directory.toString() );
return Runtime.getRuntime().
exec( metaData.getCommand(), metaData.getEnvironment() );
final String[] env = ExecUtil.toNativeEnvironment( metaData.getEnvironment() );
return Runtime.getRuntime().exec( metaData.getCommand(), env );
}
finally
{


+ 2
- 2
proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/ScriptCommandLauncher.java View File

@@ -70,7 +70,7 @@ public class ScriptCommandLauncher
prefix[ m_script.length ] = metaData.getWorkingDirectory().getCanonicalPath();

final ExecMetaData newMetaData = ExecUtil.prepend( metaData, prefix );
return Runtime.getRuntime().
exec( newMetaData.getCommand(), newMetaData.getEnvironment() );
final String[] env = ExecUtil.toNativeEnvironment( metaData.getEnvironment() );
return Runtime.getRuntime().exec( newMetaData.getCommand(), env );
}
}

+ 2
- 2
proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/WinNTCommandLauncher.java View File

@@ -41,7 +41,7 @@ public class WinNTCommandLauncher
prefix[ 5 ] = "&&";

final ExecMetaData newMetaData = ExecUtil.prepend( metaData, prefix );
return Runtime.getRuntime().
exec( newMetaData.getCommand(), newMetaData.getEnvironment() );
final String[] env = ExecUtil.toNativeEnvironment( metaData.getEnvironment() );
return Runtime.getRuntime().exec( newMetaData.getCommand(), env );
}
}

+ 7
- 29
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/Execute.java View File

@@ -44,7 +44,7 @@ public class Execute

private ExecMetaData m_metaData;
private String[] m_command;
private Properties m_environment;
private Properties m_environment = new Properties();
private File m_workingDirectory = new File( "." );
private boolean m_newEnvironment;

@@ -214,6 +214,10 @@ public class Execute

public void setEnvironment( final Properties environment )
{
if( null == environment )
{
throw new NullPointerException( "environment" );
}
m_environment = environment;
}

@@ -274,8 +278,8 @@ public class Execute
try
{
final ExecMetaData metaData =
new ExecMetaData( m_command, getNativeEnvironment(),
m_workingDirectory, false );
new ExecMetaData( m_command, m_environment,
m_workingDirectory, m_newEnvironment );

final CommandLauncher launcher = getLauncher();
final Process process = launcher.exec( metaData );
@@ -341,30 +345,4 @@ public class Execute
}
return launcher;
}

/**
* Returns the environment used to create a subprocess.
*
* @return the environment used to create a subprocess
*/
private String[] getNativeEnvironment()
throws ExecException
{
if( m_newEnvironment )
{
return Environment.toNativeFormat( m_environment );
}
else
{
try
{
Environment.addNativeEnvironment( m_environment );
return Environment.toNativeFormat( m_environment );
}
catch( final IOException ioe )
{
throw new ExecException( ioe.getMessage(), ioe );
}
}
}
}

+ 7
- 29
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/Execute.java View File

@@ -44,7 +44,7 @@ public class Execute

private ExecMetaData m_metaData;
private String[] m_command;
private Properties m_environment;
private Properties m_environment = new Properties();
private File m_workingDirectory = new File( "." );
private boolean m_newEnvironment;

@@ -214,6 +214,10 @@ public class Execute

public void setEnvironment( final Properties environment )
{
if( null == environment )
{
throw new NullPointerException( "environment" );
}
m_environment = environment;
}

@@ -274,8 +278,8 @@ public class Execute
try
{
final ExecMetaData metaData =
new ExecMetaData( m_command, getNativeEnvironment(),
m_workingDirectory, false );
new ExecMetaData( m_command, m_environment,
m_workingDirectory, m_newEnvironment );

final CommandLauncher launcher = getLauncher();
final Process process = launcher.exec( metaData );
@@ -341,30 +345,4 @@ public class Execute
}
return launcher;
}

/**
* Returns the environment used to create a subprocess.
*
* @return the environment used to create a subprocess
*/
private String[] getNativeEnvironment()
throws ExecException
{
if( m_newEnvironment )
{
return Environment.toNativeFormat( m_environment );
}
else
{
try
{
Environment.addNativeEnvironment( m_environment );
return Environment.toNativeFormat( m_environment );
}
catch( final IOException ioe )
{
throw new ExecException( ioe.getMessage(), ioe );
}
}
}
}

Loading…
Cancel
Save