git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270341 13f79535-47bb-0310-9956-ffa450edef68master
@@ -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; | |||
} | |||
@@ -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 | |||
{ | |||
@@ -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. | |||
@@ -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 | |||
{ | |||
@@ -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 ); | |||
} | |||
} |
@@ -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 ); | |||
} | |||
} |
@@ -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 ); | |||
} | |||
} | |||
} | |||
} |
@@ -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 ); | |||
} | |||
} | |||
} | |||
} |