From b6410584b65289fce8b334f40163fa2b6203479d Mon Sep 17 00:00:00 2001 From: adammurdoch Date: Mon, 18 Mar 2002 08:53:31 +0000 Subject: [PATCH] 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 --- .../java/org/apache/antlib/build/Patch.java | 5 +- .../java/org/apache/antlib/cvslib/Cvs.java | 5 +- .../java/org/apache/antlib/dotnet/CSharp.java | 5 +- .../java/org/apache/antlib/dotnet/Ilasm.java | 5 +- .../org/apache/antlib/nativelib/Exec.java | 61 ++------- .../antlib/nativelib/Resources.properties | 8 -- .../apache/antlib/security/GenerateKey.java | 5 +- .../org/apache/antlib/security/SignJar.java | 5 +- .../java/org/apache/myrmidon/api/Task.java | 4 - .../workspace/ProjectListenerSupport.java | 2 +- .../apache/myrmidon/framework/Execute.java | 127 ++++++++++++------ .../framework/LoggingExecOutputHandler.java | 47 +++++++ .../myrmidon/framework/Resources.properties | 11 +- .../org/apache/tools/todo/taskdefs/ANTLR.java | 5 +- .../org/apache/tools/todo/taskdefs/Cab.java | 5 +- .../org/apache/tools/todo/taskdefs/Java.java | 5 +- .../org/apache/tools/todo/taskdefs/Rpm.java | 5 +- .../tools/todo/taskdefs/ccm/CCMCheck.java | 7 +- .../todo/taskdefs/ccm/CCMCreateTask.java | 17 +-- .../todo/taskdefs/ccm/CCMReconfigure.java | 7 +- .../tools/todo/taskdefs/ccm/Continuus.java | 8 +- .../todo/taskdefs/clearcase/CCCheckin.java | 7 +- .../todo/taskdefs/clearcase/CCCheckout.java | 7 +- .../todo/taskdefs/clearcase/CCUnCheckout.java | 7 +- .../todo/taskdefs/clearcase/CCUpdate.java | 10 +- .../todo/taskdefs/clearcase/ClearCase.java | 8 +- .../javac/DefaultCompilerAdapter.java | 5 +- .../tools/todo/taskdefs/javacc/JJTree.java | 5 +- .../tools/todo/taskdefs/javacc/JavaCC.java | 5 +- .../tools/todo/taskdefs/javadoc/Javadoc.java | 5 +- .../todo/taskdefs/jdepend/JDependTask.java | 5 +- .../tools/todo/taskdefs/junit/JUnitTask.java | 5 +- .../metamata/AbstractMetamataTask.java | 8 +- .../tools/todo/taskdefs/metamata/MParse.java | 5 +- .../tools/todo/taskdefs/perforce/P4Base.java | 5 +- .../apache/tools/todo/taskdefs/pvcs/Pvcs.java | 11 +- .../tools/todo/taskdefs/sitraka/CovMerge.java | 15 +-- .../todo/taskdefs/sitraka/CovReport.java | 11 +- .../tools/todo/taskdefs/sitraka/Coverage.java | 15 +-- .../apache/tools/todo/taskdefs/vss/MSVSS.java | 8 +- .../tools/todo/taskdefs/vss/MSVSSCHECKIN.java | 9 +- .../todo/taskdefs/vss/MSVSSCHECKOUT.java | 9 +- .../tools/todo/taskdefs/vss/MSVSSGET.java | 10 +- .../tools/todo/taskdefs/vss/MSVSSHISTORY.java | 9 +- .../tools/todo/taskdefs/vss/MSVSSLABEL.java | 9 +- .../org/apache/tools/todo/util/FileUtils.java | 30 ++++- 46 files changed, 255 insertions(+), 317 deletions(-) create mode 100644 proposal/myrmidon/src/java/org/apache/myrmidon/framework/LoggingExecOutputHandler.java diff --git a/proposal/myrmidon/src/java/org/apache/antlib/build/Patch.java b/proposal/myrmidon/src/java/org/apache/antlib/build/Patch.java index cf783cbc0..f4b20b0b0 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/build/Patch.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/build/Patch.java @@ -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() diff --git a/proposal/myrmidon/src/java/org/apache/antlib/cvslib/Cvs.java b/proposal/myrmidon/src/java/org/apache/antlib/cvslib/Cvs.java index 77b73a352..d0af60127 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/cvslib/Cvs.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/cvslib/Cvs.java @@ -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() diff --git a/proposal/myrmidon/src/java/org/apache/antlib/dotnet/CSharp.java b/proposal/myrmidon/src/java/org/apache/antlib/dotnet/CSharp.java index 3345fe693..2998454b9 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/dotnet/CSharp.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/dotnet/CSharp.java @@ -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 ) diff --git a/proposal/myrmidon/src/java/org/apache/antlib/dotnet/Ilasm.java b/proposal/myrmidon/src/java/org/apache/antlib/dotnet/Ilasm.java index 7caf116e4..9dbaedf60 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/dotnet/Ilasm.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/dotnet/Ilasm.java @@ -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 ) diff --git a/proposal/myrmidon/src/java/org/apache/antlib/nativelib/Exec.java b/proposal/myrmidon/src/java/org/apache/antlib/nativelib/Exec.java index 436a99d2f..b44f5aaae 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/nativelib/Exec.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/nativelib/Exec.java @@ -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 ); - } } diff --git a/proposal/myrmidon/src/java/org/apache/antlib/nativelib/Resources.properties b/proposal/myrmidon/src/java/org/apache/antlib/nativelib/Resources.properties index b713f3f2e..86749caaa 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/nativelib/Resources.properties +++ b/proposal/myrmidon/src/java/org/apache/antlib/nativelib/Resources.properties @@ -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}. diff --git a/proposal/myrmidon/src/java/org/apache/antlib/security/GenerateKey.java b/proposal/myrmidon/src/java/org/apache/antlib/security/GenerateKey.java index 356ca87ad..973cff9ae 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/security/GenerateKey.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/security/GenerateKey.java @@ -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() diff --git a/proposal/myrmidon/src/java/org/apache/antlib/security/SignJar.java b/proposal/myrmidon/src/java/org/apache/antlib/security/SignJar.java index 2c10ee406..72bbf5b93 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/security/SignJar.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/security/SignJar.java @@ -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 ) diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/api/Task.java b/proposal/myrmidon/src/java/org/apache/myrmidon/api/Task.java index 0bb5d37ac..f4015a654 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/api/Task.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/api/Task.java @@ -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 Peter Donald * @version $Revision$ $Date$ * @ant:role shorthand="task" diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/ProjectListenerSupport.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/ProjectListenerSupport.java index 9c4039898..5eb107ddc 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/ProjectListenerSupport.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/ProjectListenerSupport.java @@ -16,7 +16,7 @@ import org.apache.myrmidon.listeners.ProjectListener; * @author Peter Donald * @version $Revision$ $Date$ */ -public class ProjectListenerSupport +class ProjectListenerSupport implements LogEvent { private ProjectListener[] m_listeners = new ProjectListener[ 0 ]; diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Execute.java b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Execute.java index fab3acdeb..830c8d1ac 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Execute.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Execute.java @@ -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 INVALID + * @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 ); diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/LoggingExecOutputHandler.java b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/LoggingExecOutputHandler.java new file mode 100644 index 000000000..85464879d --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/LoggingExecOutputHandler.java @@ -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 Adam Murdoch + * @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 ); + } +} diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Resources.properties b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Resources.properties index 243960646..a98af85d6 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Resources.properties +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Resources.properties @@ -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}". \ No newline at end of file +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}. + diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ANTLR.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ANTLR.java index 10ed92490..add470255 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ANTLR.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ANTLR.java @@ -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 ) { diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Cab.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Cab.java index f2ed5825d..3bd8af5e5 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Cab.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Cab.java @@ -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(); } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Java.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Java.java index 239fd3793..5e4b669b7 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Java.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Java.java @@ -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() ); } } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Rpm.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Rpm.java index 602efb473..ec59c4016 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Rpm.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Rpm.java @@ -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() diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/CCMCheck.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/CCMCheck.java index f72a32997..e94bb62b9 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/CCMCheck.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/CCMCheck.java @@ -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 ); } /** diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/CCMCreateTask.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/CCMCreateTask.java index 6e56dc733..d75ec42ac 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/CCMCreateTask.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/CCMCreateTask.java @@ -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; } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/CCMReconfigure.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/CCMReconfigure.java index 822572dd4..e113f0108 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/CCMReconfigure.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/CCMReconfigure.java @@ -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 ); } /** diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/Continuus.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/Continuus.java index 1de06e8a0..9cdc514b9 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/Continuus.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/Continuus.java @@ -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() ); } } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCCheckin.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCCheckin.java index efdd6b94b..0da1a15ae 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCCheckin.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCCheckin.java @@ -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 ); } /** diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCCheckout.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCCheckout.java index be283d2b6..65a980f81 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCCheckout.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCCheckout.java @@ -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 ); } /** diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCUnCheckout.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCUnCheckout.java index aa0379283..a6744c286 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCUnCheckout.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCUnCheckout.java @@ -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 ); } /** diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCUpdate.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCUpdate.java index 5e9ee1053..a3448f195 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCUpdate.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/CCUpdate.java @@ -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 ); } /** diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/ClearCase.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/ClearCase.java index 56fe846a0..0801439a4 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/ClearCase.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/ClearCase.java @@ -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() ); } } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/DefaultCompilerAdapter.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/DefaultCompilerAdapter.java index 95d124cd8..8451cb81b 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/DefaultCompilerAdapter.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/DefaultCompilerAdapter.java @@ -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 { diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javacc/JJTree.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javacc/JJTree.java index a4762b45d..4bed5c74a 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javacc/JJTree.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javacc/JJTree.java @@ -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() ); } } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javacc/JavaCC.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javacc/JavaCC.java index ed946fb39..1019c207b 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javacc/JavaCC.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javacc/JavaCC.java @@ -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() ); } /** diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javadoc/Javadoc.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javadoc/Javadoc.java index d19846993..d6ac1ab5e 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javadoc/Javadoc.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javadoc/Javadoc.java @@ -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 { diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jdepend/JDependTask.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jdepend/JDependTask.java index a73955b3a..ef8e0bc5d 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jdepend/JDependTask.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jdepend/JDependTask.java @@ -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() ); } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/JUnitTask.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/JUnitTask.java index d430a8e63..5f57b4bde 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/JUnitTask.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/JUnitTask.java @@ -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 { diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/AbstractMetamataTask.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/AbstractMetamataTask.java index d7d1b326d..b805411ca 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/AbstractMetamataTask.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/AbstractMetamataTask.java @@ -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 ) diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/MParse.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/MParse.java index 493863d36..811e1d4aa 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/MParse.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/MParse.java @@ -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() ); } /** diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/perforce/P4Base.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/perforce/P4Base.java index 71ac06008..d413e54ff 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/perforce/P4Base.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/perforce/P4Base.java @@ -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; diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/pvcs/Pvcs.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/pvcs/Pvcs.java index 2b4a359d5..b389e8548 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/pvcs/Pvcs.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/pvcs/Pvcs.java @@ -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() ) diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/CovMerge.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/CovMerge.java index e51cc3e17..8a4e1a09d 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/CovMerge.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/CovMerge.java @@ -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 { diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/CovReport.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/CovReport.java index 657f0311c..ed53fcab8 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/CovReport.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/CovReport.java @@ -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 ) ) diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/Coverage.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/Coverage.java index 698728a30..1280b8a85 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/Coverage.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/Coverage.java @@ -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 { diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSS.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSS.java index 2a5d7c4c9..d5f9bb7b1 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSS.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSS.java @@ -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() ); } } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKIN.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKIN.java index 1ed640dd4..562910f70 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKIN.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKIN.java @@ -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 ); } } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKOUT.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKOUT.java index 48323fb77..785309f5d 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKOUT.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKOUT.java @@ -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 ); } } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSGET.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSGET.java index ff808ebd6..6ae0137cb 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSGET.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSGET.java @@ -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 ); } } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSHISTORY.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSHISTORY.java index 933870823..757797323 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSHISTORY.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSHISTORY.java @@ -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 ); } /** diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSLABEL.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSLABEL.java index b361b4bdd..0a0d9adef 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSLABEL.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSLABEL.java @@ -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 ); } } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/util/FileUtils.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/util/FileUtils.java index c0fa2f068..195459ccd 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/util/FileUtils.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/todo/util/FileUtils.java @@ -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.

* @@ -191,10 +215,10 @@ public class FileUtils * contains double quotes, use single quotes - else surround the argument by * double quotes.

* - * @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 )