adammurdoch 02/03/09 02:13:03
Modified: proposal/myrmidon/src/testcases/org/apache/antlib/core
IfTest.java PropertyTest.java
proposal/myrmidon/src/java/org/apache/myrmidon/frontends
CLIMain.java Resources.properties
proposal/myrmidon/src/java/org/apache/myrmidon/components/executor
AspectAwareExecutor.java DefaultExecutor.java
Resources.properties
proposal/myrmidon/etc/testcases/org/apache/antlib/core
property.ant
Log:
* Some fixes to the command-line launcher:
* Was not exiting with non-zero exit code when the build failed.
* Fix the error reporting so that the entire exception chain is reported.
* Only print out stack traces when in verbose or debug mode.
* Wrap all exceptions thrown during task initialisation and execution with
a general 'task failed' exception.
* Another <property> testcase.
Revision Changes Path
1.3 +7 -4
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/antlib/core/IfTest.java
Index: IfTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/antlib/core/IfTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- IfTest.java 3 Mar 2002 07:09:30 -0000 1.2
+++ IfTest.java 9 Mar 2002 10:13:02 -0000 1.3
@@ -17,7 +17,7 @@
* Test cases for the <if> task.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
- * @version $Revision: 1.2 $ $Date: 2002/03/03 07:09:30 $
+ * @version $Revision: 1.3 $ $Date: 2002/03/09 10:13:02 $
*/
public class IfTest
extends AbstractProjectTest
@@ -83,11 +83,14 @@
final File projectFile = getTestResource( "if.ant" );
// Check for missing condition
- String message = REZ.getString( "if.no-condition.error" );
- executeTargetExpectError( projectFile, "no-condition", message );
+ String[] messages = {
+ null,
+ REZ.getString( "if.no-condition.error" )
+ };
+ executeTargetExpectError( projectFile, "no-condition", messages );
// Check for too many conditions
- String[] messages =
+ messages = new String[]
{
null,
null,
1.3 +16 -6
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/antlib/core/PropertyTest.java
Index: PropertyTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/antlib/core/PropertyTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PropertyTest.java 1 Mar 2002 08:54:34 -0000 1.2
+++ PropertyTest.java 9 Mar 2002 10:13:02 -0000 1.3
@@ -17,7 +17,7 @@
* Test cases for <property> task.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
- * @version $Revision: 1.2 $ $Date: 2002/03/01 08:54:34 $
+ * @version $Revision: 1.3 $ $Date: 2002/03/09 10:13:02 $
*/
public class PropertyTest
extends AbstractProjectTest
@@ -64,21 +64,31 @@
final File projectFile = getTestResource( "property.ant" );
// Missing name
- String message = REZ.getString( "property.no-name.error" );
- executeTargetExpectError( projectFile, "missing-name", message );
+ String[] messages =
+ {
+ null,
+ REZ.getString( "property.no-name.error" )
+ };
+ executeTargetExpectError( projectFile, "missing-name", messages );
// Missing value
- message = REZ.getString( "property.no-value.error" );
- executeTargetExpectError( projectFile, "missing-value", message );
+ messages = new String[]
+ {
+ null,
+ REZ.getString( "property.no-value.error" )
+ };
+ executeTargetExpectError( projectFile, "missing-value", messages );
// Too many values
- String[] messages = {
+ messages = new String[]
+ {
null,
null,
REZ.getString( "property.multi-set.error" )
};
executeTargetExpectError( projectFile, "too-many-values1", messages
);
executeTargetExpectError( projectFile, "too-many-values2", messages
);
+ executeTargetExpectError( projectFile, "too-many-values3", messages
);
}
}
1.28 +109 -56
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/frontends/CLIMain.java
Index: CLIMain.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/frontends/CLIMain.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- CLIMain.java 1 Mar 2002 10:35:03 -0000 1.27
+++ CLIMain.java 9 Mar 2002 10:13:03 -0000 1.28
@@ -18,6 +18,7 @@
import org.apache.avalon.excalibur.cli.CLUtil;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
+import org.apache.avalon.framework.CascadingException;
import org.apache.avalon.framework.ExceptionUtil;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.LogKitLogger;
@@ -42,7 +43,7 @@
* to run project.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.27 $ $Date: 2002/03/01 10:35:03 $
+ * @version $Revision: 1.28 $ $Date: 2002/03/09 10:13:03 $
*/
public class CLIMain
extends AbstractLogEnabled
@@ -105,6 +106,9 @@
///Determine whether tasks are actually executed
private boolean m_dryRun = false;
+ ///Log level to use
+ private static Priority m_priority = Priority.WARN;
+
/**
* Main entry point called to run standard Myrmidon.
*
@@ -120,9 +124,7 @@
}
catch( final Throwable throwable )
{
- final String message =
- REZ.getString( "error-message",
ExceptionUtil.printStackTrace( throwable ) );
- System.err.println( message );
+ main.reportError( throwable );
exitCode = -1;
}
finally
@@ -219,6 +221,7 @@
}
private boolean parseCommandLineOptions( final String[] args )
+ throws Exception
{
final CLOptionDescriptor[] options = createCLOptions();
final CLArgsParser parser = new CLArgsParser( args, options );
@@ -226,8 +229,7 @@
if( null != parser.getErrorString() )
{
final String message = REZ.getString( "error-message",
parser.getErrorString() );
- System.err.println( message );
- return false;
+ throw new Exception( message );
}
final List clOptions = parser.getArguments();
@@ -254,13 +256,13 @@
break;
case LOG_LEVEL_OPT:
- m_parameters.setParameter( "log.level",
option.getArgument() );
+ m_priority = mapLogLevel( option.getArgument() );
break;
case VERBOSE_OPT:
- m_parameters.setParameter( "log.level", "INFO" );
+ m_priority = Priority.INFO;
break;
case QUIET_OPT:
- m_parameters.setParameter( "log.level", "ERROR" );
+ m_priority = Priority.ERROR;
break;
case INCREMENTAL_OPT:
@@ -322,7 +324,7 @@
prepareLogging();
- final File homeDir = getHomeDir();
+ checkHomeDir();
final File buildFile = getBuildFile();
//getLogger().debug( "Ant Bin Directory: " + m_binDir );
@@ -336,24 +338,35 @@
}
final Embeddor embeddor = prepareEmbeddor();
- final ProjectListener listener = prepareListener( embeddor );
- //create the project
- final Project project =
- embeddor.createProject( buildFile.toString(), null,
m_builderParameters );
+ try
+ {
+ final ProjectListener listener = prepareListener( embeddor );
- //loop over build if we are in incremental mode..
- final boolean incremental = m_parameters.getParameterAsBoolean(
"incremental", false );
- if( !incremental )
+ //create the project
+ final Project project =
+ embeddor.createProject( buildFile.toString(), null,
m_builderParameters );
+
+ //loop over build if we are in incremental mode..
+ final boolean incremental = m_parameters.getParameterAsBoolean(
"incremental", false );
+ if( !incremental )
+ {
+ executeBuild( embeddor, project, listener );
+ }
+ else
+ {
+ executeIncrementalBuild( embeddor, project, listener );
+ }
+ }
+ catch( final Exception e )
{
- executeBuild( embeddor, project, listener );
+ final String message = REZ.getString( "build-failed.error" );
+ throw new CascadingException( message, e );
}
- else
+ finally
{
- executeIncrementalBuild( embeddor, project, listener );
+ shutdownEmbeddor( embeddor );
}
-
- shutdownEmbeddor( embeddor );
}
private void executeIncrementalBuild( final Embeddor embeddor,
@@ -365,7 +378,14 @@
while( true )
{
- executeBuild( embeddor, project, listener );
+ try
+ {
+ executeBuild( embeddor, project, listener );
+ }
+ catch( final TaskException te )
+ {
+ reportError( te );
+ }
final String message = REZ.getString( "repeat.notice" );
System.out.println( message );
@@ -385,6 +405,44 @@
}
}
+ /**
+ * Builds the error message for an exception
+ */
+ private void reportError( final Throwable throwable )
+ {
+ // Build the message
+ final String message;
+ if( m_priority.isLowerOrEqual( Priority.INFO ) )
+ {
+ // Verbose mode - include the stack traces
+ message = ExceptionUtil.printStackTrace( throwable, 5, true,
true );
+ }
+ else
+ {
+ // Build the message
+ final StringBuffer buffer = new StringBuffer();
+ buffer.append( throwable.getMessage() );
+ for( Throwable current = ExceptionUtil.getCause( throwable, true
);
+ current != null;
+ current = ExceptionUtil.getCause( current, true ) )
+ {
+ final String causeMessage = REZ.getString( "cause.error",
current.getMessage() );
+ buffer.append( causeMessage );
+ }
+ message = buffer.toString();
+ }
+
+ // Write the message out
+ if( getLogger() == null )
+ {
+ System.err.println( message );
+ }
+ else
+ {
+ getLogger().error( message );
+ }
+ }
+
private void executeBuild( final Embeddor embeddor,
final Project project,
final ProjectListener listener )
@@ -416,9 +474,9 @@
return buildFile;
}
- private File getHomeDir() throws Exception
+ private void checkHomeDir() throws Exception
{
- final String home = m_parameters.getParameter( "myrmidon.home", null
);
+ final String home = m_parameters.getParameter( "myrmidon.home" );
final File homeDir = ( new File( home ) ).getAbsoluteFile();
if( !homeDir.isDirectory() )
{
@@ -431,15 +489,12 @@
final String message = REZ.getString( "homedir.notice", homeDir
);
getLogger().info( message );
}
-
- return homeDir;
}
private void prepareLogging() throws Exception
{
//handle logging...
- final String logLevel = m_parameters.getParameter( "log.level", null
);
- enableLogging( new LogKitLogger( createLogger( logLevel ) ) );
+ enableLogging( new LogKitLogger( createLogger( m_priority ) ) );
}
private void shutdownEmbeddor( final Embeddor embeddor )
@@ -486,51 +541,49 @@
private void doBuild( final Workspace workspace,
final Project project,
final ArrayList targets )
+ throws TaskException
{
- try
- {
- final int targetCount = targets.size();
+ final int targetCount = targets.size();
- //if we didn't specify a target on CLI then choose default
- if( 0 == targetCount )
- {
- workspace.executeProject( project,
project.getDefaultTargetName() );
- }
- else
- {
- for( int i = 0; i < targetCount; i++ )
- {
- workspace.executeProject( project, (String)targets.get(
i ) );
- }
- }
+ //if we didn't specify a target on CLI then choose default
+ if( 0 == targetCount )
+ {
+ workspace.executeProject( project,
project.getDefaultTargetName() );
}
- catch( final TaskException ae )
+ else
{
- final String message =
- REZ.getString( "build-failed.error",
ExceptionUtil.printStackTrace( ae, 5, true ) );
- getLogger().error( message );
+ for( int i = 0; i < targetCount; i++ )
+ {
+ workspace.executeProject( project, (String)targets.get( i )
);
+ }
}
}
/**
- * Create Logger of appropriate log-level.
- *
- * @param logLevel the log-level
- * @return the logger
- * @exception Exception if an error occurs
+ * Sets the log level.
*/
- private Logger createLogger( final String logLevel )
- throws Exception
+ private Priority mapLogLevel( final String logLevel ) throws Exception
{
final String logLevelCapitalized = logLevel.toUpperCase();
final Priority priority = Priority.getPriorityForName(
logLevelCapitalized );
-
if( !priority.getName().equals( logLevelCapitalized ) )
{
final String message = REZ.getString( "bad-loglevel.error",
logLevel );
throw new Exception( message );
}
+ return priority;
+ }
+ /**
+ * Create Logger of appropriate log-level.
+ *
+ * @param priority the log-level
+ * @return the logger
+ * @exception Exception if an error occurs
+ */
+ private Logger createLogger( final Priority priority )
+ throws Exception
+ {
final Logger logger = Hierarchy.getDefaultHierarchy().getLoggerFor(
"myrmidon" );
final PatternFormatter formatter = new PatternFormatter( PATTERN );
1.6 +2 -1
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/frontends/Resources.properties
Index: Resources.properties
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/frontends/Resources.properties,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Resources.properties 24 Feb 2002 07:37:44 -0000 1.5
+++ Resources.properties 9 Mar 2002 10:13:03 -0000 1.6
@@ -18,7 +18,8 @@
home-not-dir.error=myrmidon-home ({0}) is not a directory.
bad-file.error=File {0} is not a file or doesn't exist.
bad-loglevel.error=Unknown log level - {0}.
-build-failed.error=BUILD FAILED\nReason:\n{0}
+build-failed.error=BUILD FAILED.
+cause.error=\nReason: {0}
repeat.notice=Continue ? (Enter no to stop)
1.21 +35 -24
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/AspectAwareExecutor.java
Index: AspectAwareExecutor.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/AspectAwareExecutor.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- AspectAwareExecutor.java 1 Mar 2002 08:54:20 -0000 1.20
+++ AspectAwareExecutor.java 9 Mar 2002 10:13:03 -0000 1.21
@@ -28,7 +28,7 @@
* the aspects helpers.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.20 $ $Date: 2002/03/01 08:54:20 $
+ * @version $Revision: 1.21 $ $Date: 2002/03/09 10:13:03 $
*/
public class AspectAwareExecutor
extends DefaultExecutor
@@ -75,30 +75,41 @@
final ExecutionFrame frame )
throws TaskException
{
- Configuration taskModel = getAspectManager().preCreate( model );
- taskModel = prepareAspects( taskModel );
+ try
+ {
+ Configuration taskModel = getAspectManager().preCreate( model );
+ taskModel = prepareAspects( taskModel );
- final String taskName = taskModel.getName();
- debug( "creating.notice", taskName );
- final Task task = createTask( taskName, frame );
- getAspectManager().postCreate( task );
-
- debug( "logger.notice", taskName );
- final Logger logger = frame.getLogger();
- getAspectManager().preLogEnabled( logger );
- doLogEnabled( task, taskModel, logger );
-
- debug( "contextualizing.notice", taskName );
- doContextualize( task, taskModel, frame.getContext() );
-
- debug( "configuring.notice", taskName );
- getAspectManager().preConfigure( taskModel );
- doConfigure( task, taskModel, frame.getContext() );
-
- debug( "executing.notice", taskName );
- getAspectManager().preExecute();
- doExecute( taskModel, task );
- getAspectManager().preDestroy();
+ final String taskName = taskModel.getName();
+ debug( "creating.notice", taskName );
+ final Task task = doCreateTask( taskName, frame );
+ getAspectManager().postCreate( task );
+
+ debug( "logger.notice", taskName );
+ final Logger logger = frame.getLogger();
+ getAspectManager().preLogEnabled( logger );
+ doLogEnabled( task, taskModel, logger );
+
+ debug( "contextualizing.notice", taskName );
+ doContextualize( task, taskModel, frame.getContext() );
+
+ debug( "configuring.notice", taskName );
+ getAspectManager().preConfigure( taskModel );
+ doConfigure( task, taskModel, frame.getContext() );
+
+ debug( "executing.notice", taskName );
+ getAspectManager().preExecute();
+ doExecute( taskModel, task );
+ getAspectManager().preDestroy();
+ }
+ catch( Exception e )
+ {
+ // Wrap in generic error message
+ final String message = REZ.getString( "execute.error",
+ model.getName(),
+ model.getLocation() );
+ throw new TaskException( message, e );
+ }
}
protected void doExecute( final Configuration taskModel, final Task task
)
1.29 +30 -32
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/DefaultExecutor.java
Index: DefaultExecutor.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/DefaultExecutor.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- DefaultExecutor.java 26 Feb 2002 23:21:07 -0000 1.28
+++ DefaultExecutor.java 9 Mar 2002 10:13:03 -0000 1.29
@@ -10,6 +10,7 @@
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.logger.Logger;
@@ -29,7 +30,7 @@
* The basic executor that just executes the tasks.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.28 $ $Date: 2002/02/26 23:21:07 $
+ * @version $Revision: 1.29 $ $Date: 2002/03/09 10:13:03 $
*/
public class DefaultExecutor
extends AbstractLogEnabled
@@ -52,24 +53,36 @@
m_configurer = (Configurer)serviceManager.lookup( Configurer.ROLE );
}
+ /**
+ * Executes a task.
+ */
public void execute( final Configuration taskModel, final ExecutionFrame
frame )
throws TaskException
{
final String taskName = taskModel.getName();
- debug( "creating.notice", taskName );
- final Task task = createTask( taskName, frame );
+ try
+ {
+ debug( "creating.notice", taskName );
+ final Task task = doCreateTask( taskName, frame );
- debug( "logger.notice", taskName );
- doLogEnabled( task, taskModel, frame.getLogger() );
+ debug( "logger.notice", taskName );
+ doLogEnabled( task, taskModel, frame.getLogger() );
- debug( "contextualizing.notice", taskName );
- doContextualize( task, taskModel, frame.getContext() );
+ debug( "contextualizing.notice", taskName );
+ doContextualize( task, taskModel, frame.getContext() );
- debug( "configuring.notice", taskName );
- doConfigure( task, taskModel, frame.getContext() );
+ debug( "configuring.notice", taskName );
+ doConfigure( task, taskModel, frame.getContext() );
- debug( "executing.notice", taskName );
- task.execute();
+ debug( "executing.notice", taskName );
+ task.execute();
+ }
+ catch( Exception e )
+ {
+ // Wrap in generic error message
+ final String message = REZ.getString( "execute.error", taskName,
taskModel.getLocation() );
+ throw new TaskException( message, e );
+ }
}
protected final void debug( final String key, final String taskName )
@@ -84,7 +97,7 @@
/**
* Creates a task instance.
*/
- protected final Task createTask( final String name, final ExecutionFrame
frame )
+ protected final Task doCreateTask( final String name, final
ExecutionFrame frame )
throws TaskException
{
try
@@ -94,7 +107,7 @@
}
catch( final TypeException te )
{
- final String message = REZ.getString( "no-create.error", name );
+ final String message = REZ.getString( "create.error", name );
throw new TaskException( message, te );
}
}
@@ -105,20 +118,9 @@
protected final void doConfigure( final Task task,
final Configuration taskModel,
final TaskContext taskContext )
- throws TaskException
+ throws ConfigurationException
{
- try
- {
- m_configurer.configure( task, taskModel, taskContext );
- }
- catch( final Throwable throwable )
- {
- final String message =
- REZ.getString( "config.error",
- taskModel.getName(),
- taskModel.getLocation() );
- throw new TaskException( message, throwable );
- }
+ m_configurer.configure( task, taskModel, taskContext );
}
/**
@@ -136,9 +138,7 @@
catch( final Throwable throwable )
{
final String message =
- REZ.getString( "contextualize.error",
- taskModel.getName(),
- taskModel.getLocation() );
+ REZ.getString( "contextualize.error", taskModel.getName() );
throw new TaskException( message, throwable );
}
}
@@ -160,9 +160,7 @@
catch( final Throwable throwable )
{
final String message =
- REZ.getString( "logger.error",
- taskModel.getName(),
- taskModel.getLocation() );
+ REZ.getString( "logger.error", taskModel.getName() );
throw new TaskException( message, throwable );
}
}
1.6 +4 -4
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/Resources.properties
Index: Resources.properties
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/Resources.properties,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Resources.properties 26 Feb 2002 23:21:07 -0000 1.5
+++ Resources.properties 9 Mar 2002 10:13:03 -0000 1.6
@@ -4,10 +4,10 @@
configuring.notice=Configuring {0}.
executing.notice=Executing {0}.
-no-create.error=Could not create task "{0}".
-config.error={1}: Could not configure task "{0}".
-contextualize.error={1}: Could not set the context for task "{0}".
-logger.error={1}: Could not set the logger for task "{0}".
+create.error=Could not create task <{0}>.
+contextualize.error=Could not set the context for task <{0}>.
+logger.error=Could not set the logger for task <{0}>.
+execute.error={1}: Could not execute task <{0}>.
unused-settings.error=Unused aspect settings for namespace {0}
(parameterCount={1} elementCount={2}).
dispatch-settings.notice=Dispatching Aspect Settings to namespace {0}
(parameterCount={1} elementCount={2}).
1.2 +9 -0
jakarta-ant/proposal/myrmidon/etc/testcases/org/apache/antlib/core/property.ant
Index: property.ant
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/etc/testcases/org/apache/antlib/core/property.ant,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- property.ant 26 Feb 2002 23:26:56 -0000 1.1
+++ property.ant 9 Mar 2002 10:13:03 -0000 1.2
@@ -41,4 +41,13 @@
<property-test-type value="value 2"/>
</property>
</target>
+
+ <!-- Test setting the value more than once -->
+ <target name="too-many-values3">
+ <property name="some-prop">
+ <property-test-type value="value 1"/>
+ <property-test-type value="value 2"/>
+ <property-test-type value="value 3"/>
+ </property>
+ </target>
</project>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>