Browse Source

More refactoring of framework.Execute:

* 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-ffa450edef68
master
adammurdoch 23 years ago
parent
commit
77333ba49f
35 changed files with 360 additions and 363 deletions
  1. +0
    -5
      proposal/myrmidon/src/java/org/apache/antlib/cvslib/Cvs.java
  2. +0
    -2
      proposal/myrmidon/src/java/org/apache/antlib/dotnet/CSharp.java
  3. +0
    -2
      proposal/myrmidon/src/java/org/apache/antlib/dotnet/Ilasm.java
  4. +0
    -7
      proposal/myrmidon/src/java/org/apache/antlib/nativelib/Exec.java
  5. +0
    -1
      proposal/myrmidon/src/java/org/apache/antlib/security/GenerateKey.java
  6. +12
    -4
      proposal/myrmidon/src/java/org/apache/myrmidon/api/AbstractTask.java
  7. +15
    -6
      proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/Deployment.java
  8. +3
    -2
      proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java
  9. +46
    -5
      proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/RoutingLogger.java
  10. +79
    -23
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/Execute.java
  11. +3
    -1
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/LoggingExecOutputHandler.java
  12. +167
    -0
      proposal/myrmidon/src/java/org/apache/myrmidon/frontends/AbstractLogger.java
  13. +1
    -141
      proposal/myrmidon/src/java/org/apache/myrmidon/frontends/BasicLogger.java
  14. +4
    -24
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ANTLR.java
  15. +1
    -12
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/IContract.java
  16. +6
    -25
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Java.java
  17. +0
    -6
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Rpm.java
  18. +0
    -2
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ccm/Continuus.java
  19. +0
    -2
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/clearcase/ClearCase.java
  20. +1
    -4
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/DefaultCompilerAdapter.java
  21. +0
    -1
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javacc/JJTree.java
  22. +0
    -1
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javacc/JavaCC.java
  23. +0
    -8
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javadoc/Javadoc.java
  24. +8
    -35
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jdepend/JDependTask.java
  25. +1
    -4
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jsp/WLJspc.java
  26. +6
    -6
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/AggregateTransformer.java
  27. +2
    -5
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/JUnitTask.java
  28. +1
    -1
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/XMLResultAggregator.java
  29. +0
    -1
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/AbstractMetamataTask.java
  30. +0
    -1
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/metamata/MParse.java
  31. +4
    -21
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/pvcs/Pvcs.java
  32. +0
    -1
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/CovMerge.java
  33. +0
    -1
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/CovReport.java
  34. +0
    -1
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/sitraka/Coverage.java
  35. +0
    -2
      proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSS.java

+ 0
- 5
proposal/myrmidon/src/java/org/apache/antlib/cvslib/Cvs.java View File

@@ -147,15 +147,10 @@ public class Cvs
final Properties env = buildEnvironment();

final Execute exe = new Execute();
if( m_dest == null )
{
m_dest = getBaseDirectory();
}
exe.setWorkingDirectory( m_dest );

exe.setCommandline( command );
exe.setEnvironment( env );
exe.setReturnCode( 0 );
exe.execute( getContext() );
}



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

@@ -504,8 +504,6 @@ public class CSharp
}

final Execute exe = new Execute();
exe.setReturnCode( 0 );

final Commandline cmd = exe.getCommandline();
cmd.setExecutable( EXE_NAME );



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

@@ -248,8 +248,6 @@ public class Ilasm
throws TaskException
{
final Execute exe = new Execute();
exe.setReturnCode( 0 );

final Commandline cmd = exe.getCommandline();
cmd.setExecutable( EXE_NAME );
addArgument( cmd, getDebugParameter() );


+ 0
- 7
proposal/myrmidon/src/java/org/apache/antlib/nativelib/Exec.java View File

@@ -105,15 +105,8 @@ public class Exec
return;
}

// default directory to the project's base directory
if( m_dir == null )
{
m_dir = getBaseDirectory();
}

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



+ 0
- 1
proposal/myrmidon/src/java/org/apache/antlib/security/GenerateKey.java View File

@@ -120,7 +120,6 @@ public class GenerateKey

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


+ 12
- 4
proposal/myrmidon/src/java/org/apache/myrmidon/api/AbstractTask.java View File

@@ -52,14 +52,22 @@ public abstract class AbstractTask
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();
}

///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
{
return getContext().getService( serviceClass );


+ 15
- 6
proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/Deployment.java View File

@@ -272,8 +272,11 @@ class Deployment

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();
for( int i = 0; i < definitions.length; i++ )
@@ -297,8 +300,11 @@ class Deployment
{
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
final TypeDefinition[] definitions = descriptor.getDefinitions();
@@ -324,8 +330,11 @@ class Deployment

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
final ServiceDefinition[] definitions = descriptor.getDefinitions();


+ 3
- 2
proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java View File

@@ -247,14 +247,15 @@ public class DefaultWorkspace

// Create a logger
final Logger logger =
new RoutingLogger( RoutingLogger.LEVEL_DEBUG, m_listenerSupport );
new RoutingLogger( getLogger(), m_listenerSupport );

// Create and configure the context
final DefaultTaskContext context =
new DefaultTaskContext( m_baseContext, serviceManager, logger );
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.


+ 46
- 5
proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/RoutingLogger.java View File

@@ -7,31 +7,72 @@
*/
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>
* @version $Revision$ $Date$
*/
final class RoutingLogger
extends BasicLogger
extends AbstractLogger
implements Logger
{
/**
* The endpoint of all the logging messages.
*/
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
* 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 )
{
super( null, logLevel );
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 );
}

/**


+ 79
- 23
proposal/myrmidon/src/java/org/apache/myrmidon/framework/Execute.java View File

@@ -24,6 +24,9 @@ import org.apache.tools.todo.util.FileUtils;
* This is a utility class designed to make executing native
* 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:thomas.haas@softwired-inc.com">Thomas Haas</a>
* @version $Revision$ $Date$
@@ -35,32 +38,50 @@ public class Execute

private Commandline m_command;
private Properties m_environment = new Properties();
private File m_workingDirectory = new File( "." );
private File m_workingDirectory;
private boolean m_newEnvironment;
private ExecOutputHandler m_handler;
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 )
{
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 )
{
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 )
{
m_command = command;
}

/**
* Returns the commandline of the process to launch.
*/
public Commandline getCommandline()
{
if( null == m_command )
@@ -70,6 +91,11 @@ public class Execute
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 )
{
if( null == environment )
@@ -83,7 +109,7 @@ public class Execute
* If this variable is false then then the environment specified is
* added to the environment variables for current process. If this
* 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 )
{
@@ -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 )
{
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 )
{
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
final ExecManager execManager = (ExecManager)context.getService( ExecManager.class );
final ExecMetaData metaData = buildExecMetaData( execManager );
final ExecMetaData metaData = buildExecMetaData( context, execManager );

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 );
checkReturnCode( returnCode );
return returnCode;
@@ -167,20 +211,23 @@ public class Execute
final String message = REZ.getString( "execute.no-executable.error" );
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 )
{
@@ -199,8 +246,7 @@ public class Execute
private void checkReturnCode( final int returnCode )
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",
m_command.getExecutable(),
@@ -213,11 +259,14 @@ public class Execute
* Utility method to create an ExecMetaData object
* to pass to the ExecManager service.
*/
private ExecMetaData buildExecMetaData( final ExecManager execManager )
private ExecMetaData buildExecMetaData( final TaskContext context,
final ExecManager execManager )
throws ExecException
{
// Build the command line
final String[] command = m_command.getCommandline();

// Build the environment
final Properties newEnvironment = new Properties();
if( !m_newEnvironment )
{
@@ -225,8 +274,15 @@ public class Execute
}
newEnvironment.putAll( m_environment );

// Determine the working directory
File workingDir = m_workingDirectory;
if( workingDir == null )
{
workingDir = context.getBaseDirectory();
}

return new ExecMetaData( command,
newEnvironment,
m_workingDirectory );
workingDir );
}
}

+ 3
- 1
proposal/myrmidon/src/java/org/apache/myrmidon/framework/LoggingExecOutputHandler.java View File

@@ -33,7 +33,9 @@ public class LoggingExecOutputHandler
*/
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 );
}

/**


+ 167
- 0
proposal/myrmidon/src/java/org/apache/myrmidon/frontends/AbstractLogger.java View File

@@ -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 );
}

+ 1
- 141
proposal/myrmidon/src/java/org/apache/myrmidon/frontends/BasicLogger.java View File

@@ -17,14 +17,9 @@ import org.apache.avalon.framework.logger.Logger;
* @version $Revision$ $Date$
*/
public class BasicLogger
extends 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;

/**
* The string prefixed to all log messages.
*/
@@ -45,33 +40,6 @@ public class BasicLogger
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.
*
@@ -82,33 +50,6 @@ public class BasicLogger
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.
*
@@ -119,33 +60,6 @@ public class BasicLogger
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.
*
@@ -156,33 +70,6 @@ public class BasicLogger
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.
*
@@ -193,33 +80,6 @@ public class BasicLogger
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.
*


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

@@ -10,14 +10,10 @@ package org.apache.tools.todo.taskdefs;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URL;
import org.apache.aut.nativelib.ExecManager;
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.taskdefs.ExecuteJava;
import org.apache.tools.todo.types.Argument;
import org.apache.tools.todo.types.Commandline;
import org.apache.tools.todo.types.CommandlineJava;
@@ -131,12 +127,7 @@ public class ANTLR extends AbstractTask

if( fork )
{
getContext().debug( "Forking " + commandline.toString() );
int err = run( commandline );
if( err == 1 )
{
throw new TaskException( "ANTLR returned: " + err );
}
run( commandline );
}
else
{
@@ -222,26 +213,15 @@ public class ANTLR extends AbstractTask
* execute in a forked VM
*
* @param command Description of Parameter
* @return Description of the Returned Value
* @exception org.apache.myrmidon.api.TaskException Description of Exception
*/
private int run( final Commandline command )
private void run( final Commandline command )
throws TaskException
{
final Execute exe = new Execute();
if( workingdir != null )
{
exe.setWorkingDirectory( workingdir );
}
exe.setWorkingDirectory( workingdir );
exe.setCommandline( command );
try
{
return exe.execute( getContext() );
}
catch( IOException e )
{
throw new TaskException( "Error", e );
}
exe.execute( getContext() );
}

private void validateAttributes()


+ 1
- 12
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/IContract.java View File

@@ -784,18 +784,7 @@ public class IContract extends MatchingTask
}

// 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
{// not dirty


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

@@ -120,21 +120,15 @@ public class Java
public void execute()
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
*/
public int executeJava()
public void executeJava()
throws TaskException
{
final String classname = m_cmdl.getClassname();
@@ -156,8 +150,7 @@ public class Java
if( m_fork )
{
getContext().debug( "Forking " + m_cmdl.toString() );

return run( new Commandline( m_cmdl.getCommandline() ) );
run( new Commandline( m_cmdl.getCommandline() ) );
}
else
{
@@ -172,7 +165,6 @@ public class Java

getContext().debug( "Running in same VM " + m_cmdl.getJavaCommand().toString() );
run( m_cmdl );
return 0;
}
}

@@ -212,23 +204,12 @@ public class Java
/**
* 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
{
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.setCommandline( command );
return exe.execute( getContext() );
exe.execute( getContext() );
}
}

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

@@ -91,14 +91,8 @@ public class Rpm
{
final Commandline cmd = createCommand();
final Execute exe = new Execute();

if( m_topDir == null )
{
m_topDir = getBaseDirectory();
}
exe.setWorkingDirectory( m_topDir );
exe.setCommandline( cmd );
exe.setReturnCode( 0 );

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


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

@@ -114,9 +114,7 @@ public abstract class Continuus
{
exe.setExecOutputHandler( handler );
}
exe.setWorkingDirectory( getBaseDirectory() );
exe.setCommandline( cmd );
exe.setReturnCode( 0 );
exe.execute( getContext() );
}
}

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

@@ -106,9 +106,7 @@ public abstract class ClearCase extends AbstractTask
throws TaskException
{
final Execute exe = new Execute();
exe.setWorkingDirectory( getBaseDirectory() );
exe.setCommandline( cmd );
exe.setReturnCode( 0 );
exe.execute( getContext() );
}



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

@@ -11,7 +11,6 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import org.apache.aut.nativelib.ExecManager;
import org.apache.avalon.excalibur.io.IOUtil;
import org.apache.avalon.excalibur.util.StringUtil;
import org.apache.myrmidon.api.TaskContext;
@@ -54,7 +53,6 @@ public abstract class DefaultCompilerAdapter
protected boolean m_includeJavaRuntime;
protected String m_memoryInitialSize;
protected String m_memoryMaximumSize;
protected File m_baseDir;

/*
* jdg - TODO - all these attributes are currently protected, but they
@@ -91,7 +89,6 @@ public abstract class DefaultCompilerAdapter
m_extdirs = attributes.getExtdirs();
m_compileList = attributes.getFileList();
m_compileClasspath = attributes.getClasspath();
m_baseDir = attributes.getBaseDirectory();
m_memoryInitialSize = attributes.getMemoryInitialSize();
m_memoryMaximumSize = attributes.getMemoryMaximumSize();
}
@@ -371,7 +368,7 @@ public abstract class DefaultCompilerAdapter
}

final Execute exe = new Execute();
exe.setWorkingDirectory( m_baseDir );
exe.setIgnoreReturnCode( true );
final String[] commandline = commandArray;
exe.setCommandline( new Commandline( commandline ) );
return exe.execute( getTaskContext() );


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

@@ -184,7 +184,6 @@ public class JJTree
final Execute exe = new Execute();
getContext().debug( cmdl.toString() );
exe.setCommandline( new Commandline( cmdl.getCommandline() ) );
exe.setReturnCode( 0 );
exe.execute( getContext() );
}
}

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

@@ -244,7 +244,6 @@ public class JavaCC
final Execute exe = new Execute();
final String[] commandline = cmdline.getCommandline();
exe.setCommandline( new Commandline( commandline ) );
exe.setReturnCode( 0 );
exe.execute( getContext() );
}



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

@@ -823,15 +823,7 @@ public class Javadoc
final Execute exe = new Execute();
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.setReturnCode( 0 );
try
{
exe.execute( getContext() );


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

@@ -11,10 +11,8 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import org.apache.aut.nativelib.ExecManager;
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.Commandline;
import org.apache.tools.todo.types.CommandlineJava;
@@ -36,16 +34,6 @@ import org.apache.tools.todo.util.FileUtils;
public class JDependTask
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 String m_jvm;
private String m_format = "text";
@@ -84,7 +72,7 @@ public class JDependTask
/**
* 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>
*/
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
* 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)
*/
public void setJvm( final String jvm )
@@ -179,22 +167,13 @@ public class JDependTask
}

// execute the test and get the return code
int exitValue = JDependTask.ERRORS;
if( !m_fork )
{
exitValue = executeInVM( commandline );
executeInVM( commandline );
}
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.
*/
// JL: comment extracted from JUnitTask (and slightly modified)
private int executeAsForked( final CommandlineJava commandline )
private void executeAsForked( final CommandlineJava commandline )
throws TaskException
{
// if not set, auto-create the ClassPath from the project
@@ -245,17 +224,13 @@ public class JDependTask

final String[] commandline1 = commandline.getCommandline();
exe.setCommandline( new Commandline( commandline1 ) );
if( m_dir != null )
{
exe.setWorkingDirectory( m_dir );
}
exe.setWorkingDirectory( m_dir );

if( m_outputFile != null )
{
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.
*
* @param commandline Description of Parameter
* @return Description of the Returned Value
* @exception TaskException Description of Exception
*/
public int executeInVM( final CommandlineJava commandline )
private void executeInVM( final CommandlineJava commandline )
throws TaskException
{
jdepend.textui.JDepend jdepend;
@@ -326,6 +300,5 @@ public class JDependTask
}
}
jdepend.analyze();
return SUCCESS;
}
}

+ 1
- 4
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jsp/WLJspc.java View File

@@ -231,10 +231,7 @@ public class WLJspc extends MatchingTask
//helperTask.clearArgs();
helperTask.addArg( new Argument( arg ) );
helperTask.addClasspath( compileClasspath );
if( helperTask.executeJava() != 0 )
{
getContext().warn( files[ i ] + " failed to compile" );
}
helperTask.executeJava();
}
}



+ 6
- 6
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/AggregateTransformer.java View File

@@ -16,7 +16,7 @@ import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
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.tools.todo.types.EnumeratedAttribute;
import org.w3c.dom.Document;
@@ -57,7 +57,7 @@ public class AggregateTransformer
*/
private File m_styleDir;

private AbstractTask m_task;
private TaskContext m_context;

/**
* the destination directory, this is the root from where html should be
@@ -65,9 +65,9 @@ public class AggregateTransformer
*/
private File m_toDir;

public AggregateTransformer( AbstractTask task )
public AggregateTransformer( TaskContext context )
{
m_task = task;
m_context = context;
}

public void setFormat( Format format )
@@ -196,11 +196,11 @@ public class AggregateTransformer
// set the destination directory relative from the project if needed.
if( m_toDir == null )
{
m_toDir = FileUtil.resolveFile( m_task.getBaseDirectory(), "." );
m_toDir = FileUtil.resolveFile( m_context.getBaseDirectory(), "." );
}
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() );
}
}



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

@@ -633,13 +633,10 @@ public class JUnitTask extends AbstractTask
}

final Execute exe = new Execute();
exe.setIgnoreReturnCode( true );
exe.setCommandline( new Commandline( cmd.getCommandline() ) );
if( dir != null )
{
exe.setWorkingDirectory( dir );
}
exe.setWorkingDirectory( dir );

getContext().debug( "Executing: " + cmd.toString() );
try
{
return exe.execute( getContext() );


+ 1
- 1
proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/XMLResultAggregator.java View File

@@ -133,7 +133,7 @@ public class XMLResultAggregator

public AggregateTransformer createReport()
{
AggregateTransformer transformer = new AggregateTransformer( this );
AggregateTransformer transformer = new AggregateTransformer( getContext() );
transformers.add( transformer );
return transformer;
}


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

@@ -281,7 +281,6 @@ public abstract class AbstractMetamataTask
getContext().debug( m_cmdl.toString() );
final String[] commandline = m_cmdl.getCommandline();
exe.setCommandline( new Commandline( commandline ) );
exe.setReturnCode( 0 );
exe.execute( getContext() );
}



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

@@ -292,7 +292,6 @@ public class MParse
getContext().debug( m_cmdl.toString() );
final String[] commandline = m_cmdl.getCommandline();
exe.setCommandline( new Commandline( commandline ) );
exe.setReturnCode( 0 );
exe.execute( getContext() );
}



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

@@ -19,12 +19,10 @@ import java.text.MessageFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.aut.nativelib.ExecManager;
import org.apache.aut.nativelib.ExecOutputHandler;
import org.apache.avalon.excalibur.io.IOUtil;
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.Commandline;

@@ -181,8 +179,6 @@ public class Pvcs
public void execute()
throws TaskException
{
int result = 0;

validate();

final File filelist = getFileList();
@@ -192,10 +188,9 @@ public class Pvcs
try
{
final Execute exe = new Execute();
exe.setWorkingDirectory( getBaseDirectory() );
exe.setIgnoreReturnCode( m_ignoreReturnCode );
exe.setCommandline( cmd );
result = exe.execute( getContext() );
checkResultCode( result, cmd );
exe.execute( getContext() );
}
finally
{
@@ -238,17 +233,6 @@ public class Pvcs
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()
throws TaskException
{
@@ -267,12 +251,11 @@ public class Pvcs
final File fileList = File.createTempFile( "pvcs_ant_", ".log" );

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

if( !tmp.exists() )
{


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

@@ -118,7 +118,6 @@ public class CovMerge

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 ! :-(


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

@@ -251,7 +251,6 @@ public class CovReport
// use the custom handler for stdin issues
final Execute exe = new Execute();
exe.setCommandline( cmdl );
exe.setReturnCode( 0 );
exe.execute( getContext() );
getContext().debug( "coveragePath: " + coveragePath );
getContext().debug( "format: " + format );


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

@@ -252,7 +252,6 @@ public class Coverage
// use the custom handler for stdin issues
final Execute exe = new Execute();
exe.setCommandline( cmdl );
exe.setReturnCode( 0 );
exe.execute( getContext() );
}
finally


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

@@ -213,9 +213,7 @@ public abstract class MSVSS
exe.setEnvironment( env );
}

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


Loading…
Cancel
Save