* By default, execute() checks the return code of the process against 0. This can be changed using setReturnCode() and setIgnoreReturnCode(). * Default working directory is now the project's base directory. * Tidied up tasks to reflect the new defaults. AbstractTask: * Made getBaseDirectory() and getService() protected. Logging: * Extracted AbstractLogger out of BasicLogger, and changed RoutingLogger to extend AbstractLogger, rather than BasicLogger. * RoutingLogger now uses a wrapped Logger to determine which message types are enabled, so that it respects the logging level set on the command-line. Kinda hacky, but better than writing out all the debug messages. * Changed LoggingExecOutputHandler to use warn log level, rather than info. Again, a hacky fix to get logging of external command output happening when not running in verbose mode. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271890 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -147,15 +147,10 @@ public class Cvs | |||||
| final Properties env = buildEnvironment(); | final Properties env = buildEnvironment(); | ||||
| final Execute exe = new Execute(); | final Execute exe = new Execute(); | ||||
| if( m_dest == null ) | |||||
| { | |||||
| m_dest = getBaseDirectory(); | |||||
| } | |||||
| exe.setWorkingDirectory( m_dest ); | exe.setWorkingDirectory( m_dest ); | ||||
| exe.setCommandline( command ); | exe.setCommandline( command ); | ||||
| exe.setEnvironment( env ); | exe.setEnvironment( env ); | ||||
| exe.setReturnCode( 0 ); | |||||
| exe.execute( getContext() ); | exe.execute( getContext() ); | ||||
| } | } | ||||
| @@ -504,8 +504,6 @@ public class CSharp | |||||
| } | } | ||||
| final Execute exe = new Execute(); | final Execute exe = new Execute(); | ||||
| exe.setReturnCode( 0 ); | |||||
| final Commandline cmd = exe.getCommandline(); | final Commandline cmd = exe.getCommandline(); | ||||
| cmd.setExecutable( EXE_NAME ); | cmd.setExecutable( EXE_NAME ); | ||||
| @@ -248,8 +248,6 @@ public class Ilasm | |||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| final Execute exe = new Execute(); | final Execute exe = new Execute(); | ||||
| exe.setReturnCode( 0 ); | |||||
| final Commandline cmd = exe.getCommandline(); | final Commandline cmd = exe.getCommandline(); | ||||
| cmd.setExecutable( EXE_NAME ); | cmd.setExecutable( EXE_NAME ); | ||||
| addArgument( cmd, getDebugParameter() ); | addArgument( cmd, getDebugParameter() ); | ||||
| @@ -105,15 +105,8 @@ public class Exec | |||||
| return; | return; | ||||
| } | } | ||||
| // default directory to the project's base directory | |||||
| if( m_dir == null ) | |||||
| { | |||||
| m_dir = getBaseDirectory(); | |||||
| } | |||||
| // execute the command | // execute the command | ||||
| final Execute exe = createExecute(); | final Execute exe = createExecute(); | ||||
| exe.setReturnCode( 0 ); | |||||
| exe.execute( getContext() ); | exe.execute( getContext() ); | ||||
| } | } | ||||
| @@ -120,7 +120,6 @@ public class GenerateKey | |||||
| final Commandline cmd = createCommand(); | final Commandline cmd = createCommand(); | ||||
| final Execute exe = new Execute(); | final Execute exe = new Execute(); | ||||
| exe.setWorkingDirectory( getBaseDirectory() ); | |||||
| exe.setCommandline( cmd ); | exe.setCommandline( cmd ); | ||||
| exe.execute( getContext() ); | exe.execute( getContext() ); | ||||
| } | } | ||||
| @@ -52,14 +52,22 @@ public abstract class AbstractTask | |||||
| return m_context; | return m_context; | ||||
| } | } | ||||
| //Needs to be made protected | |||||
| public final File getBaseDirectory() | |||||
| /** | |||||
| * Convenience method that returns the project's base directory. | |||||
| */ | |||||
| protected final File getBaseDirectory() | |||||
| { | { | ||||
| return getContext().getBaseDirectory(); | return getContext().getBaseDirectory(); | ||||
| } | } | ||||
| ///HACK: Make this protected | |||||
| public final Object getService( final Class serviceClass ) | |||||
| /** | |||||
| * Convenience method that locates a service for this task to use. | |||||
| * | |||||
| * @param serviceClass the service to locate. | |||||
| * @return the service, never returns null. | |||||
| * @throws TaskException if the service cannot be located. | |||||
| */ | |||||
| protected final Object getService( final Class serviceClass ) | |||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| return getContext().getService( serviceClass ); | return getContext().getService( serviceClass ); | ||||
| @@ -272,8 +272,11 @@ class Deployment | |||||
| try | try | ||||
| { | { | ||||
| final String message = REZ.getString( "url-deploy-roles.notice", descriptor.getUrl() ); | |||||
| getLogger().info( message ); | |||||
| if( getLogger().isDebugEnabled() ) | |||||
| { | |||||
| final String message = REZ.getString( "url-deploy-roles.notice", descriptor.getUrl() ); | |||||
| getLogger().debug( message ); | |||||
| } | |||||
| final RoleDefinition[] definitions = descriptor.getDefinitions(); | final RoleDefinition[] definitions = descriptor.getDefinitions(); | ||||
| for( int i = 0; i < definitions.length; i++ ) | for( int i = 0; i < definitions.length; i++ ) | ||||
| @@ -297,8 +300,11 @@ class Deployment | |||||
| { | { | ||||
| try | try | ||||
| { | { | ||||
| final String message = REZ.getString( "url-deploy-types.notice", descriptor.getUrl() ); | |||||
| getLogger().info( message ); | |||||
| if( getLogger().isDebugEnabled() ) | |||||
| { | |||||
| final String message = REZ.getString( "url-deploy-types.notice", descriptor.getUrl() ); | |||||
| getLogger().debug( message ); | |||||
| } | |||||
| // Deploy all the types | // Deploy all the types | ||||
| final TypeDefinition[] definitions = descriptor.getDefinitions(); | final TypeDefinition[] definitions = descriptor.getDefinitions(); | ||||
| @@ -324,8 +330,11 @@ class Deployment | |||||
| try | try | ||||
| { | { | ||||
| final String message = REZ.getString( "url-deploy-services.notice", descriptor.getUrl() ); | |||||
| getLogger().info( message ); | |||||
| if( getLogger().isDebugEnabled() ) | |||||
| { | |||||
| final String message = REZ.getString( "url-deploy-services.notice", descriptor.getUrl() ); | |||||
| getLogger().debug( message ); | |||||
| } | |||||
| // Deploy the services | // Deploy the services | ||||
| final ServiceDefinition[] definitions = descriptor.getDefinitions(); | final ServiceDefinition[] definitions = descriptor.getDefinitions(); | ||||
| @@ -247,14 +247,15 @@ public class DefaultWorkspace | |||||
| // Create a logger | // Create a logger | ||||
| final Logger logger = | final Logger logger = | ||||
| new RoutingLogger( RoutingLogger.LEVEL_DEBUG, m_listenerSupport ); | |||||
| new RoutingLogger( getLogger(), m_listenerSupport ); | |||||
| // Create and configure the context | // Create and configure the context | ||||
| final DefaultTaskContext context = | final DefaultTaskContext context = | ||||
| new DefaultTaskContext( m_baseContext, serviceManager, logger ); | new DefaultTaskContext( m_baseContext, serviceManager, logger ); | ||||
| context.setProperty( TaskContext.BASE_DIRECTORY, project.getBaseDirectory() ); | context.setProperty( TaskContext.BASE_DIRECTORY, project.getBaseDirectory() ); | ||||
| final DefaultExecutionFrame frame = new DefaultExecutionFrame( logger, context, typeManager ); | |||||
| final DefaultExecutionFrame frame = | |||||
| new DefaultExecutionFrame( logger, context, typeManager ); | |||||
| /** | /** | ||||
| * @todo Should no occur but done for the time being to simplify evolution. | * @todo Should no occur but done for the time being to simplify evolution. | ||||
| @@ -7,31 +7,72 @@ | |||||
| */ | */ | ||||
| package org.apache.myrmidon.components.workspace; | package org.apache.myrmidon.components.workspace; | ||||
| import org.apache.myrmidon.frontends.BasicLogger; | |||||
| import org.apache.avalon.framework.logger.Logger; | |||||
| import org.apache.myrmidon.frontends.AbstractLogger; | |||||
| /** | /** | ||||
| * A basic logger that just routes the messages to the ProjectListenerSupport. | |||||
| * A logger that just routes the messages to the ProjectListenerSupport. | |||||
| * | * | ||||
| * @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
| * @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
| */ | */ | ||||
| final class RoutingLogger | final class RoutingLogger | ||||
| extends BasicLogger | |||||
| extends AbstractLogger | |||||
| implements Logger | |||||
| { | { | ||||
| /** | /** | ||||
| * The endpoint of all the logging messages. | * The endpoint of all the logging messages. | ||||
| */ | */ | ||||
| private final ProjectListenerSupport m_listenerSupport; | private final ProjectListenerSupport m_listenerSupport; | ||||
| /** | |||||
| * A wrapped logger that is used to determine which message types are | |||||
| * enabled. | |||||
| */ | |||||
| private final Logger m_logger; | |||||
| /** | /** | ||||
| * Create a Logger that routes messages at specified level | * Create a Logger that routes messages at specified level | ||||
| * to specified support. | * to specified support. | ||||
| * | |||||
| * @todo Use something other than a logger to figure out which messages | |||||
| * are enabled. | |||||
| */ | */ | ||||
| public RoutingLogger( final int logLevel, | |||||
| public RoutingLogger( final Logger logger, | |||||
| final ProjectListenerSupport listenerSupport ) | final ProjectListenerSupport listenerSupport ) | ||||
| { | { | ||||
| super( null, logLevel ); | |||||
| m_listenerSupport = listenerSupport; | m_listenerSupport = listenerSupport; | ||||
| m_logger = logger; | |||||
| } | |||||
| public boolean isDebugEnabled() | |||||
| { | |||||
| return m_logger.isDebugEnabled(); | |||||
| } | |||||
| public boolean isInfoEnabled() | |||||
| { | |||||
| return m_logger.isInfoEnabled(); | |||||
| } | |||||
| public boolean isWarnEnabled() | |||||
| { | |||||
| return m_logger.isWarnEnabled(); | |||||
| } | |||||
| public boolean isErrorEnabled() | |||||
| { | |||||
| return m_logger.isErrorEnabled(); | |||||
| } | |||||
| public boolean isFatalErrorEnabled() | |||||
| { | |||||
| return m_logger.isFatalErrorEnabled(); | |||||
| } | |||||
| public Logger getChildLogger( final String name ) | |||||
| { | |||||
| return new RoutingLogger( m_logger.getChildLogger( name ), m_listenerSupport ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -24,6 +24,9 @@ import org.apache.tools.todo.util.FileUtils; | |||||
| * This is a utility class designed to make executing native | * This is a utility class designed to make executing native | ||||
| * processes easier in the context of ant. | * processes easier in the context of ant. | ||||
| * | * | ||||
| * <p>To execute a native process, configure an instance of this class, | |||||
| * and then call its {@link #execute} method. | |||||
| * | |||||
| * @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
| * @author <a href="mailto:thomas.haas@softwired-inc.com">Thomas Haas</a> | * @author <a href="mailto:thomas.haas@softwired-inc.com">Thomas Haas</a> | ||||
| * @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
| @@ -35,32 +38,50 @@ public class Execute | |||||
| private Commandline m_command; | private Commandline m_command; | ||||
| private Properties m_environment = new Properties(); | private Properties m_environment = new Properties(); | ||||
| private File m_workingDirectory = new File( "." ); | |||||
| private File m_workingDirectory; | |||||
| private boolean m_newEnvironment; | private boolean m_newEnvironment; | ||||
| private ExecOutputHandler m_handler; | private ExecOutputHandler m_handler; | ||||
| private long m_timeout; | private long m_timeout; | ||||
| private Integer m_returnCode; | |||||
| private int m_returnCode; | |||||
| private boolean m_ignoreReturnCode; | |||||
| /** | |||||
| * Sets the timeout, in milliseconds, for the process. The process is | |||||
| * forcibly shutdown after this time. Use 0 to allow the process to | |||||
| * run forever. Default is 0. | |||||
| * | |||||
| * @param timeout the timeout, in milliseconds. | |||||
| */ | |||||
| public void setTimeout( final long timeout ) | public void setTimeout( final long timeout ) | ||||
| { | { | ||||
| m_timeout = timeout; | m_timeout = timeout; | ||||
| } | } | ||||
| /** | |||||
| * Sets the handler for the process' output and error streams. If not | |||||
| * provided, the process' output and error are written to the log using | |||||
| * the TaskContext's logging methods. | |||||
| * | |||||
| * @param handler the handler. | |||||
| */ | |||||
| public void setExecOutputHandler( final ExecOutputHandler handler ) | public void setExecOutputHandler( final ExecOutputHandler handler ) | ||||
| { | { | ||||
| m_handler = handler; | m_handler = handler; | ||||
| } | } | ||||
| /** | /** | ||||
| * Sets the commandline of the subprocess to launch. | |||||
| * Sets the commandline of the process to launch. | |||||
| * | * | ||||
| * @param command the commandline of the subprocess to launch | |||||
| * @param command the commandline of the process to launch | |||||
| */ | */ | ||||
| public void setCommandline( final Commandline command ) | public void setCommandline( final Commandline command ) | ||||
| { | { | ||||
| m_command = command; | m_command = command; | ||||
| } | } | ||||
| /** | |||||
| * Returns the commandline of the process to launch. | |||||
| */ | |||||
| public Commandline getCommandline() | public Commandline getCommandline() | ||||
| { | { | ||||
| if( null == m_command ) | if( null == m_command ) | ||||
| @@ -70,6 +91,11 @@ public class Execute | |||||
| return m_command; | return m_command; | ||||
| } | } | ||||
| /** | |||||
| * Sets the environment to use for the process. | |||||
| * | |||||
| * @param environment a map from environment variable name to value. | |||||
| */ | |||||
| public void setEnvironment( final Properties environment ) | public void setEnvironment( final Properties environment ) | ||||
| { | { | ||||
| if( null == environment ) | if( null == environment ) | ||||
| @@ -83,7 +109,7 @@ public class Execute | |||||
| * If this variable is false then then the environment specified is | * If this variable is false then then the environment specified is | ||||
| * added to the environment variables for current process. If this | * added to the environment variables for current process. If this | ||||
| * value is true then the specified environment replaces the environment | * value is true then the specified environment replaces the environment | ||||
| * for the command. | |||||
| * for the command. Default is false. | |||||
| */ | */ | ||||
| public void setNewenvironment( final boolean newEnvironment ) | public void setNewenvironment( final boolean newEnvironment ) | ||||
| { | { | ||||
| @@ -91,18 +117,36 @@ public class Execute | |||||
| } | } | ||||
| /** | /** | ||||
| * Sets the working directory of the process to execute. <p> | |||||
| * Sets the working directory of the process to execute. Default is the | |||||
| * project's base directory. | |||||
| * | * | ||||
| * @param workingDirectory the working directory of the process. | |||||
| * @param workingDirectory the working directory of the process. Use | |||||
| * null for the project's base directory. | |||||
| */ | */ | ||||
| public void setWorkingDirectory( final File workingDirectory ) | public void setWorkingDirectory( final File workingDirectory ) | ||||
| { | { | ||||
| m_workingDirectory = workingDirectory; | m_workingDirectory = workingDirectory; | ||||
| } | } | ||||
| /** | |||||
| * Sets the expected return code of the process. If the process does not | |||||
| * exit with this return code, and exception is thrown by {@link #execute}. | |||||
| * Default is 0. | |||||
| * | |||||
| * @param returnCode the expected return code. | |||||
| */ | |||||
| public void setReturnCode( final int returnCode ) | public void setReturnCode( final int returnCode ) | ||||
| { | { | ||||
| m_returnCode = new Integer( returnCode ); | |||||
| m_returnCode = returnCode; | |||||
| } | |||||
| /** | |||||
| * If set to true, the return code of the process is ignore. If false, | |||||
| * it is compared against the expected return code. Default is false. | |||||
| */ | |||||
| public void setIgnoreReturnCode( final boolean ignore ) | |||||
| { | |||||
| m_ignoreReturnCode = ignore; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -122,11 +166,11 @@ public class Execute | |||||
| // Build the command meta-info | // Build the command meta-info | ||||
| final ExecManager execManager = (ExecManager)context.getService( ExecManager.class ); | final ExecManager execManager = (ExecManager)context.getService( ExecManager.class ); | ||||
| final ExecMetaData metaData = buildExecMetaData( execManager ); | |||||
| final ExecMetaData metaData = buildExecMetaData( context, execManager ); | |||||
| logExecDetails( metaData, context ); | logExecDetails( metaData, context ); | ||||
| // Execute the command and check return code | |||||
| // Execute the process and check return code | |||||
| final int returnCode = execManager.execute( metaData, handler, m_timeout ); | final int returnCode = execManager.execute( metaData, handler, m_timeout ); | ||||
| checkReturnCode( returnCode ); | checkReturnCode( returnCode ); | ||||
| return returnCode; | return returnCode; | ||||
| @@ -167,20 +211,23 @@ public class Execute | |||||
| final String message = REZ.getString( "execute.no-executable.error" ); | final String message = REZ.getString( "execute.no-executable.error" ); | ||||
| throw new TaskException( message ); | throw new TaskException( message ); | ||||
| } | } | ||||
| if( !m_workingDirectory.exists() ) | |||||
| if( m_workingDirectory != null ) | |||||
| { | { | ||||
| final String message = REZ.getString( "execute.dir-noexist.error", m_workingDirectory ); | |||||
| throw new TaskException( message ); | |||||
| } | |||||
| else if( !m_workingDirectory.isDirectory() ) | |||||
| { | |||||
| final String message = REZ.getString( "execute.dir-notdir.error", m_workingDirectory ); | |||||
| throw new TaskException( message ); | |||||
| if( !m_workingDirectory.exists() ) | |||||
| { | |||||
| final String message = REZ.getString( "execute.dir-noexist.error", m_workingDirectory ); | |||||
| throw new TaskException( message ); | |||||
| } | |||||
| 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. | |||||
| * Creates an output handler to use for the process' stdout and stderr. | |||||
| */ | */ | ||||
| private ExecOutputHandler buildOutputHandler( final TaskContext context ) | private ExecOutputHandler buildOutputHandler( final TaskContext context ) | ||||
| { | { | ||||
| @@ -199,8 +246,7 @@ public class Execute | |||||
| private void checkReturnCode( final int returnCode ) | private void checkReturnCode( final int returnCode ) | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| if( null != m_returnCode && | |||||
| returnCode != m_returnCode.intValue() ) | |||||
| if( ! m_ignoreReturnCode && returnCode != m_returnCode ) | |||||
| { | { | ||||
| final String message = REZ.getString( "execute.bad-resultcode.error", | final String message = REZ.getString( "execute.bad-resultcode.error", | ||||
| m_command.getExecutable(), | m_command.getExecutable(), | ||||
| @@ -213,11 +259,14 @@ public class Execute | |||||
| * Utility method to create an ExecMetaData object | * Utility method to create an ExecMetaData object | ||||
| * to pass to the ExecManager service. | * to pass to the ExecManager service. | ||||
| */ | */ | ||||
| private ExecMetaData buildExecMetaData( final ExecManager execManager ) | |||||
| private ExecMetaData buildExecMetaData( final TaskContext context, | |||||
| final ExecManager execManager ) | |||||
| throws ExecException | throws ExecException | ||||
| { | { | ||||
| // Build the command line | |||||
| final String[] command = m_command.getCommandline(); | final String[] command = m_command.getCommandline(); | ||||
| // Build the environment | |||||
| final Properties newEnvironment = new Properties(); | final Properties newEnvironment = new Properties(); | ||||
| if( !m_newEnvironment ) | if( !m_newEnvironment ) | ||||
| { | { | ||||
| @@ -225,8 +274,15 @@ public class Execute | |||||
| } | } | ||||
| newEnvironment.putAll( m_environment ); | newEnvironment.putAll( m_environment ); | ||||
| // Determine the working directory | |||||
| File workingDir = m_workingDirectory; | |||||
| if( workingDir == null ) | |||||
| { | |||||
| workingDir = context.getBaseDirectory(); | |||||
| } | |||||
| return new ExecMetaData( command, | return new ExecMetaData( command, | ||||
| newEnvironment, | newEnvironment, | ||||
| m_workingDirectory ); | |||||
| workingDir ); | |||||
| } | } | ||||
| } | } | ||||
| @@ -33,7 +33,9 @@ public class LoggingExecOutputHandler | |||||
| */ | */ | ||||
| public void stdout( final String line ) | public void stdout( final String line ) | ||||
| { | { | ||||
| m_context.info( line ); | |||||
| // TODO - should be using info(), but currently that is only used | |||||
| // when ant is run in verbose mode | |||||
| m_context.warn( line ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -0,0 +1,167 @@ | |||||
| /* | |||||
| * 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.frontends; | |||||
| import org.apache.avalon.framework.logger.Logger; | |||||
| /** | |||||
| * A partial logger implementation. | |||||
| * | |||||
| * @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
| * @version $Revision$ $Date$ | |||||
| */ | |||||
| public abstract class AbstractLogger | |||||
| implements Logger | |||||
| { | |||||
| public final static int LEVEL_DEBUG = 0; | |||||
| public final static int LEVEL_INFO = 1; | |||||
| public final static int LEVEL_WARN = 2; | |||||
| public final static int LEVEL_ERROR = 3; | |||||
| public final static int LEVEL_FATAL = 4; | |||||
| /** | |||||
| * Log a debug message. | |||||
| * | |||||
| * @param message the message | |||||
| */ | |||||
| public void debug( final String message ) | |||||
| { | |||||
| if( isDebugEnabled() ) | |||||
| { | |||||
| output( message, null ); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Log a debug message. | |||||
| * | |||||
| * @param message the message | |||||
| * @param throwable the throwable | |||||
| */ | |||||
| public void debug( final String message, final Throwable throwable ) | |||||
| { | |||||
| if( isDebugEnabled() ) | |||||
| { | |||||
| output( message, throwable ); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Log a info message. | |||||
| * | |||||
| * @param message the message | |||||
| */ | |||||
| public void info( final String message ) | |||||
| { | |||||
| if( isInfoEnabled() ) | |||||
| { | |||||
| output( message, null ); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Log a info message. | |||||
| * | |||||
| * @param message the message | |||||
| * @param throwable the throwable | |||||
| */ | |||||
| public void info( final String message, final Throwable throwable ) | |||||
| { | |||||
| if( isInfoEnabled() ) | |||||
| { | |||||
| output( message, throwable ); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Log a warn message. | |||||
| * | |||||
| * @param message the message | |||||
| */ | |||||
| public void warn( final String message ) | |||||
| { | |||||
| if( isWarnEnabled() ) | |||||
| { | |||||
| output( message, null ); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Log a warn message. | |||||
| * | |||||
| * @param message the message | |||||
| * @param throwable the throwable | |||||
| */ | |||||
| public void warn( final String message, final Throwable throwable ) | |||||
| { | |||||
| if( isWarnEnabled() ) | |||||
| { | |||||
| output( message, throwable ); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Log a error message. | |||||
| * | |||||
| * @param message the message | |||||
| */ | |||||
| public void error( final String message ) | |||||
| { | |||||
| if( isErrorEnabled() ) | |||||
| { | |||||
| output( message, null ); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Log a error message. | |||||
| * | |||||
| * @param message the message | |||||
| * @param throwable the throwable | |||||
| */ | |||||
| public void error( final String message, final Throwable throwable ) | |||||
| { | |||||
| if( isErrorEnabled() ) | |||||
| { | |||||
| output( message, throwable ); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Log a fatalError message. | |||||
| * | |||||
| * @param message the message | |||||
| */ | |||||
| public void fatalError( final String message ) | |||||
| { | |||||
| if( isFatalErrorEnabled() ) | |||||
| { | |||||
| output( message, null ); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Log a fatalError message. | |||||
| * | |||||
| * @param message the message | |||||
| * @param throwable the throwable | |||||
| */ | |||||
| public void fatalError( final String message, final Throwable throwable ) | |||||
| { | |||||
| if( isFatalErrorEnabled() ) | |||||
| { | |||||
| output( message, throwable ); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Utility method to output messages. | |||||
| */ | |||||
| protected abstract void output( final String message, | |||||
| final Throwable throwable ); | |||||
| } | |||||
| @@ -17,14 +17,9 @@ import org.apache.avalon.framework.logger.Logger; | |||||
| * @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
| */ | */ | ||||
| public class BasicLogger | public class BasicLogger | ||||
| extends AbstractLogger | |||||
| implements Logger | implements Logger | ||||
| { | { | ||||
| public final static int LEVEL_DEBUG = 0; | |||||
| public final static int LEVEL_INFO = 1; | |||||
| public final static int LEVEL_WARN = 2; | |||||
| public final static int LEVEL_ERROR = 3; | |||||
| public final static int LEVEL_FATAL = 4; | |||||
| /** | /** | ||||
| * The string prefixed to all log messages. | * The string prefixed to all log messages. | ||||
| */ | */ | ||||
| @@ -45,33 +40,6 @@ public class BasicLogger | |||||
| m_logLevel = logLevel; | m_logLevel = logLevel; | ||||
| } | } | ||||
| /** | |||||
| * Log a debug message. | |||||
| * | |||||
| * @param message the message | |||||
| */ | |||||
| public void debug( final String message ) | |||||
| { | |||||
| if( isDebugEnabled() ) | |||||
| { | |||||
| output( message, null ); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Log a debug message. | |||||
| * | |||||
| * @param message the message | |||||
| * @param throwable the throwable | |||||
| */ | |||||
| public void debug( final String message, final Throwable throwable ) | |||||
| { | |||||
| if( isDebugEnabled() ) | |||||
| { | |||||
| output( message, throwable ); | |||||
| } | |||||
| } | |||||
| /** | /** | ||||
| * Determine if messages of priority "debug" will be logged. | * Determine if messages of priority "debug" will be logged. | ||||
| * | * | ||||
| @@ -82,33 +50,6 @@ public class BasicLogger | |||||
| return m_logLevel <= LEVEL_DEBUG; | return m_logLevel <= LEVEL_DEBUG; | ||||
| } | } | ||||
| /** | |||||
| * Log a info message. | |||||
| * | |||||
| * @param message the message | |||||
| */ | |||||
| public void info( final String message ) | |||||
| { | |||||
| if( isInfoEnabled() ) | |||||
| { | |||||
| output( message, null ); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Log a info message. | |||||
| * | |||||
| * @param message the message | |||||
| * @param throwable the throwable | |||||
| */ | |||||
| public void info( final String message, final Throwable throwable ) | |||||
| { | |||||
| if( isInfoEnabled() ) | |||||
| { | |||||
| output( message, throwable ); | |||||
| } | |||||
| } | |||||
| /** | /** | ||||
| * Determine if messages of priority "info" will be logged. | * Determine if messages of priority "info" will be logged. | ||||
| * | * | ||||
| @@ -119,33 +60,6 @@ public class BasicLogger | |||||
| return m_logLevel <= LEVEL_INFO; | return m_logLevel <= LEVEL_INFO; | ||||
| } | } | ||||
| /** | |||||
| * Log a warn message. | |||||
| * | |||||
| * @param message the message | |||||
| */ | |||||
| public void warn( final String message ) | |||||
| { | |||||
| if( isWarnEnabled() ) | |||||
| { | |||||
| output( message, null ); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Log a warn message. | |||||
| * | |||||
| * @param message the message | |||||
| * @param throwable the throwable | |||||
| */ | |||||
| public void warn( final String message, final Throwable throwable ) | |||||
| { | |||||
| if( isWarnEnabled() ) | |||||
| { | |||||
| output( message, throwable ); | |||||
| } | |||||
| } | |||||
| /** | /** | ||||
| * Determine if messages of priority "warn" will be logged. | * Determine if messages of priority "warn" will be logged. | ||||
| * | * | ||||
| @@ -156,33 +70,6 @@ public class BasicLogger | |||||
| return m_logLevel <= LEVEL_WARN; | return m_logLevel <= LEVEL_WARN; | ||||
| } | } | ||||
| /** | |||||
| * Log a error message. | |||||
| * | |||||
| * @param message the message | |||||
| */ | |||||
| public void error( final String message ) | |||||
| { | |||||
| if( isErrorEnabled() ) | |||||
| { | |||||
| output( message, null ); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Log a error message. | |||||
| * | |||||
| * @param message the message | |||||
| * @param throwable the throwable | |||||
| */ | |||||
| public void error( final String message, final Throwable throwable ) | |||||
| { | |||||
| if( isErrorEnabled() ) | |||||
| { | |||||
| output( message, throwable ); | |||||
| } | |||||
| } | |||||
| /** | /** | ||||
| * Determine if messages of priority "error" will be logged. | * Determine if messages of priority "error" will be logged. | ||||
| * | * | ||||
| @@ -193,33 +80,6 @@ public class BasicLogger | |||||
| return m_logLevel <= LEVEL_ERROR; | return m_logLevel <= LEVEL_ERROR; | ||||
| } | } | ||||
| /** | |||||
| * Log a fatalError message. | |||||
| * | |||||
| * @param message the message | |||||
| */ | |||||
| public void fatalError( final String message ) | |||||
| { | |||||
| if( isFatalErrorEnabled() ) | |||||
| { | |||||
| output( message, null ); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Log a fatalError message. | |||||
| * | |||||
| * @param message the message | |||||
| * @param throwable the throwable | |||||
| */ | |||||
| public void fatalError( final String message, final Throwable throwable ) | |||||
| { | |||||
| if( isFatalErrorEnabled() ) | |||||
| { | |||||
| output( message, throwable ); | |||||
| } | |||||
| } | |||||
| /** | /** | ||||
| * Determine if messages of priority "fatalError" will be logged. | * Determine if messages of priority "fatalError" will be logged. | ||||
| * | * | ||||
| @@ -10,14 +10,10 @@ package org.apache.tools.todo.taskdefs; | |||||
| import java.io.BufferedReader; | import java.io.BufferedReader; | ||||
| import java.io.File; | import java.io.File; | ||||
| import java.io.FileReader; | import java.io.FileReader; | ||||
| import java.io.IOException; | |||||
| import java.net.URL; | import java.net.URL; | ||||
| import org.apache.aut.nativelib.ExecManager; | |||||
| import org.apache.myrmidon.api.AbstractTask; | import org.apache.myrmidon.api.AbstractTask; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.api.TaskContext; | |||||
| import org.apache.myrmidon.framework.Execute; | import org.apache.myrmidon.framework.Execute; | ||||
| import org.apache.tools.todo.taskdefs.ExecuteJava; | |||||
| import org.apache.tools.todo.types.Argument; | import org.apache.tools.todo.types.Argument; | ||||
| import org.apache.tools.todo.types.Commandline; | import org.apache.tools.todo.types.Commandline; | ||||
| import org.apache.tools.todo.types.CommandlineJava; | import org.apache.tools.todo.types.CommandlineJava; | ||||
| @@ -131,12 +127,7 @@ public class ANTLR extends AbstractTask | |||||
| if( fork ) | if( fork ) | ||||
| { | { | ||||
| getContext().debug( "Forking " + commandline.toString() ); | |||||
| int err = run( commandline ); | |||||
| if( err == 1 ) | |||||
| { | |||||
| throw new TaskException( "ANTLR returned: " + err ); | |||||
| } | |||||
| run( commandline ); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| @@ -222,26 +213,15 @@ public class ANTLR extends AbstractTask | |||||
| * execute in a forked VM | * execute in a forked VM | ||||
| * | * | ||||
| * @param command Description of Parameter | * @param command Description of Parameter | ||||
| * @return Description of the Returned Value | |||||
| * @exception org.apache.myrmidon.api.TaskException Description of Exception | * @exception org.apache.myrmidon.api.TaskException Description of Exception | ||||
| */ | */ | ||||
| private int run( final Commandline command ) | |||||
| private void run( final Commandline command ) | |||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| final Execute exe = new Execute(); | final Execute exe = new Execute(); | ||||
| if( workingdir != null ) | |||||
| { | |||||
| exe.setWorkingDirectory( workingdir ); | |||||
| } | |||||
| exe.setWorkingDirectory( workingdir ); | |||||
| exe.setCommandline( command ); | exe.setCommandline( command ); | ||||
| try | |||||
| { | |||||
| return exe.execute( getContext() ); | |||||
| } | |||||
| catch( IOException e ) | |||||
| { | |||||
| throw new TaskException( "Error", e ); | |||||
| } | |||||
| exe.execute( getContext() ); | |||||
| } | } | ||||
| private void validateAttributes() | private void validateAttributes() | ||||
| @@ -784,18 +784,7 @@ public class IContract extends MatchingTask | |||||
| } | } | ||||
| // do it! | // do it! | ||||
| int result = iContract.executeJava(); | |||||
| if( result != 0 ) | |||||
| { | |||||
| if( iContractMissing ) | |||||
| { | |||||
| getContext().info( "iContract can't be found on your classpath. Your classpath is:" ); | |||||
| getContext().info( classpath.toString() ); | |||||
| getContext().info( "If you don't have the iContract jar, go get it at http://www.reliable-systems.com/tools/" ); | |||||
| } | |||||
| throw new TaskException( "iContract instrumentation failed. Code=" + result ); | |||||
| } | |||||
| iContract.executeJava(); | |||||
| } | } | ||||
| else | else | ||||
| {// not dirty | {// not dirty | ||||
| @@ -120,21 +120,15 @@ public class Java | |||||
| public void execute() | public void execute() | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| final int err = executeJava(); | |||||
| if( 0 != err ) | |||||
| { | |||||
| throw new TaskException( "Java returned: " + err ); | |||||
| } | |||||
| executeJava(); | |||||
| } | } | ||||
| /** | /** | ||||
| * Do the execution and return a return code. | |||||
| * Do the execution. | |||||
| * | * | ||||
| * @return the return code from the execute java class if it was executed in | |||||
| * a separate VM (fork = "yes"). | |||||
| * @exception org.apache.myrmidon.api.TaskException Description of Exception | * @exception org.apache.myrmidon.api.TaskException Description of Exception | ||||
| */ | */ | ||||
| public int executeJava() | |||||
| public void executeJava() | |||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| final String classname = m_cmdl.getClassname(); | final String classname = m_cmdl.getClassname(); | ||||
| @@ -156,8 +150,7 @@ public class Java | |||||
| if( m_fork ) | if( m_fork ) | ||||
| { | { | ||||
| getContext().debug( "Forking " + m_cmdl.toString() ); | getContext().debug( "Forking " + m_cmdl.toString() ); | ||||
| return run( new Commandline( m_cmdl.getCommandline() ) ); | |||||
| run( new Commandline( m_cmdl.getCommandline() ) ); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| @@ -172,7 +165,6 @@ public class Java | |||||
| getContext().debug( "Running in same VM " + m_cmdl.getJavaCommand().toString() ); | getContext().debug( "Running in same VM " + m_cmdl.getJavaCommand().toString() ); | ||||
| run( m_cmdl ); | run( m_cmdl ); | ||||
| return 0; | |||||
| } | } | ||||
| } | } | ||||
| @@ -212,23 +204,12 @@ public class Java | |||||
| /** | /** | ||||
| * Executes the given classname with the given arguments in a separate VM. | * Executes the given classname with the given arguments in a separate VM. | ||||
| */ | */ | ||||
| private int run( final Commandline command ) | |||||
| private void run( final Commandline command ) | |||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| final Execute exe = new Execute(); | final Execute exe = new Execute(); | ||||
| if( m_dir == null ) | |||||
| { | |||||
| m_dir = getBaseDirectory(); | |||||
| } | |||||
| else if( !m_dir.exists() || !m_dir.isDirectory() ) | |||||
| { | |||||
| final String message = m_dir.getAbsolutePath() + " is not a valid directory"; | |||||
| throw new TaskException( message ); | |||||
| } | |||||
| exe.setWorkingDirectory( m_dir ); | exe.setWorkingDirectory( m_dir ); | ||||
| exe.setCommandline( command ); | exe.setCommandline( command ); | ||||
| return exe.execute( getContext() ); | |||||
| exe.execute( getContext() ); | |||||
| } | } | ||||
| } | } | ||||
| @@ -91,14 +91,8 @@ public class Rpm | |||||
| { | { | ||||
| final Commandline cmd = createCommand(); | final Commandline cmd = createCommand(); | ||||
| final Execute exe = new Execute(); | final Execute exe = new Execute(); | ||||
| if( m_topDir == null ) | |||||
| { | |||||
| m_topDir = getBaseDirectory(); | |||||
| } | |||||
| exe.setWorkingDirectory( m_topDir ); | exe.setWorkingDirectory( m_topDir ); | ||||
| exe.setCommandline( cmd ); | exe.setCommandline( cmd ); | ||||
| exe.setReturnCode( 0 ); | |||||
| final String message = "Building the RPM based on the " + m_specFile + " file"; | final String message = "Building the RPM based on the " + m_specFile + " file"; | ||||
| getContext().info( message ); | getContext().info( message ); | ||||
| @@ -114,9 +114,7 @@ public abstract class Continuus | |||||
| { | { | ||||
| exe.setExecOutputHandler( handler ); | exe.setExecOutputHandler( handler ); | ||||
| } | } | ||||
| exe.setWorkingDirectory( getBaseDirectory() ); | |||||
| exe.setCommandline( cmd ); | exe.setCommandline( cmd ); | ||||
| exe.setReturnCode( 0 ); | |||||
| exe.execute( getContext() ); | exe.execute( getContext() ); | ||||
| } | } | ||||
| } | } | ||||
| @@ -106,9 +106,7 @@ public abstract class ClearCase extends AbstractTask | |||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| final Execute exe = new Execute(); | final Execute exe = new Execute(); | ||||
| exe.setWorkingDirectory( getBaseDirectory() ); | |||||
| exe.setCommandline( cmd ); | exe.setCommandline( cmd ); | ||||
| exe.setReturnCode( 0 ); | |||||
| exe.execute( getContext() ); | exe.execute( getContext() ); | ||||
| } | } | ||||
| @@ -11,7 +11,6 @@ import java.io.File; | |||||
| import java.io.FileWriter; | import java.io.FileWriter; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import java.io.PrintWriter; | import java.io.PrintWriter; | ||||
| import org.apache.aut.nativelib.ExecManager; | |||||
| import org.apache.avalon.excalibur.io.IOUtil; | import org.apache.avalon.excalibur.io.IOUtil; | ||||
| import org.apache.avalon.excalibur.util.StringUtil; | import org.apache.avalon.excalibur.util.StringUtil; | ||||
| import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
| @@ -54,7 +53,6 @@ public abstract class DefaultCompilerAdapter | |||||
| protected boolean m_includeJavaRuntime; | protected boolean m_includeJavaRuntime; | ||||
| protected String m_memoryInitialSize; | protected String m_memoryInitialSize; | ||||
| protected String m_memoryMaximumSize; | protected String m_memoryMaximumSize; | ||||
| protected File m_baseDir; | |||||
| /* | /* | ||||
| * jdg - TODO - all these attributes are currently protected, but they | * jdg - TODO - all these attributes are currently protected, but they | ||||
| @@ -91,7 +89,6 @@ public abstract class DefaultCompilerAdapter | |||||
| m_extdirs = attributes.getExtdirs(); | m_extdirs = attributes.getExtdirs(); | ||||
| m_compileList = attributes.getFileList(); | m_compileList = attributes.getFileList(); | ||||
| m_compileClasspath = attributes.getClasspath(); | m_compileClasspath = attributes.getClasspath(); | ||||
| m_baseDir = attributes.getBaseDirectory(); | |||||
| m_memoryInitialSize = attributes.getMemoryInitialSize(); | m_memoryInitialSize = attributes.getMemoryInitialSize(); | ||||
| m_memoryMaximumSize = attributes.getMemoryMaximumSize(); | m_memoryMaximumSize = attributes.getMemoryMaximumSize(); | ||||
| } | } | ||||
| @@ -371,7 +368,7 @@ public abstract class DefaultCompilerAdapter | |||||
| } | } | ||||
| final Execute exe = new Execute(); | final Execute exe = new Execute(); | ||||
| exe.setWorkingDirectory( m_baseDir ); | |||||
| exe.setIgnoreReturnCode( true ); | |||||
| final String[] commandline = commandArray; | final String[] commandline = commandArray; | ||||
| exe.setCommandline( new Commandline( commandline ) ); | exe.setCommandline( new Commandline( commandline ) ); | ||||
| return exe.execute( getTaskContext() ); | return exe.execute( getTaskContext() ); | ||||
| @@ -184,7 +184,6 @@ public class JJTree | |||||
| final Execute exe = new Execute(); | final Execute exe = new Execute(); | ||||
| getContext().debug( cmdl.toString() ); | getContext().debug( cmdl.toString() ); | ||||
| exe.setCommandline( new Commandline( cmdl.getCommandline() ) ); | exe.setCommandline( new Commandline( cmdl.getCommandline() ) ); | ||||
| exe.setReturnCode( 0 ); | |||||
| exe.execute( getContext() ); | exe.execute( getContext() ); | ||||
| } | } | ||||
| } | } | ||||
| @@ -244,7 +244,6 @@ public class JavaCC | |||||
| final Execute exe = new Execute(); | final Execute exe = new Execute(); | ||||
| final String[] commandline = cmdline.getCommandline(); | final String[] commandline = cmdline.getCommandline(); | ||||
| exe.setCommandline( new Commandline( commandline ) ); | exe.setCommandline( new Commandline( commandline ) ); | ||||
| exe.setReturnCode( 0 ); | |||||
| exe.execute( getContext() ); | exe.execute( getContext() ); | ||||
| } | } | ||||
| @@ -823,15 +823,7 @@ public class Javadoc | |||||
| final Execute exe = new Execute(); | final Execute exe = new Execute(); | ||||
| exe.setExecOutputHandler( this ); | exe.setExecOutputHandler( this ); | ||||
| /* | |||||
| * No reason to change the working directory as all filenames and | |||||
| * path components have been resolved already. | |||||
| * | |||||
| * Avoid problems with command line length in some environments. | |||||
| */ | |||||
| exe.setWorkingDirectory( null ); | |||||
| exe.setCommandline( cmd ); | exe.setCommandline( cmd ); | ||||
| exe.setReturnCode( 0 ); | |||||
| try | try | ||||
| { | { | ||||
| exe.execute( getContext() ); | exe.execute( getContext() ); | ||||
| @@ -11,10 +11,8 @@ import java.io.File; | |||||
| import java.io.FileWriter; | import java.io.FileWriter; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import java.io.PrintWriter; | import java.io.PrintWriter; | ||||
| import org.apache.aut.nativelib.ExecManager; | |||||
| import org.apache.myrmidon.api.AbstractTask; | import org.apache.myrmidon.api.AbstractTask; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.api.TaskContext; | |||||
| import org.apache.myrmidon.framework.Execute; | import org.apache.myrmidon.framework.Execute; | ||||
| import org.apache.tools.todo.types.Commandline; | import org.apache.tools.todo.types.Commandline; | ||||
| import org.apache.tools.todo.types.CommandlineJava; | import org.apache.tools.todo.types.CommandlineJava; | ||||
| @@ -36,16 +34,6 @@ import org.apache.tools.todo.util.FileUtils; | |||||
| public class JDependTask | public class JDependTask | ||||
| extends AbstractTask | extends AbstractTask | ||||
| { | { | ||||
| /** | |||||
| * No problems with this test. | |||||
| */ | |||||
| private final static int SUCCESS = 0; | |||||
| /** | |||||
| * An error occured. | |||||
| */ | |||||
| private final static int ERRORS = 1; | |||||
| private boolean m_fork; | private boolean m_fork; | ||||
| private String m_jvm; | private String m_jvm; | ||||
| private String m_format = "text"; | private String m_format = "text"; | ||||
| @@ -84,7 +72,7 @@ public class JDependTask | |||||
| /** | /** | ||||
| * Tells whether a JVM should be forked for the task. Default: false. | * Tells whether a JVM should be forked for the task. Default: false. | ||||
| * | * | ||||
| * @param value <tt>true</tt> if a JVM should be forked, otherwise <tt>false | |||||
| * @param fork <tt>true</tt> if a JVM should be forked, otherwise <tt>false | |||||
| * <tt> | * <tt> | ||||
| */ | */ | ||||
| public void setFork( final boolean fork ) | public void setFork( final boolean fork ) | ||||
| @@ -101,7 +89,7 @@ public class JDependTask | |||||
| * Set a new VM to execute the task. Default is <tt>java</tt> . Ignored if | * Set a new VM to execute the task. Default is <tt>java</tt> . Ignored if | ||||
| * no JVM is forked. | * no JVM is forked. | ||||
| * | * | ||||
| * @param value the new VM to use instead of <tt>java</tt> | |||||
| * @param jvm the new VM to use instead of <tt>java</tt> | |||||
| * @see #setFork(boolean) | * @see #setFork(boolean) | ||||
| */ | */ | ||||
| public void setJvm( final String jvm ) | public void setJvm( final String jvm ) | ||||
| @@ -179,22 +167,13 @@ public class JDependTask | |||||
| } | } | ||||
| // execute the test and get the return code | // execute the test and get the return code | ||||
| int exitValue = JDependTask.ERRORS; | |||||
| if( !m_fork ) | if( !m_fork ) | ||||
| { | { | ||||
| exitValue = executeInVM( commandline ); | |||||
| executeInVM( commandline ); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| exitValue = executeAsForked( commandline ); | |||||
| } | |||||
| // if there is an error/failure and that it should halt, stop everything otherwise | |||||
| // just log a statement | |||||
| final boolean errorOccurred = exitValue == JDependTask.ERRORS; | |||||
| if( errorOccurred ) | |||||
| { | |||||
| throw new TaskException( "JDepend failed" ); | |||||
| executeAsForked( commandline ); | |||||
| } | } | ||||
| } | } | ||||
| @@ -205,7 +184,7 @@ public class JDependTask | |||||
| * killedProcess()</tt> method of the watchdog class. | * killedProcess()</tt> method of the watchdog class. | ||||
| */ | */ | ||||
| // JL: comment extracted from JUnitTask (and slightly modified) | // JL: comment extracted from JUnitTask (and slightly modified) | ||||
| private int executeAsForked( final CommandlineJava commandline ) | |||||
| private void executeAsForked( final CommandlineJava commandline ) | |||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| // if not set, auto-create the ClassPath from the project | // if not set, auto-create the ClassPath from the project | ||||
| @@ -245,17 +224,13 @@ public class JDependTask | |||||
| final String[] commandline1 = commandline.getCommandline(); | final String[] commandline1 = commandline.getCommandline(); | ||||
| exe.setCommandline( new Commandline( commandline1 ) ); | exe.setCommandline( new Commandline( commandline1 ) ); | ||||
| if( m_dir != null ) | |||||
| { | |||||
| exe.setWorkingDirectory( m_dir ); | |||||
| } | |||||
| exe.setWorkingDirectory( m_dir ); | |||||
| if( m_outputFile != null ) | if( m_outputFile != null ) | ||||
| { | { | ||||
| getContext().info( "Output to be stored in " + m_outputFile.getPath() ); | getContext().info( "Output to be stored in " + m_outputFile.getPath() ); | ||||
| } | } | ||||
| getContext().debug( "Executing: " + commandline.toString() ); | |||||
| return exe.execute( getContext() ); | |||||
| exe.execute( getContext() ); | |||||
| } | } | ||||
| @@ -268,10 +243,9 @@ public class JDependTask | |||||
| * Execute inside VM. | * Execute inside VM. | ||||
| * | * | ||||
| * @param commandline Description of Parameter | * @param commandline Description of Parameter | ||||
| * @return Description of the Returned Value | |||||
| * @exception TaskException Description of Exception | * @exception TaskException Description of Exception | ||||
| */ | */ | ||||
| public int executeInVM( final CommandlineJava commandline ) | |||||
| private void executeInVM( final CommandlineJava commandline ) | |||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| jdepend.textui.JDepend jdepend; | jdepend.textui.JDepend jdepend; | ||||
| @@ -326,6 +300,5 @@ public class JDependTask | |||||
| } | } | ||||
| } | } | ||||
| jdepend.analyze(); | jdepend.analyze(); | ||||
| return SUCCESS; | |||||
| } | } | ||||
| } | } | ||||
| @@ -231,10 +231,7 @@ public class WLJspc extends MatchingTask | |||||
| //helperTask.clearArgs(); | //helperTask.clearArgs(); | ||||
| helperTask.addArg( new Argument( arg ) ); | helperTask.addArg( new Argument( arg ) ); | ||||
| helperTask.addClasspath( compileClasspath ); | helperTask.addClasspath( compileClasspath ); | ||||
| if( helperTask.executeJava() != 0 ) | |||||
| { | |||||
| getContext().warn( files[ i ] + " failed to compile" ); | |||||
| } | |||||
| helperTask.executeJava(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -16,7 +16,7 @@ import java.net.URL; | |||||
| import javax.xml.parsers.DocumentBuilder; | import javax.xml.parsers.DocumentBuilder; | ||||
| import javax.xml.parsers.DocumentBuilderFactory; | import javax.xml.parsers.DocumentBuilderFactory; | ||||
| import org.apache.avalon.excalibur.io.FileUtil; | import org.apache.avalon.excalibur.io.FileUtil; | ||||
| import org.apache.myrmidon.api.AbstractTask; | |||||
| import org.apache.myrmidon.api.TaskContext; | |||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.tools.todo.types.EnumeratedAttribute; | import org.apache.tools.todo.types.EnumeratedAttribute; | ||||
| import org.w3c.dom.Document; | import org.w3c.dom.Document; | ||||
| @@ -57,7 +57,7 @@ public class AggregateTransformer | |||||
| */ | */ | ||||
| private File m_styleDir; | private File m_styleDir; | ||||
| private AbstractTask m_task; | |||||
| private TaskContext m_context; | |||||
| /** | /** | ||||
| * the destination directory, this is the root from where html should be | * the destination directory, this is the root from where html should be | ||||
| @@ -65,9 +65,9 @@ public class AggregateTransformer | |||||
| */ | */ | ||||
| private File m_toDir; | private File m_toDir; | ||||
| public AggregateTransformer( AbstractTask task ) | |||||
| public AggregateTransformer( TaskContext context ) | |||||
| { | { | ||||
| m_task = task; | |||||
| m_context = context; | |||||
| } | } | ||||
| public void setFormat( Format format ) | public void setFormat( Format format ) | ||||
| @@ -196,11 +196,11 @@ public class AggregateTransformer | |||||
| // set the destination directory relative from the project if needed. | // set the destination directory relative from the project if needed. | ||||
| if( m_toDir == null ) | if( m_toDir == null ) | ||||
| { | { | ||||
| m_toDir = FileUtil.resolveFile( m_task.getBaseDirectory(), "." ); | |||||
| m_toDir = FileUtil.resolveFile( m_context.getBaseDirectory(), "." ); | |||||
| } | } | ||||
| else if( !m_toDir.isAbsolute() ) | else if( !m_toDir.isAbsolute() ) | ||||
| { | { | ||||
| m_toDir = FileUtil.resolveFile( m_task.getBaseDirectory(), m_toDir.getPath() ); | |||||
| m_toDir = FileUtil.resolveFile( m_context.getBaseDirectory(), m_toDir.getPath() ); | |||||
| } | } | ||||
| } | } | ||||
| @@ -633,13 +633,10 @@ public class JUnitTask extends AbstractTask | |||||
| } | } | ||||
| final Execute exe = new Execute(); | final Execute exe = new Execute(); | ||||
| exe.setIgnoreReturnCode( true ); | |||||
| exe.setCommandline( new Commandline( cmd.getCommandline() ) ); | exe.setCommandline( new Commandline( cmd.getCommandline() ) ); | ||||
| if( dir != null ) | |||||
| { | |||||
| exe.setWorkingDirectory( dir ); | |||||
| } | |||||
| exe.setWorkingDirectory( dir ); | |||||
| getContext().debug( "Executing: " + cmd.toString() ); | |||||
| try | try | ||||
| { | { | ||||
| return exe.execute( getContext() ); | return exe.execute( getContext() ); | ||||
| @@ -133,7 +133,7 @@ public class XMLResultAggregator | |||||
| public AggregateTransformer createReport() | public AggregateTransformer createReport() | ||||
| { | { | ||||
| AggregateTransformer transformer = new AggregateTransformer( this ); | |||||
| AggregateTransformer transformer = new AggregateTransformer( getContext() ); | |||||
| transformers.add( transformer ); | transformers.add( transformer ); | ||||
| return transformer; | return transformer; | ||||
| } | } | ||||
| @@ -281,7 +281,6 @@ public abstract class AbstractMetamataTask | |||||
| getContext().debug( m_cmdl.toString() ); | getContext().debug( m_cmdl.toString() ); | ||||
| final String[] commandline = m_cmdl.getCommandline(); | final String[] commandline = m_cmdl.getCommandline(); | ||||
| exe.setCommandline( new Commandline( commandline ) ); | exe.setCommandline( new Commandline( commandline ) ); | ||||
| exe.setReturnCode( 0 ); | |||||
| exe.execute( getContext() ); | exe.execute( getContext() ); | ||||
| } | } | ||||
| @@ -292,7 +292,6 @@ public class MParse | |||||
| getContext().debug( m_cmdl.toString() ); | getContext().debug( m_cmdl.toString() ); | ||||
| final String[] commandline = m_cmdl.getCommandline(); | final String[] commandline = m_cmdl.getCommandline(); | ||||
| exe.setCommandline( new Commandline( commandline ) ); | exe.setCommandline( new Commandline( commandline ) ); | ||||
| exe.setReturnCode( 0 ); | |||||
| exe.execute( getContext() ); | exe.execute( getContext() ); | ||||
| } | } | ||||
| @@ -19,12 +19,10 @@ import java.text.MessageFormat; | |||||
| import java.text.ParseException; | import java.text.ParseException; | ||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.Iterator; | import java.util.Iterator; | ||||
| import org.apache.aut.nativelib.ExecManager; | |||||
| import org.apache.aut.nativelib.ExecOutputHandler; | import org.apache.aut.nativelib.ExecOutputHandler; | ||||
| import org.apache.avalon.excalibur.io.IOUtil; | import org.apache.avalon.excalibur.io.IOUtil; | ||||
| import org.apache.myrmidon.api.AbstractTask; | import org.apache.myrmidon.api.AbstractTask; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.api.TaskContext; | |||||
| import org.apache.myrmidon.framework.Execute; | import org.apache.myrmidon.framework.Execute; | ||||
| import org.apache.tools.todo.types.Commandline; | import org.apache.tools.todo.types.Commandline; | ||||
| @@ -181,8 +179,6 @@ public class Pvcs | |||||
| public void execute() | public void execute() | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| int result = 0; | |||||
| validate(); | validate(); | ||||
| final File filelist = getFileList(); | final File filelist = getFileList(); | ||||
| @@ -192,10 +188,9 @@ public class Pvcs | |||||
| try | try | ||||
| { | { | ||||
| final Execute exe = new Execute(); | final Execute exe = new Execute(); | ||||
| exe.setWorkingDirectory( getBaseDirectory() ); | |||||
| exe.setIgnoreReturnCode( m_ignoreReturnCode ); | |||||
| exe.setCommandline( cmd ); | exe.setCommandline( cmd ); | ||||
| result = exe.execute( getContext() ); | |||||
| checkResultCode( result, cmd ); | |||||
| exe.execute( getContext() ); | |||||
| } | } | ||||
| finally | finally | ||||
| { | { | ||||
| @@ -238,17 +233,6 @@ public class Pvcs | |||||
| return cmd; | return cmd; | ||||
| } | } | ||||
| private void checkResultCode( final int result, final Commandline cmd ) | |||||
| throws TaskException | |||||
| { | |||||
| if( result != 0 && !m_ignoreReturnCode ) | |||||
| { | |||||
| final String message = "Failed executing: " + cmd.toString() + | |||||
| ". Return code was " + result; | |||||
| throw new TaskException( message ); | |||||
| } | |||||
| } | |||||
| private File getFileList() | private File getFileList() | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| @@ -267,12 +251,11 @@ public class Pvcs | |||||
| final File fileList = File.createTempFile( "pvcs_ant_", ".log" ); | final File fileList = File.createTempFile( "pvcs_ant_", ".log" ); | ||||
| final Execute exe = new Execute(); | final Execute exe = new Execute(); | ||||
| exe.setIgnoreReturnCode( m_ignoreReturnCode ); | |||||
| exe.setExecOutputHandler( this ); | exe.setExecOutputHandler( this ); | ||||
| m_output = new FileOutputStream( tmp ); | m_output = new FileOutputStream( tmp ); | ||||
| exe.setWorkingDirectory( getBaseDirectory() ); | |||||
| exe.setCommandline( cmd ); | exe.setCommandline( cmd ); | ||||
| final int result = exe.execute( getContext() ); | |||||
| checkResultCode( result, cmd ); | |||||
| exe.execute( getContext() ); | |||||
| if( !tmp.exists() ) | if( !tmp.exists() ) | ||||
| { | { | ||||
| @@ -118,7 +118,6 @@ public class CovMerge | |||||
| final Execute exe = new Execute(); | final Execute exe = new Execute(); | ||||
| exe.setCommandline( cmdl ); | exe.setCommandline( cmdl ); | ||||
| exe.setReturnCode( 0 ); | |||||
| // JProbe process always return 0 so we will not be | // JProbe process always return 0 so we will not be | ||||
| // able to check for failure ! :-( | // able to check for failure ! :-( | ||||
| @@ -251,7 +251,6 @@ public class CovReport | |||||
| // use the custom handler for stdin issues | // use the custom handler for stdin issues | ||||
| final Execute exe = new Execute(); | final Execute exe = new Execute(); | ||||
| exe.setCommandline( cmdl ); | exe.setCommandline( cmdl ); | ||||
| exe.setReturnCode( 0 ); | |||||
| exe.execute( getContext() ); | exe.execute( getContext() ); | ||||
| getContext().debug( "coveragePath: " + coveragePath ); | getContext().debug( "coveragePath: " + coveragePath ); | ||||
| getContext().debug( "format: " + format ); | getContext().debug( "format: " + format ); | ||||
| @@ -252,7 +252,6 @@ public class Coverage | |||||
| // use the custom handler for stdin issues | // use the custom handler for stdin issues | ||||
| final Execute exe = new Execute(); | final Execute exe = new Execute(); | ||||
| exe.setCommandline( cmdl ); | exe.setCommandline( cmdl ); | ||||
| exe.setReturnCode( 0 ); | |||||
| exe.execute( getContext() ); | exe.execute( getContext() ); | ||||
| } | } | ||||
| finally | finally | ||||
| @@ -213,9 +213,7 @@ public abstract class MSVSS | |||||
| exe.setEnvironment( env ); | exe.setEnvironment( env ); | ||||
| } | } | ||||
| exe.setWorkingDirectory( getBaseDirectory() ); | |||||
| exe.setCommandline( cmd ); | exe.setCommandline( cmd ); | ||||
| exe.setReturnCode( 0 ); | |||||
| exe.execute( getContext() ); | exe.execute( getContext() ); | ||||
| } | } | ||||
| } | } | ||||