Browse Source

Some refactoring of framework.Execute:

* Moved the general-purpose logging and validation code from Exec task to
  Execute.

* Removed Execute's constructor, replaced with a TaskContext passed to
  Execute.execute().

* If no ExecOutputHandler is provided, Execute routes the process' stdout
  and stderr via TaskContext's log methods.

* Removed a bunch of debug messages from tasks, as Execute now takes care of this.

* Replaced a bunch of return code == 0 checks, with calls to
  Execute.setReturnCode( 0 ).


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271888 13f79535-47bb-0310-9956-ffa450edef68
master
adammurdoch 23 years ago
parent
commit
b6410584b6
46 changed files with 255 additions and 317 deletions
  1. +2
    -3
      proposal/myrmidon/src/java/org/apache/antlib/build/Patch.java
  2. +2
    -3
      proposal/myrmidon/src/java/org/apache/antlib/cvslib/Cvs.java
  3. +2
    -3
      proposal/myrmidon/src/java/org/apache/antlib/dotnet/CSharp.java
  4. +2
    -3
      proposal/myrmidon/src/java/org/apache/antlib/dotnet/Ilasm.java
  5. +8
    -53
      proposal/myrmidon/src/java/org/apache/antlib/nativelib/Exec.java
  6. +0
    -8
      proposal/myrmidon/src/java/org/apache/antlib/nativelib/Resources.properties
  7. +2
    -3
      proposal/myrmidon/src/java/org/apache/antlib/security/GenerateKey.java
  8. +2
    -3
      proposal/myrmidon/src/java/org/apache/antlib/security/SignJar.java
  9. +0
    -4
      proposal/myrmidon/src/java/org/apache/myrmidon/api/Task.java
  10. +1
    -1
      proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/ProjectListenerSupport.java
  11. +86
    -41
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/Execute.java
  12. +47
    -0
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/LoggingExecOutputHandler.java
  13. +10
    -1
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/Resources.properties
  14. +2
    -3
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ANTLR.java
  15. +2
    -3
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Cab.java
  16. +2
    -3
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Java.java
  17. +2
    -3
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Rpm.java
  18. +1
    -6
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/CCMCheck.java
  19. +2
    -15
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/CCMCreateTask.java
  20. +1
    -6
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/CCMReconfigure.java
  21. +4
    -4
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/Continuus.java
  22. +1
    -6
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCCheckin.java
  23. +1
    -6
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCCheckout.java
  24. +1
    -6
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCUnCheckout.java
  25. +1
    -9
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCUpdate.java
  26. +4
    -4
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/ClearCase.java
  27. +2
    -3
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/DefaultCompilerAdapter.java
  28. +2
    -3
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javacc/JJTree.java
  29. +2
    -3
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javacc/JavaCC.java
  30. +2
    -3
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javadoc/Javadoc.java
  31. +2
    -3
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jdepend/JDependTask.java
  32. +2
    -3
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/JUnitTask.java
  33. +2
    -6
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/AbstractMetamataTask.java
  34. +2
    -3
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/MParse.java
  35. +2
    -3
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/perforce/P4Base.java
  36. +4
    -7
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/pvcs/Pvcs.java
  37. +3
    -12
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/CovMerge.java
  38. +3
    -8
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/CovReport.java
  39. +3
    -12
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/Coverage.java
  40. +4
    -4
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSS.java
  41. +1
    -8
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKIN.java
  42. +1
    -8
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKOUT.java
  43. +1
    -9
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSGET.java
  44. +1
    -8
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSHISTORY.java
  45. +1
    -8
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSLABEL.java
  46. +27
    -3
      proposal/myrmidon/src/todo/org/apache/tools/todo/util/FileUtils.java

+ 2
- 3
proposal/myrmidon/src/java/org/apache/antlib/build/Patch.java View File

@@ -106,10 +106,9 @@ public class Patch
{
validate();

final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();
buildCommand( exe.getCommandline() );
exe.execute();
exe.execute( getContext() );
}

private void validate()


+ 2
- 3
proposal/myrmidon/src/java/org/apache/antlib/cvslib/Cvs.java View File

@@ -147,8 +147,7 @@ public class Cvs
final Commandline command = buildCommandline();
final Properties env = buildEnvironment();

final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();
if( m_dest == null )
{
m_dest = getBaseDirectory();
@@ -158,7 +157,7 @@ public class Cvs
exe.setCommandline( command );
exe.setEnvironment( env );
exe.setReturnCode( 0 );
exe.execute();
exe.execute( getContext() );
}

private Properties buildEnvironment()


+ 2
- 3
proposal/myrmidon/src/java/org/apache/antlib/dotnet/CSharp.java View File

@@ -506,8 +506,7 @@ public class CSharp
m_srcDir = getBaseDirectory();
}

final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();
exe.setReturnCode( 0 );

final Commandline cmd = exe.getCommandline();
@@ -549,7 +548,7 @@ public class CSharp
}

//now run the command of exe + settings + files
exe.execute();
exe.execute( getContext() );
}

private void addArgument( final Commandline cmd, final String argument )


+ 2
- 3
proposal/myrmidon/src/java/org/apache/antlib/dotnet/Ilasm.java View File

@@ -250,8 +250,7 @@ public class Ilasm
public void executeOneFile( final String targetFile )
throws TaskException
{
final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();
exe.setReturnCode( 0 );

final Commandline cmd = exe.getCommandline();
@@ -265,7 +264,7 @@ public class Ilasm
addArgument( cmd, getKeyfileParameter() );
addArgument( cmd, getExtraOptionsParameter() );
addArgument( cmd, targetFile );
exe.execute();
exe.execute( getContext() );
}

private void addArgument( final Commandline cmd, final String argument )


+ 8
- 53
proposal/myrmidon/src/java/org/apache/antlib/nativelib/Exec.java View File

@@ -9,13 +9,9 @@ package org.apache.antlib.nativelib;

import java.io.File;
import java.util.Properties;
import org.apache.aut.nativelib.ExecManager;
import org.apache.aut.nativelib.Os;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.api.AbstractTask;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.framework.Execute;
import org.apache.tools.todo.types.Argument;
import org.apache.tools.todo.types.Commandline;
@@ -36,9 +32,6 @@ import org.apache.tools.todo.types.EnvironmentVariable;
public class Exec
extends AbstractTask
{
private final static Resources REZ =
ResourceManager.getPackageResources( Exec.class );

private long m_timeout;
private EnvironmentData m_env = new EnvironmentData();
private Commandline m_command = new Commandline();
@@ -107,28 +100,9 @@ public class Exec
public void execute()
throws TaskException
{
validate();
if( null == m_os || Os.isFamily( m_os ) )
{
final Execute exe = createExecute();
doExecute( exe );
}
}

private void doExecute( final Execute exe )
throws TaskException
{
exe.setReturnCode( 0 );
exe.execute();
}

private void validate()
throws TaskException
{
if( null == m_command.getExecutable() )
if( null != m_os && Os.isFamily( m_os ) )
{
final String message = REZ.getString( "exec.no-executable.error" );
throw new TaskException( message );
return;
}

// default directory to the project's base directory
@@ -136,19 +110,11 @@ public class Exec
{
m_dir = getBaseDirectory();
}
else
{
if( !m_dir.exists() )
{
final String message = REZ.getString( "exec.dir-noexist.error", m_dir );
throw new TaskException( message );
}
else if( !m_dir.isDirectory() )
{
final String message = REZ.getString( "exec.dir-notdir.error", m_dir );
throw new TaskException( message );
}
}

// execute the command
final Execute exe = createExecute();
exe.setReturnCode( 0 );
exe.execute( getContext() );
}

private Execute createExecute()
@@ -156,10 +122,7 @@ public class Exec
{
final Properties environment = m_env.getVariables();

logExecDetails( environment );

final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();
exe.setTimeout( m_timeout );
exe.setWorkingDirectory( m_dir );
exe.setNewenvironment( m_newEnvironment );
@@ -167,12 +130,4 @@ public class Exec
exe.setCommandline( m_command );
return exe;
}

private void logExecDetails( final Properties environment )
{
// show the command
getContext().debug( m_command.toString() );
final String message = REZ.getString( "exec.env-vars.notice", environment );
getContext().debug( message );
}
}

+ 0
- 8
proposal/myrmidon/src/java/org/apache/antlib/nativelib/Resources.properties View File

@@ -1,11 +1,3 @@
loadenv.no-prefix.error=No prefix specified for environment data.
loadenv.prefix.notice=Loading Environment with prefix {0}.
loadenv.ignoring-empty.warn=Key {0} in native OS environment is empty - ignoring key.

exec.failed.error=Execute failed. (Reason: {0}).
exec.bad-resultcode.error=Bad result code {0}.
exec.no-executable.error=No executable specified.
exec.dir-noexist.error=The directory you specified ({0}) does not exist.
exec.dir-notdir.error=The directory you specified is not a directory.
exec.env-vars.notice=Setting environment variables: {0}.
exec.invalid-os.notice=This OS, {0} was not found in the specified list of valid OSes: {1}.

+ 2
- 3
proposal/myrmidon/src/java/org/apache/antlib/security/GenerateKey.java View File

@@ -121,11 +121,10 @@ public class GenerateKey
getContext().info( message );

final Commandline cmd = createCommand();
final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();
exe.setWorkingDirectory( getBaseDirectory() );
exe.setCommandline( cmd );
exe.execute();
exe.execute( getContext() );
}

private Commandline createCommand()


+ 2
- 3
proposal/myrmidon/src/java/org/apache/antlib/security/SignJar.java View File

@@ -296,10 +296,9 @@ public class SignJar
getContext().info( message );

final Commandline cmd = buildCommand( jarTarget, jarSource );
final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();
exe.setCommandline( cmd );
exe.execute();
exe.execute( getContext() );
}

private Commandline buildCommand( final File jarTarget, final File jarSource )


+ 0
- 4
proposal/myrmidon/src/java/org/apache/myrmidon/api/Task.java View File

@@ -10,15 +10,11 @@ package org.apache.myrmidon.api;
/**
* This is the interface that tasks implement to be executed in Myrmidon runtime.
*
* Instances can also implement the Avalon LogEnabled method to receive a logger.
*
* Tasks can also choose to implement Avalon Configurable if they wish to directly
* receive the Configuration data representing the task. If this interface is
* not implemented then the container will be responsble for mapping configuration
* onto the task object.
*
* The Components passed in via ComponentManager are determined by container.
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @version $Revision$ $Date$
* @ant:role shorthand="task"


+ 1
- 1
proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/ProjectListenerSupport.java View File

@@ -16,7 +16,7 @@ import org.apache.myrmidon.listeners.ProjectListener;
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @version $Revision$ $Date$
*/
public class ProjectListenerSupport
class ProjectListenerSupport
implements LogEvent
{
private ProjectListener[] m_listeners = new ProjectListener[ 0 ];


+ 86
- 41
proposal/myrmidon/src/java/org/apache/myrmidon/framework/Execute.java View File

@@ -8,14 +8,17 @@
package org.apache.myrmidon.framework;

import java.io.File;
import java.io.IOException;
import java.util.Properties;
import org.apache.aut.nativelib.ExecException;
import org.apache.aut.nativelib.ExecManager;
import org.apache.aut.nativelib.ExecMetaData;
import org.apache.aut.nativelib.ExecOutputHandler;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.todo.types.Commandline;
import org.apache.tools.todo.util.FileUtils;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;

/**
* This is a utility class designed to make executing native
@@ -27,20 +30,17 @@ import org.apache.tools.todo.types.Commandline;
*/
public class Execute
{
private final static Resources REZ
= ResourceManager.getPackageResources( Execute.class );

private Commandline m_command;
private Properties m_environment = new Properties();
private File m_workingDirectory = new File( "." );
private boolean m_newEnvironment;
private ExecOutputHandler m_handler;
private long m_timeout;
private ExecManager m_execManager;
private Integer m_returnCode;

public Execute( final ExecManager execManager )
{
m_execManager = execManager;
}

public void setTimeout( final long timeout )
{
m_timeout = timeout;
@@ -108,59 +108,104 @@ public class Execute
/**
* Runs a process defined by the command line and returns its exit status.
*
* @return the exit status of the subprocess or <code>INVALID</code>
* @return the exit status of the subprocess.
*/
public int execute()
public int execute( final TaskContext context )
throws TaskException
{
final int returnCode = executeNativeProcess();
checkReturnCode( returnCode );
return returnCode;
validate();

try
{
// Build an output handler
final ExecOutputHandler handler = buildOutputHandler( context );

// Build the command meta-info
final ExecManager execManager = (ExecManager)context.getService( ExecManager.class );
final ExecMetaData metaData = buildExecMetaData( execManager );

logExecDetails( metaData, context );

// Execute the command and check return code
final int returnCode = execManager.execute( metaData, handler, m_timeout );
checkReturnCode( returnCode );
return returnCode;
}
catch( final Exception e )
{
final String message = REZ.getString( "execute.failed.error", m_command.getExecutable() );
throw new TaskException( message, e );
}
}

/**
* Utility method to verify that specified return code was the
* return code expected (if any).
* Logs the details of the command.
*/
private void checkReturnCode( final int returnCode )
private void logExecDetails( final ExecMetaData metaData,
final TaskContext context )
throws TaskException
{
if( null != m_returnCode &&
returnCode != m_returnCode.intValue() )
if( ! context.isDebugEnabled() )
{
throw new TaskException( "Unexpected return code " + returnCode );
return;
}

String cmdline = FileUtils.buildCommandLine( metaData.getCommand() );
String message = REZ.getString( "execute.command.notice", cmdline );
context.debug( message );
message = REZ.getString( "execute.env-vars.notice", metaData.getEnvironment() );
context.debug( message );
}

/**
* Actually execute the native process.
* Vaidates the arguments.
*/
private int executeNativeProcess()
throws TaskException
private void validate() throws TaskException
{
try
if( null == m_command.getExecutable() )
{
final ExecMetaData metaData = buildExecMetaData();
if( null != m_handler )
{
return m_execManager.execute( metaData, m_handler, m_timeout );
}
else
{
return m_execManager.execute( metaData,
null,
System.out,
System.err,
m_timeout );
}
final String message = REZ.getString( "execute.no-executable.error" );
throw new TaskException( message );
}
catch( final ExecException ee )
if( !m_workingDirectory.exists() )
{
throw new TaskException( ee.getMessage(), ee );
final String message = REZ.getString( "execute.dir-noexist.error", m_workingDirectory );
throw new TaskException( message );
}
catch( final IOException ioe )
else if( !m_workingDirectory.isDirectory() )
{
final String message = REZ.getString( "execute.dir-notdir.error", m_workingDirectory );
throw new TaskException( message );
}
}

/**
* Creates an output handler to use when executing the commmand.
*/
private ExecOutputHandler buildOutputHandler( final TaskContext context )
{
ExecOutputHandler handler = m_handler;
if( handler == null )
{
handler = new LoggingExecOutputHandler( context );
}
return handler;
}

/**
* Utility method to verify that specified return code was the
* return code expected (if any).
*/
private void checkReturnCode( final int returnCode )
throws TaskException
{
if( null != m_returnCode &&
returnCode != m_returnCode.intValue() )
{
throw new TaskException( ioe.getMessage(), ioe );
final String message = REZ.getString( "execute.bad-resultcode.error",
m_command.getExecutable(),
new Integer(returnCode) );
throw new TaskException( message );
}
}

@@ -168,7 +213,7 @@ public class Execute
* Utility method to create an ExecMetaData object
* to pass to the ExecManager service.
*/
private ExecMetaData buildExecMetaData()
private ExecMetaData buildExecMetaData( final ExecManager execManager )
throws ExecException
{
final String[] command = m_command.getCommandline();
@@ -176,7 +221,7 @@ public class Execute
final Properties newEnvironment = new Properties();
if( !m_newEnvironment )
{
newEnvironment.putAll( m_execManager.getNativeEnvironment() );
newEnvironment.putAll( execManager.getNativeEnvironment() );
}
newEnvironment.putAll( m_environment );



+ 47
- 0
proposal/myrmidon/src/java/org/apache/myrmidon/framework/LoggingExecOutputHandler.java View File

@@ -0,0 +1,47 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.framework;

import org.apache.aut.nativelib.ExecOutputHandler;
import org.apache.myrmidon.api.TaskContext;

/**
* An {@link ExecOutputHandler} adaptor, that writes output to the logging
* methods of a {@link TaskContext}.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*/
public class LoggingExecOutputHandler
implements ExecOutputHandler
{
private final TaskContext m_context;

public LoggingExecOutputHandler( final TaskContext context )
{
m_context = context;
}

/**
* Receive notification about the process writing
* to standard output.
*/
public void stdout( final String line )
{
m_context.info( line );
}

/**
* Receive notification about the process writing
* to standard error.
*/
public void stderr( final String line )
{
m_context.error( line );
}
}

+ 10
- 1
proposal/myrmidon/src/java/org/apache/myrmidon/framework/Resources.properties View File

@@ -17,4 +17,13 @@ type.no-id.error=Id must be specified.

unknown-family=Don't know how to detect os family "{0}"

facade.missing-impl.error=Unable to determine the name of implementation for facade task "{0}".
facade.missing-impl.error=Unable to determine the name of implementation for facade task "{0}".

execute.no-executable.error=No executable specified.
execute.dir-noexist.error=The specified working directory "{0}" does not exist.
execute.dir-notdir.error=The specified working directory "{0}" is not a directory.
execute.failed.error=Command "{0}" failed.
execute.bad-resultcode.error=Command "{0}" returned unexpected exit code {1}.
execute.command.notice=Executing: {0}
execute.env-vars.notice=Using environment: {0}.


+ 2
- 3
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ANTLR.java View File

@@ -228,8 +228,7 @@ public class ANTLR extends AbstractTask
private int run( final Commandline command )
throws TaskException
{
final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();
if( workingdir != null )
{
exe.setWorkingDirectory( workingdir );
@@ -237,7 +236,7 @@ public class ANTLR extends AbstractTask
exe.setCommandline( command );
try
{
return exe.execute();
return exe.execute( getContext() );
}
catch( IOException e )
{


+ 2
- 3
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Cab.java View File

@@ -137,12 +137,11 @@ public class Cab
try
{
File listFile = createListFile( files );
final ExecManager execManager = (ExecManager)getService( ExecManager.class );
Execute exe = new Execute( execManager );
Execute exe = new Execute();
exe.setWorkingDirectory( m_baseDir );
final Commandline cmd = createCommand( listFile );
exe.setCommandline( cmd );
exe.execute();
exe.execute( getContext() );

listFile.delete();
}


+ 2
- 3
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Java.java View File

@@ -215,8 +215,7 @@ public class Java
private int run( final Commandline command )
throws TaskException
{
final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();

if( m_dir == null )
{
@@ -230,6 +229,6 @@ public class Java

exe.setWorkingDirectory( m_dir );
exe.setCommandline( command );
return exe.execute();
return exe.execute( getContext() );
}
}

+ 2
- 3
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Rpm.java View File

@@ -90,8 +90,7 @@ public class Rpm
throws TaskException
{
final Commandline cmd = createCommand();
final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();

if( m_topDir == null )
{
@@ -103,7 +102,7 @@ public class Rpm

final String message = "Building the RPM based on the " + m_specFile + " file";
getContext().info( message );
exe.execute();
exe.execute( getContext() );
}

private Commandline createCommand()


+ 1
- 6
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/CCMCheck.java View File

@@ -119,12 +119,7 @@ public class CCMCheck extends Continuus

checkOptions( commandLine );

final int result = run( commandLine, null );
if( result != 0 )
{
final String message = "Failed executing: " + commandLine.toString();
throw new TaskException( message );
}
run( commandLine, null );
}

/**


+ 2
- 15
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/CCMCreateTask.java View File

@@ -147,15 +147,7 @@ public class CCMCreateTask
cmd.setExecutable( getCcmCommand() );
cmd.addArgument( COMMAND_DEFAULT_TASK );
cmd.addArgument( m_task );

getContext().debug( commandLine.toString() );

final int result2 = run( cmd, null );
if( result2 != 0 )
{
final String message = "Failed executing: " + cmd.toString();
throw new TaskException( message );
}
run( cmd, null );
}

private Commandline determineTask()
@@ -170,12 +162,7 @@ public class CCMCreateTask

checkOptions( commandLine );

final int result = run( commandLine, this );
if( result != 0 )
{
final String message = "Failed executing: " + commandLine.toString();
throw new TaskException( message );
}
run( commandLine, this );
return commandLine;
}



+ 1
- 6
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/CCMReconfigure.java View File

@@ -85,12 +85,7 @@ public class CCMReconfigure

checkOptions( cmd );

final int result = run( cmd, null );
if( result != 0 )
{
final String message = "Failed executing: " + cmd.toString();
throw new TaskException( message );
}
run( cmd, null );
}

/**


+ 4
- 4
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/Continuus.java View File

@@ -106,17 +106,17 @@ public abstract class Continuus
return toReturn;
}

protected int run( final Commandline cmd, final ExecOutputHandler handler )
protected void run( final Commandline cmd, final ExecOutputHandler handler )
throws TaskException
{
final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();
if( null != handler )
{
exe.setExecOutputHandler( handler );
}
exe.setWorkingDirectory( getBaseDirectory() );
exe.setCommandline( cmd );
return exe.execute();
exe.setReturnCode( 0 );
exe.execute( getContext() );
}
}

+ 1
- 6
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCCheckin.java View File

@@ -339,12 +339,7 @@ public class CCCheckin extends ClearCase

checkOptions( commandLine );

final int result = run( commandLine );
if( result != 0 )
{
final String message = "Failed executing: " + commandLine.toString();
throw new TaskException( message );
}
run( commandLine );
}

/**


+ 1
- 6
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCCheckout.java View File

@@ -427,12 +427,7 @@ public class CCCheckout extends ClearCase

checkOptions( commandLine );

final int result = run( commandLine );
if( result != 0 )
{
final String message = "Failed executing: " + commandLine.toString();
throw new TaskException( message );
}
run( commandLine );
}

/**


+ 1
- 6
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCUnCheckout.java View File

@@ -131,12 +131,7 @@ public class CCUnCheckout extends ClearCase

checkOptions( commandLine );

final int result = run( commandLine );
if( result != 0 )
{
final String message = "Failed executing: " + commandLine.toString();
throw new TaskException( message );
}
run( commandLine );
}

/**


+ 1
- 9
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCUpdate.java View File

@@ -341,15 +341,7 @@ public class CCUpdate extends ClearCase
// Check the command line options
checkOptions( commandLine );

// For debugging
System.out.println( commandLine.toString() );

final int result = run( commandLine );
if( result != 0 )
{
final String message = "Failed executing: " + commandLine.toString();
throw new TaskException( message );
}
run( commandLine );
}

/**


+ 4
- 4
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/ClearCase.java View File

@@ -102,14 +102,14 @@ public abstract class ClearCase extends AbstractTask
return toReturn;
}

protected int run( Commandline cmd )
protected void run( Commandline cmd )
throws TaskException
{
final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();
exe.setWorkingDirectory( getBaseDirectory() );
exe.setCommandline( cmd );
return exe.execute();
exe.setReturnCode( 0 );
exe.execute( getContext() );
}

}


+ 2
- 3
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/DefaultCompilerAdapter.java View File

@@ -370,12 +370,11 @@ public abstract class DefaultCompilerAdapter
commandArray = args;
}

final ExecManager execManager = (ExecManager)m_attributes.getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();
exe.setWorkingDirectory( m_baseDir );
final String[] commandline = commandArray;
exe.setCommandline( new Commandline( commandline ) );
return exe.execute();
return exe.execute( getTaskContext() );
}
finally
{


+ 2
- 3
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javacc/JJTree.java View File

@@ -181,11 +181,10 @@ public class JJTree
cmdl.addVmArgument( "-mx140M" );
cmdl.addVmArgument( "-Dinstall.root=" + javaccHome.getAbsolutePath() );

final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();
getContext().debug( cmdl.toString() );
exe.setCommandline( new Commandline( cmdl.getCommandline() ) );
exe.setReturnCode( 0 );
exe.execute();
exe.execute( getContext() );
}
}

+ 2
- 3
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javacc/JavaCC.java View File

@@ -241,12 +241,11 @@ public class JavaCC
throws TaskException
{
getContext().debug( cmdline.toString() );
final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();
final String[] commandline = cmdline.getCommandline();
exe.setCommandline( new Commandline( commandline ) );
exe.setReturnCode( 0 );
exe.execute();
exe.execute( getContext() );
}

/**


+ 2
- 3
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javadoc/Javadoc.java View File

@@ -820,8 +820,7 @@ public class Javadoc

getContext().info( "Javadoc execution" );

final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();
exe.setExecOutputHandler( this );

/*
@@ -835,7 +834,7 @@ public class Javadoc
exe.setReturnCode( 0 );
try
{
exe.execute();
exe.execute( getContext() );
}
finally
{


+ 2
- 3
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jdepend/JDependTask.java View File

@@ -241,8 +241,7 @@ public class JDependTask
commandline.addArgument( f.getPath() );
}

final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();

final String[] commandline1 = commandline.getCommandline();
exe.setCommandline( new Commandline( commandline1 ) );
@@ -256,7 +255,7 @@ public class JDependTask
getContext().info( "Output to be stored in " + m_outputFile.getPath() );
}
getContext().debug( "Executing: " + commandline.toString() );
return exe.execute();
return exe.execute( getContext() );
}




+ 2
- 3
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/JUnitTask.java View File

@@ -632,8 +632,7 @@ public class JUnitTask extends AbstractTask
throw new TaskException( "Error creating temporary properties file.", ioe );
}

final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();
exe.setCommandline( new Commandline( cmd.getCommandline() ) );
if( dir != null )
{
@@ -643,7 +642,7 @@ public class JUnitTask extends AbstractTask
getContext().debug( "Executing: " + cmd.toString() );
try
{
return exe.execute();
return exe.execute( getContext() );
}
finally
{


+ 2
- 6
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/AbstractMetamataTask.java View File

@@ -273,20 +273,16 @@ public abstract class AbstractMetamataTask

/**
* execute the process with a specific handler
*
* @param handler Description of Parameter
* @exception TaskException Description of Exception
*/
protected void execute0()
throws TaskException
{
final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();
getContext().debug( m_cmdl.toString() );
final String[] commandline = m_cmdl.getCommandline();
exe.setCommandline( new Commandline( commandline ) );
exe.setReturnCode( 0 );
exe.execute();
exe.execute( getContext() );
}

protected void generateOptionsFile( File tofile, ArrayList options )


+ 2
- 3
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/MParse.java View File

@@ -288,13 +288,12 @@ public class MParse
return;
}

final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();
getContext().debug( m_cmdl.toString() );
final String[] commandline = m_cmdl.getCommandline();
exe.setCommandline( new Commandline( commandline ) );
exe.setReturnCode( 0 );
exe.execute();
exe.execute( getContext() );
}

/**


+ 2
- 3
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/perforce/P4Base.java View File

@@ -165,12 +165,11 @@ public abstract class P4Base
handler = this;
}

final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();
exe.setExecOutputHandler( handler );
exe.setCommandline( cmd );

exe.execute();
exe.execute( getContext() );
if( null != m_error )
{
throw m_error;


+ 4
- 7
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/pvcs/Pvcs.java View File

@@ -189,14 +189,12 @@ public class Pvcs

final Commandline cmd = buildGetCommand( filelist );
getContext().info( "Getting files" );
getContext().debug( "Executing " + cmd.toString() );
try
{
final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();
exe.setWorkingDirectory( getBaseDirectory() );
exe.setCommandline( cmd );
result = exe.execute();
result = exe.execute( getContext() );
checkResultCode( result, cmd );
}
finally
@@ -268,13 +266,12 @@ public class Pvcs
tmp = File.createTempFile( "pvcs_ant_", ".log" );
final File fileList = File.createTempFile( "pvcs_ant_", ".log" );

final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();
exe.setExecOutputHandler( this );
m_output = new FileOutputStream( tmp );
exe.setWorkingDirectory( getBaseDirectory() );
exe.setCommandline( cmd );
final int result = exe.execute();
final int result = exe.execute( getContext() );
checkResultCode( result, cmd );

if( !tmp.exists() )


+ 3
- 12
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/CovMerge.java View File

@@ -116,22 +116,13 @@ public class CovMerge
}
cmdl.addArgument( "-jp_paramfile=" + paramfile.getAbsolutePath() );

final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
getContext().debug( cmdl.toString() );
final Execute exe = new Execute();
exe.setCommandline( cmdl );
exe.setReturnCode( 0 );

// JProbe process always return 0 so we will not be
// able to check for failure ! :-(
int exitValue = exe.execute();
if( exitValue != 0 )
{
throw new TaskException( "JProbe Coverage Merging failed (" + exitValue + ")" );
}
}
catch( IOException e )
{
throw new TaskException( "Failed to run JProbe Coverage Merge: " + e );
exe.execute( getContext() );
}
finally
{


+ 3
- 8
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/CovReport.java View File

@@ -249,15 +249,10 @@ public class CovReport
}

// use the custom handler for stdin issues
final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
getContext().debug( cmdl.toString() );
final Execute exe = new Execute();
exe.setCommandline( cmdl );
int exitValue = exe.execute();
if( exitValue != 0 )
{
throw new TaskException( "JProbe Coverage Report failed (" + exitValue + ")" );
}
exe.setReturnCode( 0 );
exe.execute( getContext() );
getContext().debug( "coveragePath: " + coveragePath );
getContext().debug( "format: " + format );
if( reference != null && "xml".equals( format ) )


+ 3
- 12
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/Coverage.java View File

@@ -250,19 +250,10 @@ public class Coverage
cmdl.addArgument( "-jp_input=" + paramfile.getAbsolutePath() );

// use the custom handler for stdin issues
final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
getContext().debug( cmdl.toString() );
final Execute exe = new Execute();
exe.setCommandline( cmdl );
int exitValue = exe.execute();
if( exitValue != 0 )
{
throw new TaskException( "JProbe Coverage failed (" + exitValue + ")" );
}
}
catch( IOException e )
{
throw new TaskException( "Failed to execute JProbe Coverage.", e );
exe.setReturnCode( 0 );
exe.execute( getContext() );
}
finally
{


+ 4
- 4
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSS.java View File

@@ -199,11 +199,10 @@ public abstract class MSVSS
return m_vssPath;
}

protected int run( Commandline cmd )
protected void run( final Commandline cmd )
throws TaskException
{
final ExecManager execManager = (ExecManager)getService( ExecManager.class );
final Execute exe = new Execute( execManager );
final Execute exe = new Execute();

// If location of ss.ini is specified we need to set the
// environment-variable SSDIR to this value
@@ -216,7 +215,8 @@ public abstract class MSVSS

exe.setWorkingDirectory( getBaseDirectory() );
exe.setCommandline( cmd );
return exe.execute();
exe.setReturnCode( 0 );
exe.execute( getContext() );
}
}


+ 1
- 8
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKIN.java View File

@@ -9,8 +9,6 @@ package org.apache.tools.todo.taskdefs.vss;

import java.io.File;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.api.AbstractTask;
import org.apache.myrmidon.api.TaskContext;
import org.apache.tools.todo.types.Commandline;
import org.apache.tools.todo.types.Path;

@@ -208,11 +206,6 @@ public class MSVSSCHECKIN
// -C
commandLine.addArgument( "-C" + m_comment );

final int result = run( commandLine );
if( result != 0 )
{
final String message = "Failed executing: " + commandLine.toString();
throw new TaskException( message );
}
run( commandLine );
}
}

+ 1
- 8
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKOUT.java View File

@@ -9,8 +9,6 @@ package org.apache.tools.todo.taskdefs.vss;

import java.io.File;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.api.AbstractTask;
import org.apache.myrmidon.api.TaskContext;
import org.apache.tools.todo.types.Commandline;
import org.apache.tools.todo.types.Path;

@@ -250,12 +248,7 @@ public class MSVSSCHECKOUT
// -Y
getLoginCommand( commandLine );

final int result = run( commandLine );
if( result != 0 )
{
final String message = "Failed executing: " + commandLine.toString();
throw new TaskException( message );
}
run( commandLine );
}
}


+ 1
- 9
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSGET.java View File

@@ -9,8 +9,6 @@ package org.apache.tools.todo.taskdefs.vss;

import java.io.File;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.api.AbstractTask;
import org.apache.myrmidon.api.TaskContext;
import org.apache.tools.todo.types.Commandline;
import org.apache.tools.todo.types.Path;

@@ -471,7 +469,6 @@ public class MSVSSGET extends MSVSS
throws TaskException
{
Commandline commandLine = new Commandline();
int result = 0;

// first off, make sure that we've got a command and a vssdir ...
if( getVsspath() == null )
@@ -505,12 +502,7 @@ public class MSVSSGET extends MSVSS
// -Y
getLoginCommand( commandLine );

result = run( commandLine );
if( result != 0 )
{
String msg = "Failed executing: " + commandLine.toString();
throw new TaskException( msg );
}
run( commandLine );
}

}


+ 1
- 8
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSHISTORY.java View File

@@ -222,7 +222,6 @@ public class MSVSSHISTORY extends MSVSS
throws TaskException
{
Commandline commandLine = new Commandline();
int result = 0;

// first off, make sure that we've got a command and a vssdir and a label ...
if( getVsspath() == null )
@@ -270,13 +269,7 @@ public class MSVSSHISTORY extends MSVSS

System.out.println( "***: " + commandLine );

result = run( commandLine );
if( result != 0 )
{
String msg = "Failed executing: " + commandLine.toString();
throw new TaskException( msg );
}

run( commandLine );
}

/**


+ 1
- 8
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSLABEL.java View File

@@ -323,7 +323,6 @@ public class MSVSSLABEL extends MSVSS
throws TaskException
{
Commandline commandLine = new Commandline();
int result = 0;

// first off, make sure that we've got a command and a vssdir and a label ...
if( getVsspath() == null )
@@ -365,12 +364,6 @@ public class MSVSSLABEL extends MSVSS
// -Y
getLoginCommand( commandLine );

result = run( commandLine );
if( result != 0 )
{
String msg = "Failed executing: " + commandLine.toString();
throw new TaskException( msg );
}

run( commandLine );
}
}

+ 27
- 3
proposal/myrmidon/src/todo/org/apache/tools/todo/util/FileUtils.java View File

@@ -184,6 +184,30 @@ public class FileUtils
return new File( path );
}

/**
* Builds a command-line from an array of individual arguments, quoting
* the arguments as necessary.
*
* @todo Move to {@link org.apache.aut.nativelib.Os}, and get rid of the
* exception.
*/
public static String buildCommandLine( final String[] arguments )
throws TaskException
{
final StringBuffer cmd = new StringBuffer();
for( int i = 0; i < arguments.length; i++ )
{
String arg = arguments[ i ];
if( i > 0 )
{
cmd.append( ' ' );
}
cmd.append( quoteArgument( arg ) );
}

return cmd.toString();
}

/**
* Put quotes around the given String if necessary. <p>
*
@@ -191,10 +215,10 @@ public class FileUtils
* contains double quotes, use single quotes - else surround the argument by
* double quotes.</p>
*
* @param argument Description of Parameter
* @return Description of the Returned Value
* @todo Move to {@link org.apache.aut.nativelib.Os}, and get rid of the
* exception.
*/
public static String quoteArgument( String argument )
public static String quoteArgument( final String argument )
throws TaskException
{
if( argument.indexOf( "\"" ) > -1 )


Loading…
Cancel
Save