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; | package org.apache.myrmidon.framework.exec; | ||||
import java.io.File; | import java.io.File; | ||||
import java.util.Properties; | |||||
/** | /** | ||||
* This class holds meta data that is used to launch a native executable. | * 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 | * process if <code>isEnvironmentAdditive=true</code> else it specifies | ||||
* full environment. | * full environment. | ||||
*/ | */ | ||||
private String[] m_environment; | |||||
private Properties m_environment; | |||||
/** | /** | ||||
* If this variable is true then then the environment specified is | * 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. | * a null environment and an additive environment. | ||||
*/ | */ | ||||
public ExecMetaData( final String[] command, | public ExecMetaData( final String[] command, | ||||
final String[] environment, | |||||
final Properties environment, | |||||
final File workingDirectory, | final File workingDirectory, | ||||
final boolean environmentAdditive ) | final boolean environmentAdditive ) | ||||
{ | { | ||||
@@ -92,7 +93,7 @@ public class ExecMetaData | |||||
return m_command; | return m_command; | ||||
} | } | ||||
public String[] getEnvironment() | |||||
public Properties getEnvironment() | |||||
{ | { | ||||
return m_environment; | return m_environment; | ||||
} | } | ||||
@@ -64,8 +64,8 @@ public class DefaultCommandLauncher | |||||
{ | { | ||||
if( ExecUtil.isCwd( metaData.getWorkingDirectory() ) ) | 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 ) | else if( null == c_execWithCWD ) | ||||
{ | { | ||||
@@ -87,9 +87,10 @@ public class DefaultCommandLauncher | |||||
private Process execJava13( final ExecMetaData metaData ) | private Process execJava13( final ExecMetaData metaData ) | ||||
throws IOException, ExecException | throws IOException, ExecException | ||||
{ | { | ||||
final String[] env = ExecUtil.toNativeEnvironment( metaData.getEnvironment() ); | |||||
final Object[] args = | final Object[] args = | ||||
{metaData.getCommand(), | {metaData.getCommand(), | ||||
metaData.getEnvironment(), | |||||
env, | |||||
metaData.getWorkingDirectory()}; | metaData.getWorkingDirectory()}; | ||||
try | try | ||||
{ | { | ||||
@@ -9,6 +9,9 @@ package org.apache.myrmidon.framework.exec.launchers; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.IOException; | 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; | import org.apache.myrmidon.framework.exec.ExecMetaData; | ||||
/** | /** | ||||
@@ -74,6 +77,13 @@ class ExecUtil | |||||
return file.getCanonicalFile().equals( getCwd() ); | 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. | * Return the current working directory of the JVM. | ||||
* This value is initialized when this class is first loaded. | * This value is initialized when this class is first loaded. | ||||
@@ -36,8 +36,8 @@ public class MacCommandLauncher | |||||
final File directory = metaData.getWorkingDirectory().getCanonicalFile(); | final File directory = metaData.getWorkingDirectory().getCanonicalFile(); | ||||
if( ExecUtil.isCwd( directory ) ) | 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 | //WARNING: This is an ugly hack and not thread safe in the slightest way | ||||
@@ -46,8 +46,8 @@ public class MacCommandLauncher | |||||
try | try | ||||
{ | { | ||||
System.setProperty( "user.dir", directory.toString() ); | 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 | finally | ||||
{ | { | ||||
@@ -70,7 +70,7 @@ public class ScriptCommandLauncher | |||||
prefix[ m_script.length ] = metaData.getWorkingDirectory().getCanonicalPath(); | prefix[ m_script.length ] = metaData.getWorkingDirectory().getCanonicalPath(); | ||||
final ExecMetaData newMetaData = ExecUtil.prepend( metaData, prefix ); | 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 ] = "&&"; | prefix[ 5 ] = "&&"; | ||||
final ExecMetaData newMetaData = ExecUtil.prepend( metaData, prefix ); | 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 ExecMetaData m_metaData; | ||||
private String[] m_command; | private String[] m_command; | ||||
private Properties m_environment; | |||||
private Properties m_environment = new Properties(); | |||||
private File m_workingDirectory = new File( "." ); | private File m_workingDirectory = new File( "." ); | ||||
private boolean m_newEnvironment; | private boolean m_newEnvironment; | ||||
@@ -214,6 +214,10 @@ public class Execute | |||||
public void setEnvironment( final Properties environment ) | public void setEnvironment( final Properties environment ) | ||||
{ | { | ||||
if( null == environment ) | |||||
{ | |||||
throw new NullPointerException( "environment" ); | |||||
} | |||||
m_environment = environment; | m_environment = environment; | ||||
} | } | ||||
@@ -274,8 +278,8 @@ public class Execute | |||||
try | try | ||||
{ | { | ||||
final ExecMetaData metaData = | 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 CommandLauncher launcher = getLauncher(); | ||||
final Process process = launcher.exec( metaData ); | final Process process = launcher.exec( metaData ); | ||||
@@ -341,30 +345,4 @@ public class Execute | |||||
} | } | ||||
return launcher; | 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 ExecMetaData m_metaData; | ||||
private String[] m_command; | private String[] m_command; | ||||
private Properties m_environment; | |||||
private Properties m_environment = new Properties(); | |||||
private File m_workingDirectory = new File( "." ); | private File m_workingDirectory = new File( "." ); | ||||
private boolean m_newEnvironment; | private boolean m_newEnvironment; | ||||
@@ -214,6 +214,10 @@ public class Execute | |||||
public void setEnvironment( final Properties environment ) | public void setEnvironment( final Properties environment ) | ||||
{ | { | ||||
if( null == environment ) | |||||
{ | |||||
throw new NullPointerException( "environment" ); | |||||
} | |||||
m_environment = environment; | m_environment = environment; | ||||
} | } | ||||
@@ -274,8 +278,8 @@ public class Execute | |||||
try | try | ||||
{ | { | ||||
final ExecMetaData metaData = | 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 CommandLauncher launcher = getLauncher(); | ||||
final Process process = launcher.exec( metaData ); | final Process process = launcher.exec( metaData ); | ||||
@@ -341,30 +345,4 @@ public class Execute | |||||
} | } | ||||
return launcher; | 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 ); | |||||
} | |||||
} | |||||
} | |||||
} | } |