Browse Source

Convert from using TaskException to ExecException

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270335 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 23 years ago
parent
commit
4a9c6d79bc
13 changed files with 174 additions and 125 deletions
  1. +2
    -3
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/CommandLauncher.java
  2. +23
    -16
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/Environment.java
  3. +1
    -2
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/ExecManager.java
  4. +8
    -8
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/DefaultCommandLauncher.java
  5. +2
    -2
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/MacCommandLauncher.java
  6. +2
    -2
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/ScriptCommandLauncher.java
  7. +2
    -2
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/WinNTCommandLauncher.java
  8. +5
    -0
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Property.java
  9. +52
    -44
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/Execute.java
  10. +10
    -1
      proposal/myrmidon/src/main/org/apache/tools/ant/types/CommandlineJava.java
  11. +5
    -0
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Property.java
  12. +52
    -44
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/Execute.java
  13. +10
    -1
      proposal/myrmidon/src/todo/org/apache/tools/ant/types/CommandlineJava.java

+ 2
- 3
proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/CommandLauncher.java View File

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

import java.io.IOException;
import org.apache.myrmidon.api.TaskException;

/**
* 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
* to the command not being fully specified and not in
* 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.
*/
Process exec( ExecMetaData metaData )
throws IOException, TaskException;
throws IOException, ExecException;
}

+ 23
- 16
proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/Environment.java View File

@@ -15,8 +15,8 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;
import java.util.Properties;
import org.apache.myrmidon.api.TaskException;
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.PumpStreamHandler;

@@ -49,7 +49,7 @@ public final class Environment
}

public static String[] toNativeFormat( final Properties environment )
throws TaskException
throws ExecException
{
final ArrayList newEnvironment = new ArrayList();

@@ -68,7 +68,7 @@ public final class Environment
* @deprecated Dont use me!!!
*/
public static Properties createEnvVars( final String[] environment )
throws TaskException
throws ExecException
{
final Properties newEnvironment = new Properties();

@@ -82,7 +82,7 @@ public final class Environment
}

public static void addNativeEnvironment( final Properties environment )
throws TaskException, IOException
throws ExecException, IOException
{
final Properties nativeEnvironment = getEnvironmentVariables();
final Iterator nativeKeys = nativeEnvironment.keySet().iterator();
@@ -105,7 +105,7 @@ public final class Environment
* native EnvironmentData Variables for the current process.
*/
private static String[] getNativeEnvironmentAsArray()
throws IOException, TaskException
throws IOException, ExecException
{
final Properties environment = getEnvironmentVariables();

@@ -128,7 +128,7 @@ public final class Environment
* native EnvironmentData Variables for the current process.
*/
public static Properties getNativeEnvironment()
throws IOException, TaskException
throws IOException, ExecException
{
return new Properties( getEnvironmentVariables() );
}
@@ -138,7 +138,7 @@ public final class Environment
* attempt to load it if it has not already been loaded.
*/
private synchronized static Properties getEnvironmentVariables()
throws IOException, TaskException
throws IOException, ExecException
{
if( null == c_procEnvironment )
{
@@ -152,7 +152,7 @@ public final class Environment
* Retrieve a last of environment variables from the native OS.
*/
private static synchronized Properties retrieveEnvironmentVariables()
throws IOException, TaskException
throws IOException, ExecException
{
final Properties properties = new Properties();
final String data = getEnvironmentText();
@@ -198,7 +198,7 @@ public final class Environment
*/
private static void addProperty( final Properties properties,
final String data )
throws TaskException
throws ExecException
{
final int index = data.indexOf( '=' );
if( -1 == index )
@@ -206,7 +206,7 @@ public final class Environment
//Our env variable does not have any = in it.
final String message = "EnvironmentData variable '" + data +
"' does not have a '=' character in it";
throw new TaskException( message );
throw new ExecException( message );
}
else
{
@@ -221,7 +221,7 @@ public final class Environment
* running the environment command.
*/
private static String getEnvironmentText()
throws IOException, TaskException
throws IOException, ExecException
{
final ByteArrayOutputStream output = new ByteArrayOutputStream();
final Execute exe = new Execute( new PumpStreamHandler( output ) );
@@ -230,10 +230,17 @@ public final class Environment
// Make sure we do not recurse forever
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();
@@ -244,7 +251,7 @@ public final class Environment
* variables.
*/
private static String[] getEnvCommand()
throws TaskException
throws ExecException
{
if( Os.isFamily( "os/2" ) )
{
@@ -280,7 +287,7 @@ public final class Environment
{
final String message =
"Unable to determine native environment variables";
throw new TaskException( message );
throw new ExecException( message );
}
}
}

+ 1
- 2
proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/ExecManager.java View File

@@ -10,7 +10,6 @@ package org.apache.myrmidon.framework.exec;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.myrmidon.api.TaskException;

/**
* Interface via which clients can request that a native
@@ -53,5 +52,5 @@ public interface ExecManager
OutputStream output,
OutputStream error,
long timeout )
throws IOException, TaskException /*TimeoutException*/;
throws IOException, ExecException /*TimeoutException*/;
}

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

@@ -11,8 +11,8 @@ import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.exec.CommandLauncher;
import org.apache.myrmidon.framework.exec.ExecException;
import org.apache.myrmidon.framework.exec.ExecMetaData;

/**
@@ -56,11 +56,11 @@ public class DefaultCommandLauncher
* launch the application for some reason. Usually due
* to the command not being fully specified and not in
* 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.
*/
public Process exec( final ExecMetaData metaData )
throws IOException, TaskException
throws IOException, ExecException
{
if( ExecUtil.isCwd( metaData.getWorkingDirectory() ) )
{
@@ -71,7 +71,7 @@ public class DefaultCommandLauncher
{
final String message = "Unable to launch native command in a " +
"working directory other than \".\"";
throw new TaskException( message );
throw new ExecException( message );
}
else
{
@@ -85,7 +85,7 @@ public class DefaultCommandLauncher
* under 1.2.
*/
private Process execJava13( final ExecMetaData metaData )
throws IOException, TaskException
throws IOException, ExecException
{
final Object[] args =
{metaData.getCommand(),
@@ -97,11 +97,11 @@ public class DefaultCommandLauncher
}
catch( final IllegalAccessException iae )
{
throw new TaskException( iae.getMessage(), iae );
throw new ExecException( iae.getMessage(), iae );
}
catch( final IllegalArgumentException iae )
{
throw new TaskException( iae.getMessage(), iae );
throw new ExecException( iae.getMessage(), iae );
}
catch( final InvocationTargetException ite )
{
@@ -113,7 +113,7 @@ public class DefaultCommandLauncher
}
else
{
throw new TaskException( t.getMessage(), t );
throw new ExecException( t.getMessage(), t );
}
}
}


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

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

import java.io.File;
import java.io.IOException;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.exec.CommandLauncher;
import org.apache.myrmidon.framework.exec.ExecException;
import org.apache.myrmidon.framework.exec.ExecMetaData;

/**
@@ -31,7 +31,7 @@ public class MacCommandLauncher
* Execute the specified native command.
*/
public Process exec( final ExecMetaData metaData )
throws IOException, TaskException
throws IOException, ExecException
{
final File directory = metaData.getWorkingDirectory().getCanonicalFile();
if( ExecUtil.isCwd( directory ) )


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

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

import java.io.IOException;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.exec.CommandLauncher;
import org.apache.myrmidon.framework.exec.ExecException;
import org.apache.myrmidon.framework.exec.ExecMetaData;

/**
@@ -59,7 +59,7 @@ public class ScriptCommandLauncher
* set the working directory.
*/
public Process exec( final ExecMetaData metaData )
throws IOException, TaskException
throws IOException, ExecException
{
// Build the command
final String[] prefix = new String[ m_script.length + 1 ];


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

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

import java.io.IOException;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.exec.CommandLauncher;
import org.apache.myrmidon.framework.exec.ExecException;
import org.apache.myrmidon.framework.exec.ExecMetaData;

/**
@@ -28,7 +28,7 @@ public class WinNTCommandLauncher
* set the working directory.
*/
public Process exec( final ExecMetaData metaData )
throws IOException, TaskException
throws IOException, ExecException
{
// Use cmd.exe to change to the specified directory before running
// the command


+ 5
- 0
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Property.java View File

@@ -16,6 +16,7 @@ import java.util.Iterator;
import java.util.Properties;
import org.apache.myrmidon.api.TaskException;
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.Project;
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 )
{
throw new TaskException( ioe.getMessage(), ioe );


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

@@ -16,6 +16,7 @@ import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.Os;
import org.apache.myrmidon.framework.exec.CommandLauncher;
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.launchers.DefaultCommandLauncher;
import org.apache.myrmidon.framework.exec.launchers.MacCommandLauncher;
@@ -269,58 +270,65 @@ public class Execute
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
{
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()
@@ -339,7 +347,7 @@ public class Execute
* @return the environment used to create a subprocess
*/
private String[] getNativeEnvironment()
throws TaskException
throws ExecException
{
if( m_newEnvironment )
{
@@ -354,7 +362,7 @@ public class Execute
}
catch( final IOException ioe )
{
throw new TaskException( ioe.getMessage(), ioe );
throw new ExecException( ioe.getMessage(), ioe );
}
}
}


+ 10
- 1
proposal/myrmidon/src/main/org/apache/tools/ant/types/CommandlineJava.java View File

@@ -13,6 +13,7 @@ import java.util.Properties;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.Os;
import org.apache.myrmidon.framework.exec.Environment;
import org.apache.myrmidon.framework.exec.ExecException;
import org.apache.tools.ant.Project;

/**
@@ -355,7 +356,15 @@ public class CommandlineJava implements Cloneable
public String[] getJavaVariables()
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 )
return null;


+ 5
- 0
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Property.java View File

@@ -16,6 +16,7 @@ import java.util.Iterator;
import java.util.Properties;
import org.apache.myrmidon.api.TaskException;
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.Project;
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 )
{
throw new TaskException( ioe.getMessage(), ioe );


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

@@ -16,6 +16,7 @@ import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.Os;
import org.apache.myrmidon.framework.exec.CommandLauncher;
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.launchers.DefaultCommandLauncher;
import org.apache.myrmidon.framework.exec.launchers.MacCommandLauncher;
@@ -269,58 +270,65 @@ public class Execute
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
{
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()
@@ -339,7 +347,7 @@ public class Execute
* @return the environment used to create a subprocess
*/
private String[] getNativeEnvironment()
throws TaskException
throws ExecException
{
if( m_newEnvironment )
{
@@ -354,7 +362,7 @@ public class Execute
}
catch( final IOException ioe )
{
throw new TaskException( ioe.getMessage(), ioe );
throw new ExecException( ioe.getMessage(), ioe );
}
}
}


+ 10
- 1
proposal/myrmidon/src/todo/org/apache/tools/ant/types/CommandlineJava.java View File

@@ -13,6 +13,7 @@ import java.util.Properties;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.Os;
import org.apache.myrmidon.framework.exec.Environment;
import org.apache.myrmidon.framework.exec.ExecException;
import org.apache.tools.ant.Project;

/**
@@ -355,7 +356,15 @@ public class CommandlineJava implements Cloneable
public String[] getJavaVariables()
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 )
return null;


Loading…
Cancel
Save