donaldp 01/12/22 14:53:26
Modified: proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec
Execute.java
Log:
Continued refactoring
Revision Changes Path
1.11 +42 -36
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/Execute.java
Index: Execute.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/Execute.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Execute.java 2001/12/22 22:15:36 1.10
+++ Execute.java 2001/12/22 22:53:26 1.11
@@ -9,7 +9,6 @@
import java.io.File;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Locale;
import java.util.Properties;
import org.apache.avalon.excalibur.io.FileUtil;
@@ -165,7 +164,8 @@
* @param watchdog a watchdog for the subprocess or <code>null</code> to
to
* disable a timeout for the subprocess.
*/
- public Execute( ExecuteStreamHandler streamHandler, ExecuteWatchdog
watchdog )
+ public Execute( final ExecuteStreamHandler streamHandler,
+ final ExecuteWatchdog watchdog )
{
m_streamHandler = streamHandler;
m_watchdog = watchdog;
@@ -179,15 +179,16 @@
* @param cmdline The command to execute.
* @throws TaskException if the command does not return 0.
*/
- public static void runCommand( Task task, String[] cmdline )
+ public static void runCommand( final Task task, final String[] cmdline )
throws TaskException
{
try
{
task.log( Commandline.toString( cmdline ), Project.MSG_VERBOSE );
- Execute exe = new Execute( new LogStreamHandler( task,
-
Project.MSG_INFO,
- Project.MSG_ERR
) );
+ final Execute exe =
+ new Execute( new LogStreamHandler( task,
+ Project.MSG_INFO,
+ Project.MSG_ERR ) );
exe.setCommandline( cmdline );
int retval = exe.execute();
if( retval != 0 )
@@ -195,9 +196,9 @@
throw new TaskException( cmdline[ 0 ] + " failed with return
code " + retval );
}
}
- catch( IOException exc )
+ catch( final IOException ioe )
{
- throw new TaskException( "Could not launch " + cmdline[ 0 ] + ":
" + exc );
+ throw new TaskException( "Could not launch " + cmdline[ 0 ] + ":
" + ioe );
}
}
@@ -254,10 +255,10 @@
*
* @return the environment used to create a subprocess
*/
- public String[] getEnvironment()
+ private String[] getEnvironment()
throws TaskException
{
- if( m_environment == null || m_newEnvironment )
+ if( m_newEnvironment )
{
return Environment.toNativeFormat( m_environment );
}
@@ -284,27 +285,26 @@
public int execute()
throws IOException, TaskException
{
- CommandLauncher launcher = c_launcher != null ? c_launcher :
c_shellLauncher;
- if( !m_useVMLauncher )
- {
- launcher = c_shellLauncher;
- }
final ExecMetaData metaData =
new ExecMetaData( m_command, getEnvironment(),
m_workingDirectory, false );
+
+ final CommandLauncher launcher = getLauncher();
final Process process = launcher.exec( metaData );
+
try
{
m_streamHandler.setProcessInputStream( process.getOutputStream()
);
m_streamHandler.setProcessOutputStream( process.getInputStream()
);
m_streamHandler.setProcessErrorStream( process.getErrorStream()
);
}
- catch( IOException e )
+ catch( final IOException ioe )
{
process.destroy();
- throw e;
+ throw ioe;
}
+
m_streamHandler.start();
// add the process to the list of those to destroy if the VM exits
@@ -312,21 +312,44 @@
c_processDestroyer.add( process );
if( m_watchdog != null )
+ {
m_watchdog.start( process );
- waitFor( 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 m_exitValue;
+ }
+ return process.exitValue();;
}
+ private CommandLauncher getLauncher()
+ {
+ CommandLauncher launcher = c_launcher;
+ if( !m_useVMLauncher )
+ {
+ launcher = c_shellLauncher;
+ }
+ return launcher;
+ }
+
/**
* test for an untimely death of the process
*
@@ -336,22 +359,5 @@
public boolean killedProcess()
{
return m_watchdog != null && m_watchdog.killedProcess();
- }
-
- private void setExitValue( final int value )
- {
- m_exitValue = value;
- }
-
- protected void waitFor( Process process )
- {
- try
- {
- process.waitFor();
- setExitValue( process.exitValue() );
- }
- catch( InterruptedException e )
- {
- }
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>