git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270335 13f79535-47bb-0310-9956-ffa450edef68master
@@ -8,7 +8,6 @@ | |||||
package org.apache.myrmidon.framework.exec; | package org.apache.myrmidon.framework.exec; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import org.apache.myrmidon.api.TaskException; | |||||
/** | /** | ||||
* This is the interface implemented by objects which are capable of | * This is the interface implemented by objects which are capable of | ||||
@@ -32,9 +31,9 @@ public interface CommandLauncher | |||||
* launch the application for some reason. Usually due | * launch the application for some reason. Usually due | ||||
* to the command not being fully specified and not in | * to the command not being fully specified and not in | ||||
* the PATH env var. | * the PATH env var. | ||||
* @exception TaskException if the command launcher detects that | |||||
* @exception ExecException if the command launcher detects that | |||||
* it can not execute the native command for some reason. | * it can not execute the native command for some reason. | ||||
*/ | */ | ||||
Process exec( ExecMetaData metaData ) | Process exec( ExecMetaData metaData ) | ||||
throws IOException, TaskException; | |||||
throws IOException, ExecException; | |||||
} | } |
@@ -15,8 +15,8 @@ import java.util.ArrayList; | |||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.Locale; | import java.util.Locale; | ||||
import java.util.Properties; | import java.util.Properties; | ||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.myrmidon.framework.Os; | import org.apache.myrmidon.framework.Os; | ||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.tools.ant.taskdefs.exec.Execute; | import org.apache.tools.ant.taskdefs.exec.Execute; | ||||
import org.apache.tools.ant.taskdefs.exec.PumpStreamHandler; | import org.apache.tools.ant.taskdefs.exec.PumpStreamHandler; | ||||
@@ -49,7 +49,7 @@ public final class Environment | |||||
} | } | ||||
public static String[] toNativeFormat( final Properties environment ) | public static String[] toNativeFormat( final Properties environment ) | ||||
throws TaskException | |||||
throws ExecException | |||||
{ | { | ||||
final ArrayList newEnvironment = new ArrayList(); | final ArrayList newEnvironment = new ArrayList(); | ||||
@@ -68,7 +68,7 @@ public final class Environment | |||||
* @deprecated Dont use me!!! | * @deprecated Dont use me!!! | ||||
*/ | */ | ||||
public static Properties createEnvVars( final String[] environment ) | public static Properties createEnvVars( final String[] environment ) | ||||
throws TaskException | |||||
throws ExecException | |||||
{ | { | ||||
final Properties newEnvironment = new Properties(); | final Properties newEnvironment = new Properties(); | ||||
@@ -82,7 +82,7 @@ public final class Environment | |||||
} | } | ||||
public static void addNativeEnvironment( final Properties environment ) | public static void addNativeEnvironment( final Properties environment ) | ||||
throws TaskException, IOException | |||||
throws ExecException, IOException | |||||
{ | { | ||||
final Properties nativeEnvironment = getEnvironmentVariables(); | final Properties nativeEnvironment = getEnvironmentVariables(); | ||||
final Iterator nativeKeys = nativeEnvironment.keySet().iterator(); | final Iterator nativeKeys = nativeEnvironment.keySet().iterator(); | ||||
@@ -105,7 +105,7 @@ public final class Environment | |||||
* native EnvironmentData Variables for the current process. | * native EnvironmentData Variables for the current process. | ||||
*/ | */ | ||||
private static String[] getNativeEnvironmentAsArray() | private static String[] getNativeEnvironmentAsArray() | ||||
throws IOException, TaskException | |||||
throws IOException, ExecException | |||||
{ | { | ||||
final Properties environment = getEnvironmentVariables(); | final Properties environment = getEnvironmentVariables(); | ||||
@@ -128,7 +128,7 @@ public final class Environment | |||||
* native EnvironmentData Variables for the current process. | * native EnvironmentData Variables for the current process. | ||||
*/ | */ | ||||
public static Properties getNativeEnvironment() | public static Properties getNativeEnvironment() | ||||
throws IOException, TaskException | |||||
throws IOException, ExecException | |||||
{ | { | ||||
return new Properties( getEnvironmentVariables() ); | return new Properties( getEnvironmentVariables() ); | ||||
} | } | ||||
@@ -138,7 +138,7 @@ public final class Environment | |||||
* attempt to load it if it has not already been loaded. | * attempt to load it if it has not already been loaded. | ||||
*/ | */ | ||||
private synchronized static Properties getEnvironmentVariables() | private synchronized static Properties getEnvironmentVariables() | ||||
throws IOException, TaskException | |||||
throws IOException, ExecException | |||||
{ | { | ||||
if( null == c_procEnvironment ) | if( null == c_procEnvironment ) | ||||
{ | { | ||||
@@ -152,7 +152,7 @@ public final class Environment | |||||
* Retrieve a last of environment variables from the native OS. | * Retrieve a last of environment variables from the native OS. | ||||
*/ | */ | ||||
private static synchronized Properties retrieveEnvironmentVariables() | private static synchronized Properties retrieveEnvironmentVariables() | ||||
throws IOException, TaskException | |||||
throws IOException, ExecException | |||||
{ | { | ||||
final Properties properties = new Properties(); | final Properties properties = new Properties(); | ||||
final String data = getEnvironmentText(); | final String data = getEnvironmentText(); | ||||
@@ -198,7 +198,7 @@ public final class Environment | |||||
*/ | */ | ||||
private static void addProperty( final Properties properties, | private static void addProperty( final Properties properties, | ||||
final String data ) | final String data ) | ||||
throws TaskException | |||||
throws ExecException | |||||
{ | { | ||||
final int index = data.indexOf( '=' ); | final int index = data.indexOf( '=' ); | ||||
if( -1 == index ) | if( -1 == index ) | ||||
@@ -206,7 +206,7 @@ public final class Environment | |||||
//Our env variable does not have any = in it. | //Our env variable does not have any = in it. | ||||
final String message = "EnvironmentData variable '" + data + | final String message = "EnvironmentData variable '" + data + | ||||
"' does not have a '=' character in it"; | "' does not have a '=' character in it"; | ||||
throw new TaskException( message ); | |||||
throw new ExecException( message ); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
@@ -221,7 +221,7 @@ public final class Environment | |||||
* running the environment command. | * running the environment command. | ||||
*/ | */ | ||||
private static String getEnvironmentText() | private static String getEnvironmentText() | ||||
throws IOException, TaskException | |||||
throws IOException, ExecException | |||||
{ | { | ||||
final ByteArrayOutputStream output = new ByteArrayOutputStream(); | final ByteArrayOutputStream output = new ByteArrayOutputStream(); | ||||
final Execute exe = new Execute( new PumpStreamHandler( output ) ); | final Execute exe = new Execute( new PumpStreamHandler( output ) ); | ||||
@@ -230,10 +230,17 @@ public final class Environment | |||||
// Make sure we do not recurse forever | // Make sure we do not recurse forever | ||||
exe.setNewenvironment( true ); | exe.setNewenvironment( true ); | ||||
final int retval = exe.execute(); | |||||
if( retval != 0 ) | |||||
try | |||||
{ | |||||
final int retval = exe.execute(); | |||||
if( retval != 0 ) | |||||
{ | |||||
// Just try to use what we got | |||||
} | |||||
} | |||||
catch( final TaskException te ) | |||||
{ | { | ||||
// Just try to use what we got | |||||
throw new ExecException( te.getMessage(), te ); | |||||
} | } | ||||
return output.toString(); | return output.toString(); | ||||
@@ -244,7 +251,7 @@ public final class Environment | |||||
* variables. | * variables. | ||||
*/ | */ | ||||
private static String[] getEnvCommand() | private static String[] getEnvCommand() | ||||
throws TaskException | |||||
throws ExecException | |||||
{ | { | ||||
if( Os.isFamily( "os/2" ) ) | if( Os.isFamily( "os/2" ) ) | ||||
{ | { | ||||
@@ -280,7 +287,7 @@ public final class Environment | |||||
{ | { | ||||
final String message = | final String message = | ||||
"Unable to determine native environment variables"; | "Unable to determine native environment variables"; | ||||
throw new TaskException( message ); | |||||
throw new ExecException( message ); | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -10,7 +10,6 @@ package org.apache.myrmidon.framework.exec; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.InputStream; | import java.io.InputStream; | ||||
import java.io.OutputStream; | import java.io.OutputStream; | ||||
import org.apache.myrmidon.api.TaskException; | |||||
/** | /** | ||||
* Interface via which clients can request that a native | * Interface via which clients can request that a native | ||||
@@ -53,5 +52,5 @@ public interface ExecManager | |||||
OutputStream output, | OutputStream output, | ||||
OutputStream error, | OutputStream error, | ||||
long timeout ) | long timeout ) | ||||
throws IOException, TaskException /*TimeoutException*/; | |||||
throws IOException, ExecException /*TimeoutException*/; | |||||
} | } |
@@ -11,8 +11,8 @@ import java.io.File; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.lang.reflect.InvocationTargetException; | import java.lang.reflect.InvocationTargetException; | ||||
import java.lang.reflect.Method; | import java.lang.reflect.Method; | ||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.myrmidon.framework.exec.CommandLauncher; | import org.apache.myrmidon.framework.exec.CommandLauncher; | ||||
import org.apache.myrmidon.framework.exec.ExecException; | |||||
import org.apache.myrmidon.framework.exec.ExecMetaData; | import org.apache.myrmidon.framework.exec.ExecMetaData; | ||||
/** | /** | ||||
@@ -56,11 +56,11 @@ public class DefaultCommandLauncher | |||||
* launch the application for some reason. Usually due | * launch the application for some reason. Usually due | ||||
* to the command not being fully specified and not in | * to the command not being fully specified and not in | ||||
* the PATH env var. | * the PATH env var. | ||||
* @exception TaskException if the command launcher detects that | |||||
* @exception ExecException if the command launcher detects that | |||||
* it can not execute the native command for some reason. | * it can not execute the native command for some reason. | ||||
*/ | */ | ||||
public Process exec( final ExecMetaData metaData ) | public Process exec( final ExecMetaData metaData ) | ||||
throws IOException, TaskException | |||||
throws IOException, ExecException | |||||
{ | { | ||||
if( ExecUtil.isCwd( metaData.getWorkingDirectory() ) ) | if( ExecUtil.isCwd( metaData.getWorkingDirectory() ) ) | ||||
{ | { | ||||
@@ -71,7 +71,7 @@ public class DefaultCommandLauncher | |||||
{ | { | ||||
final String message = "Unable to launch native command in a " + | final String message = "Unable to launch native command in a " + | ||||
"working directory other than \".\""; | "working directory other than \".\""; | ||||
throw new TaskException( message ); | |||||
throw new ExecException( message ); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
@@ -85,7 +85,7 @@ public class DefaultCommandLauncher | |||||
* under 1.2. | * under 1.2. | ||||
*/ | */ | ||||
private Process execJava13( final ExecMetaData metaData ) | private Process execJava13( final ExecMetaData metaData ) | ||||
throws IOException, TaskException | |||||
throws IOException, ExecException | |||||
{ | { | ||||
final Object[] args = | final Object[] args = | ||||
{metaData.getCommand(), | {metaData.getCommand(), | ||||
@@ -97,11 +97,11 @@ public class DefaultCommandLauncher | |||||
} | } | ||||
catch( final IllegalAccessException iae ) | catch( final IllegalAccessException iae ) | ||||
{ | { | ||||
throw new TaskException( iae.getMessage(), iae ); | |||||
throw new ExecException( iae.getMessage(), iae ); | |||||
} | } | ||||
catch( final IllegalArgumentException iae ) | catch( final IllegalArgumentException iae ) | ||||
{ | { | ||||
throw new TaskException( iae.getMessage(), iae ); | |||||
throw new ExecException( iae.getMessage(), iae ); | |||||
} | } | ||||
catch( final InvocationTargetException ite ) | catch( final InvocationTargetException ite ) | ||||
{ | { | ||||
@@ -113,7 +113,7 @@ public class DefaultCommandLauncher | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
throw new TaskException( t.getMessage(), t ); | |||||
throw new ExecException( t.getMessage(), t ); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -9,8 +9,8 @@ package org.apache.myrmidon.framework.exec.launchers; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.myrmidon.framework.exec.CommandLauncher; | import org.apache.myrmidon.framework.exec.CommandLauncher; | ||||
import org.apache.myrmidon.framework.exec.ExecException; | |||||
import org.apache.myrmidon.framework.exec.ExecMetaData; | import org.apache.myrmidon.framework.exec.ExecMetaData; | ||||
/** | /** | ||||
@@ -31,7 +31,7 @@ public class MacCommandLauncher | |||||
* Execute the specified native command. | * Execute the specified native command. | ||||
*/ | */ | ||||
public Process exec( final ExecMetaData metaData ) | public Process exec( final ExecMetaData metaData ) | ||||
throws IOException, TaskException | |||||
throws IOException, ExecException | |||||
{ | { | ||||
final File directory = metaData.getWorkingDirectory().getCanonicalFile(); | final File directory = metaData.getWorkingDirectory().getCanonicalFile(); | ||||
if( ExecUtil.isCwd( directory ) ) | if( ExecUtil.isCwd( directory ) ) | ||||
@@ -8,8 +8,8 @@ | |||||
package org.apache.myrmidon.framework.exec.launchers; | package org.apache.myrmidon.framework.exec.launchers; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.myrmidon.framework.exec.CommandLauncher; | import org.apache.myrmidon.framework.exec.CommandLauncher; | ||||
import org.apache.myrmidon.framework.exec.ExecException; | |||||
import org.apache.myrmidon.framework.exec.ExecMetaData; | import org.apache.myrmidon.framework.exec.ExecMetaData; | ||||
/** | /** | ||||
@@ -59,7 +59,7 @@ public class ScriptCommandLauncher | |||||
* set the working directory. | * set the working directory. | ||||
*/ | */ | ||||
public Process exec( final ExecMetaData metaData ) | public Process exec( final ExecMetaData metaData ) | ||||
throws IOException, TaskException | |||||
throws IOException, ExecException | |||||
{ | { | ||||
// Build the command | // Build the command | ||||
final String[] prefix = new String[ m_script.length + 1 ]; | final String[] prefix = new String[ m_script.length + 1 ]; | ||||
@@ -8,8 +8,8 @@ | |||||
package org.apache.myrmidon.framework.exec.launchers; | package org.apache.myrmidon.framework.exec.launchers; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.myrmidon.framework.exec.CommandLauncher; | import org.apache.myrmidon.framework.exec.CommandLauncher; | ||||
import org.apache.myrmidon.framework.exec.ExecException; | |||||
import org.apache.myrmidon.framework.exec.ExecMetaData; | import org.apache.myrmidon.framework.exec.ExecMetaData; | ||||
/** | /** | ||||
@@ -28,7 +28,7 @@ public class WinNTCommandLauncher | |||||
* set the working directory. | * set the working directory. | ||||
*/ | */ | ||||
public Process exec( final ExecMetaData metaData ) | public Process exec( final ExecMetaData metaData ) | ||||
throws IOException, TaskException | |||||
throws IOException, ExecException | |||||
{ | { | ||||
// Use cmd.exe to change to the specified directory before running | // Use cmd.exe to change to the specified directory before running | ||||
// the command | // the command | ||||
@@ -16,6 +16,7 @@ import java.util.Iterator; | |||||
import java.util.Properties; | import java.util.Properties; | ||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
import org.apache.myrmidon.framework.exec.Environment; | import org.apache.myrmidon.framework.exec.Environment; | ||||
import org.apache.myrmidon.framework.exec.ExecException; | |||||
import org.apache.tools.ant.AntClassLoader; | import org.apache.tools.ant.AntClassLoader; | ||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
@@ -232,6 +233,10 @@ public class Property extends Task | |||||
} | } | ||||
} | } | ||||
} | } | ||||
catch( final ExecException ee ) | |||||
{ | |||||
throw new TaskException( ee.getMessage(), ee ); | |||||
} | |||||
catch( final IOException ioe ) | catch( final IOException ioe ) | ||||
{ | { | ||||
throw new TaskException( ioe.getMessage(), ioe ); | throw new TaskException( ioe.getMessage(), ioe ); | ||||
@@ -16,6 +16,7 @@ import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.myrmidon.framework.Os; | import org.apache.myrmidon.framework.Os; | ||||
import org.apache.myrmidon.framework.exec.CommandLauncher; | import org.apache.myrmidon.framework.exec.CommandLauncher; | ||||
import org.apache.myrmidon.framework.exec.Environment; | 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; | ||||
import org.apache.myrmidon.framework.exec.launchers.DefaultCommandLauncher; | import org.apache.myrmidon.framework.exec.launchers.DefaultCommandLauncher; | ||||
import org.apache.myrmidon.framework.exec.launchers.MacCommandLauncher; | import org.apache.myrmidon.framework.exec.launchers.MacCommandLauncher; | ||||
@@ -269,58 +270,65 @@ public class Execute | |||||
throws IOException, TaskException | throws IOException, TaskException | ||||
{ | { | ||||
final ExecMetaData metaData = | |||||
new ExecMetaData( m_command, getNativeEnvironment(), | |||||
m_workingDirectory, false ); | |||||
final CommandLauncher launcher = getLauncher(); | |||||
final Process process = launcher.exec( metaData ); | |||||
try | try | ||||
{ | { | ||||
m_streamHandler.setProcessInputStream( process.getOutputStream() ); | |||||
m_streamHandler.setProcessOutputStream( process.getInputStream() ); | |||||
m_streamHandler.setProcessErrorStream( process.getErrorStream() ); | |||||
} | |||||
catch( final IOException ioe ) | |||||
{ | |||||
process.destroy(); | |||||
throw ioe; | |||||
} | |||||
final ExecMetaData metaData = | |||||
new ExecMetaData( m_command, getNativeEnvironment(), | |||||
m_workingDirectory, false ); | |||||
m_streamHandler.start(); | |||||
final CommandLauncher launcher = getLauncher(); | |||||
final Process process = launcher.exec( metaData ); | |||||
// add the process to the list of those to destroy if the VM exits | |||||
// | |||||
c_processDestroyer.add( process ); | |||||
try | |||||
{ | |||||
m_streamHandler.setProcessInputStream( process.getOutputStream() ); | |||||
m_streamHandler.setProcessOutputStream( process.getInputStream() ); | |||||
m_streamHandler.setProcessErrorStream( process.getErrorStream() ); | |||||
} | |||||
catch( final IOException ioe ) | |||||
{ | |||||
process.destroy(); | |||||
throw ioe; | |||||
} | |||||
if( m_watchdog != null ) | |||||
{ | |||||
m_watchdog.start( process ); | |||||
} | |||||
try | |||||
{ | |||||
process.waitFor(); | |||||
} | |||||
catch( final InterruptedException ie ) | |||||
{ | |||||
//shu\ould never happen | |||||
} | |||||
m_streamHandler.start(); | |||||
// remove the process to the list of those to destroy if the VM exits | |||||
// | |||||
c_processDestroyer.remove( process ); | |||||
// add the process to the list of those to destroy if the VM exits | |||||
// | |||||
c_processDestroyer.add( process ); | |||||
if( m_watchdog != null ) | |||||
{ | |||||
m_watchdog.stop(); | |||||
if( m_watchdog != null ) | |||||
{ | |||||
m_watchdog.start( process ); | |||||
} | |||||
try | |||||
{ | |||||
process.waitFor(); | |||||
} | |||||
catch( final InterruptedException ie ) | |||||
{ | |||||
//shu\ould never happen | |||||
} | |||||
// remove the process to the list of those to destroy if the VM exits | |||||
// | |||||
c_processDestroyer.remove( process ); | |||||
if( m_watchdog != null ) | |||||
{ | |||||
m_watchdog.stop(); | |||||
} | |||||
m_streamHandler.stop(); | |||||
if( m_watchdog != null ) | |||||
{ | |||||
m_watchdog.checkException(); | |||||
} | |||||
return process.exitValue(); | |||||
} | } | ||||
m_streamHandler.stop(); | |||||
if( m_watchdog != null ) | |||||
catch( final ExecException ee ) | |||||
{ | { | ||||
m_watchdog.checkException(); | |||||
throw new TaskException( ee.getMessage(), ee ); | |||||
} | } | ||||
return process.exitValue(); | |||||
} | } | ||||
private CommandLauncher getLauncher() | private CommandLauncher getLauncher() | ||||
@@ -339,7 +347,7 @@ public class Execute | |||||
* @return the environment used to create a subprocess | * @return the environment used to create a subprocess | ||||
*/ | */ | ||||
private String[] getNativeEnvironment() | private String[] getNativeEnvironment() | ||||
throws TaskException | |||||
throws ExecException | |||||
{ | { | ||||
if( m_newEnvironment ) | if( m_newEnvironment ) | ||||
{ | { | ||||
@@ -354,7 +362,7 @@ public class Execute | |||||
} | } | ||||
catch( final IOException ioe ) | catch( final IOException ioe ) | ||||
{ | { | ||||
throw new TaskException( ioe.getMessage(), ioe ); | |||||
throw new ExecException( ioe.getMessage(), ioe ); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -13,6 +13,7 @@ import java.util.Properties; | |||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
import org.apache.myrmidon.framework.Os; | import org.apache.myrmidon.framework.Os; | ||||
import org.apache.myrmidon.framework.exec.Environment; | import org.apache.myrmidon.framework.exec.Environment; | ||||
import org.apache.myrmidon.framework.exec.ExecException; | |||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
/** | /** | ||||
@@ -355,7 +356,15 @@ public class CommandlineJava implements Cloneable | |||||
public String[] getJavaVariables() | public String[] getJavaVariables() | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
String props[] = Environment.toNativeFormat( super.getVariables() ); | |||||
String props[] = new String[ 0 ]; | |||||
try | |||||
{ | |||||
props = Environment.toNativeFormat( super.getVariables() ); | |||||
} | |||||
catch( final ExecException ee ) | |||||
{ | |||||
throw new TaskException( ee.getMessage(), ee ); | |||||
} | |||||
if( props == null ) | if( props == null ) | ||||
return null; | return null; | ||||
@@ -16,6 +16,7 @@ import java.util.Iterator; | |||||
import java.util.Properties; | import java.util.Properties; | ||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
import org.apache.myrmidon.framework.exec.Environment; | import org.apache.myrmidon.framework.exec.Environment; | ||||
import org.apache.myrmidon.framework.exec.ExecException; | |||||
import org.apache.tools.ant.AntClassLoader; | import org.apache.tools.ant.AntClassLoader; | ||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
@@ -232,6 +233,10 @@ public class Property extends Task | |||||
} | } | ||||
} | } | ||||
} | } | ||||
catch( final ExecException ee ) | |||||
{ | |||||
throw new TaskException( ee.getMessage(), ee ); | |||||
} | |||||
catch( final IOException ioe ) | catch( final IOException ioe ) | ||||
{ | { | ||||
throw new TaskException( ioe.getMessage(), ioe ); | throw new TaskException( ioe.getMessage(), ioe ); | ||||
@@ -16,6 +16,7 @@ import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.myrmidon.framework.Os; | import org.apache.myrmidon.framework.Os; | ||||
import org.apache.myrmidon.framework.exec.CommandLauncher; | import org.apache.myrmidon.framework.exec.CommandLauncher; | ||||
import org.apache.myrmidon.framework.exec.Environment; | 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; | ||||
import org.apache.myrmidon.framework.exec.launchers.DefaultCommandLauncher; | import org.apache.myrmidon.framework.exec.launchers.DefaultCommandLauncher; | ||||
import org.apache.myrmidon.framework.exec.launchers.MacCommandLauncher; | import org.apache.myrmidon.framework.exec.launchers.MacCommandLauncher; | ||||
@@ -269,58 +270,65 @@ public class Execute | |||||
throws IOException, TaskException | throws IOException, TaskException | ||||
{ | { | ||||
final ExecMetaData metaData = | |||||
new ExecMetaData( m_command, getNativeEnvironment(), | |||||
m_workingDirectory, false ); | |||||
final CommandLauncher launcher = getLauncher(); | |||||
final Process process = launcher.exec( metaData ); | |||||
try | try | ||||
{ | { | ||||
m_streamHandler.setProcessInputStream( process.getOutputStream() ); | |||||
m_streamHandler.setProcessOutputStream( process.getInputStream() ); | |||||
m_streamHandler.setProcessErrorStream( process.getErrorStream() ); | |||||
} | |||||
catch( final IOException ioe ) | |||||
{ | |||||
process.destroy(); | |||||
throw ioe; | |||||
} | |||||
final ExecMetaData metaData = | |||||
new ExecMetaData( m_command, getNativeEnvironment(), | |||||
m_workingDirectory, false ); | |||||
m_streamHandler.start(); | |||||
final CommandLauncher launcher = getLauncher(); | |||||
final Process process = launcher.exec( metaData ); | |||||
// add the process to the list of those to destroy if the VM exits | |||||
// | |||||
c_processDestroyer.add( process ); | |||||
try | |||||
{ | |||||
m_streamHandler.setProcessInputStream( process.getOutputStream() ); | |||||
m_streamHandler.setProcessOutputStream( process.getInputStream() ); | |||||
m_streamHandler.setProcessErrorStream( process.getErrorStream() ); | |||||
} | |||||
catch( final IOException ioe ) | |||||
{ | |||||
process.destroy(); | |||||
throw ioe; | |||||
} | |||||
if( m_watchdog != null ) | |||||
{ | |||||
m_watchdog.start( process ); | |||||
} | |||||
try | |||||
{ | |||||
process.waitFor(); | |||||
} | |||||
catch( final InterruptedException ie ) | |||||
{ | |||||
//shu\ould never happen | |||||
} | |||||
m_streamHandler.start(); | |||||
// remove the process to the list of those to destroy if the VM exits | |||||
// | |||||
c_processDestroyer.remove( process ); | |||||
// add the process to the list of those to destroy if the VM exits | |||||
// | |||||
c_processDestroyer.add( process ); | |||||
if( m_watchdog != null ) | |||||
{ | |||||
m_watchdog.stop(); | |||||
if( m_watchdog != null ) | |||||
{ | |||||
m_watchdog.start( process ); | |||||
} | |||||
try | |||||
{ | |||||
process.waitFor(); | |||||
} | |||||
catch( final InterruptedException ie ) | |||||
{ | |||||
//shu\ould never happen | |||||
} | |||||
// remove the process to the list of those to destroy if the VM exits | |||||
// | |||||
c_processDestroyer.remove( process ); | |||||
if( m_watchdog != null ) | |||||
{ | |||||
m_watchdog.stop(); | |||||
} | |||||
m_streamHandler.stop(); | |||||
if( m_watchdog != null ) | |||||
{ | |||||
m_watchdog.checkException(); | |||||
} | |||||
return process.exitValue(); | |||||
} | } | ||||
m_streamHandler.stop(); | |||||
if( m_watchdog != null ) | |||||
catch( final ExecException ee ) | |||||
{ | { | ||||
m_watchdog.checkException(); | |||||
throw new TaskException( ee.getMessage(), ee ); | |||||
} | } | ||||
return process.exitValue(); | |||||
} | } | ||||
private CommandLauncher getLauncher() | private CommandLauncher getLauncher() | ||||
@@ -339,7 +347,7 @@ public class Execute | |||||
* @return the environment used to create a subprocess | * @return the environment used to create a subprocess | ||||
*/ | */ | ||||
private String[] getNativeEnvironment() | private String[] getNativeEnvironment() | ||||
throws TaskException | |||||
throws ExecException | |||||
{ | { | ||||
if( m_newEnvironment ) | if( m_newEnvironment ) | ||||
{ | { | ||||
@@ -354,7 +362,7 @@ public class Execute | |||||
} | } | ||||
catch( final IOException ioe ) | catch( final IOException ioe ) | ||||
{ | { | ||||
throw new TaskException( ioe.getMessage(), ioe ); | |||||
throw new ExecException( ioe.getMessage(), ioe ); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -13,6 +13,7 @@ import java.util.Properties; | |||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
import org.apache.myrmidon.framework.Os; | import org.apache.myrmidon.framework.Os; | ||||
import org.apache.myrmidon.framework.exec.Environment; | import org.apache.myrmidon.framework.exec.Environment; | ||||
import org.apache.myrmidon.framework.exec.ExecException; | |||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
/** | /** | ||||
@@ -355,7 +356,15 @@ public class CommandlineJava implements Cloneable | |||||
public String[] getJavaVariables() | public String[] getJavaVariables() | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
String props[] = Environment.toNativeFormat( super.getVariables() ); | |||||
String props[] = new String[ 0 ]; | |||||
try | |||||
{ | |||||
props = Environment.toNativeFormat( super.getVariables() ); | |||||
} | |||||
catch( final ExecException ee ) | |||||
{ | |||||
throw new TaskException( ee.getMessage(), ee ); | |||||
} | |||||
if( props == null ) | if( props == null ) | ||||
return null; | return null; | ||||