Add a new Executor and allow possibility of "dry runs". Ie runs that don't actually execute commands. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269238 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -132,6 +132,7 @@ public class DefaultEmbeddor | |||||
| setupLogger( projectManager ); | setupLogger( projectManager ); | ||||
| if( projectManager instanceof Composable ) | if( projectManager instanceof Composable ) | ||||
| { | { | ||||
| final DefaultComponentManager componentManager = | final DefaultComponentManager componentManager = | ||||
| @@ -237,6 +238,7 @@ public class DefaultEmbeddor | |||||
| "org.apache.myrmidon.components.type.DefaultTypeManager" ); | "org.apache.myrmidon.components.type.DefaultTypeManager" ); | ||||
| defaults.setParameter( Executor.ROLE, | defaults.setParameter( Executor.ROLE, | ||||
| //"org.apache.myrmidon.components.executor.DefaultExecutor" ); | //"org.apache.myrmidon.components.executor.DefaultExecutor" ); | ||||
| //"org.apache.myrmidon.components.executor.PrintingExecutor" ); | |||||
| "org.apache.myrmidon.components.executor.AspectAwareExecutor" ); | "org.apache.myrmidon.components.executor.AspectAwareExecutor" ); | ||||
| defaults.setParameter( ProjectManager.ROLE, | defaults.setParameter( ProjectManager.ROLE, | ||||
| "org.apache.myrmidon.components.manager.DefaultProjectManager" ); | "org.apache.myrmidon.components.manager.DefaultProjectManager" ); | ||||
| @@ -95,13 +95,19 @@ public class AspectAwareExecutor | |||||
| getLogger().debug( "Executing" ); | getLogger().debug( "Executing" ); | ||||
| getAspectManager().preExecute(); | getAspectManager().preExecute(); | ||||
| task.execute(); | |||||
| doExecute( taskModel, task ); | |||||
| getLogger().debug( "Disposing" ); | getLogger().debug( "Disposing" ); | ||||
| getAspectManager().preDestroy(); | getAspectManager().preDestroy(); | ||||
| doDispose( task, taskModel ); | doDispose( task, taskModel ); | ||||
| } | } | ||||
| protected void doExecute( final Configuration taskModel, final Task task ) | |||||
| throws TaskException | |||||
| { | |||||
| task.execute(); | |||||
| } | |||||
| //TODO: Extract and clean taskModel here. | //TODO: Extract and clean taskModel here. | ||||
| //Get all parameters from model and provide to appropriate aspect. | //Get all parameters from model and provide to appropriate aspect. | ||||
| //aspect( final Parameters parameters, final Configuration[] elements ) | //aspect( final Parameters parameters, final Configuration[] elements ) | ||||
| @@ -0,0 +1,76 @@ | |||||
| /* | |||||
| * 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 file. | |||||
| */ | |||||
| package org.apache.myrmidon.components.executor; | |||||
| import org.apache.myrmidon.api.Task; | |||||
| import org.apache.myrmidon.api.TaskException; | |||||
| import org.apache.avalon.framework.configuration.Configuration; | |||||
| public class PrintingExecutor | |||||
| extends AspectAwareExecutor | |||||
| { | |||||
| protected void doExecute( final Configuration taskModel, final Task task ) | |||||
| throws TaskException | |||||
| { | |||||
| final StringBuffer sb = new StringBuffer(); | |||||
| printConfiguration( taskModel, 0, sb ); | |||||
| System.out.println( sb.toString() ); | |||||
| } | |||||
| private void printConfiguration( final Configuration taskModel, | |||||
| final int level, | |||||
| final StringBuffer sb ) | |||||
| { | |||||
| for( int i = 0; i < level; i++ ) | |||||
| { | |||||
| sb.append( ' ' ); | |||||
| } | |||||
| sb.append( '<' ); | |||||
| sb.append( taskModel.getName() ); | |||||
| final String[] names = taskModel.getAttributeNames(); | |||||
| for( int i = 0; i < names.length; i++ ) | |||||
| { | |||||
| final String name = names[ i ]; | |||||
| final String value = taskModel.getAttribute( name, null ); | |||||
| sb.append( ' ' ); | |||||
| sb.append( name ); | |||||
| sb.append( "=\"" ); | |||||
| sb.append( value ); | |||||
| sb.append( '\"' ); | |||||
| } | |||||
| final Configuration[] children = taskModel.getChildren(); | |||||
| if( 0 == children.length ) | |||||
| { | |||||
| sb.append( "/>\n" ); | |||||
| } | |||||
| else | |||||
| { | |||||
| sb.append( ">\n" ); | |||||
| for( int i = 0; i < children.length; i++ ) | |||||
| { | |||||
| printConfiguration( children[ i ], level + 1, sb ); | |||||
| } | |||||
| for( int i = 0; i < level; i++ ) | |||||
| { | |||||
| sb.append( ' ' ); | |||||
| } | |||||
| sb.append( "</" ); | |||||
| sb.append( taskModel.getName() ); | |||||
| sb.append( ">\n" ); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -29,7 +29,7 @@ import org.apache.myrmidon.api.TaskException; | |||||
| import org.apache.myrmidon.components.executor.DefaultExecutionFrame; | import org.apache.myrmidon.components.executor.DefaultExecutionFrame; | ||||
| import org.apache.myrmidon.components.executor.ExecutionFrame; | import org.apache.myrmidon.components.executor.ExecutionFrame; | ||||
| import org.apache.myrmidon.components.executor.Executor; | import org.apache.myrmidon.components.executor.Executor; | ||||
| import org.apache.myrmidon.components.model.Condition; | |||||
| import org.apache.myrmidon.framework.Condition; | |||||
| import org.apache.myrmidon.components.model.Project; | import org.apache.myrmidon.components.model.Project; | ||||
| import org.apache.myrmidon.components.model.Target; | import org.apache.myrmidon.components.model.Target; | ||||
| import org.apache.myrmidon.components.type.TypeManager; | import org.apache.myrmidon.components.type.TypeManager; | ||||
| @@ -9,6 +9,7 @@ package org.apache.myrmidon.components.model; | |||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import org.apache.avalon.framework.configuration.Configuration; | import org.apache.avalon.framework.configuration.Configuration; | ||||
| import org.apache.myrmidon.framework.Condition; | |||||
| /** | /** | ||||
| * Targets in build file. | * Targets in build file. | ||||
| @@ -15,5 +15,5 @@ package org.apache.myrmidon.framework; | |||||
| */ | */ | ||||
| public interface DataType | public interface DataType | ||||
| { | { | ||||
| String ROLE = "org.apache.myrmidon.api.DataType"; | |||||
| String ROLE = "org.apache.myrmidon.framework.DataType"; | |||||
| } | } | ||||
| @@ -8,7 +8,7 @@ | |||||
| package org.apache.myrmidon.framework; | package org.apache.myrmidon.framework; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.components.model.Condition; | |||||
| import org.apache.myrmidon.framework.Condition; | |||||
| /** | /** | ||||
| * Basic data type for holding patterns. | * Basic data type for holding patterns. | ||||
| @@ -37,6 +37,7 @@ import org.apache.myrmidon.api.DefaultTaskContext; | |||||
| import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.components.builder.ProjectBuilder; | import org.apache.myrmidon.components.builder.ProjectBuilder; | ||||
| import org.apache.myrmidon.components.executor.Executor; | |||||
| import org.apache.myrmidon.components.embeddor.Embeddor; | import org.apache.myrmidon.components.embeddor.Embeddor; | ||||
| import org.apache.myrmidon.components.embeddor.DefaultEmbeddor; | import org.apache.myrmidon.components.embeddor.DefaultEmbeddor; | ||||
| import org.apache.myrmidon.components.manager.LogTargetToListenerAdapter; | import org.apache.myrmidon.components.manager.LogTargetToListenerAdapter; | ||||
| @@ -67,13 +68,14 @@ public class CLIMain | |||||
| private static final int TASKLIB_DIR_OPT = 5; | private static final int TASKLIB_DIR_OPT = 5; | ||||
| private static final int INCREMENTAL_OPT = 6; | private static final int INCREMENTAL_OPT = 6; | ||||
| private static final int HOME_DIR_OPT = 7; | private static final int HOME_DIR_OPT = 7; | ||||
| private static final int DRY_RUN_OPT = 8; | |||||
| //incompatable options for info options | //incompatable options for info options | ||||
| private static final int[] INFO_OPT_INCOMPAT = new int[] | private static final int[] INFO_OPT_INCOMPAT = new int[] | ||||
| { | { | ||||
| HELP_OPT, QUIET_OPT, VERBOSE_OPT, FILE_OPT, | HELP_OPT, QUIET_OPT, VERBOSE_OPT, FILE_OPT, | ||||
| LOG_LEVEL_OPT, VERSION_OPT, LISTENER_OPT, | LOG_LEVEL_OPT, VERSION_OPT, LISTENER_OPT, | ||||
| DEFINE_OPT //TASKLIB_DIR_OPT, HOME_DIR_OPT | |||||
| DEFINE_OPT, DRY_RUN_OPT //TASKLIB_DIR_OPT, HOME_DIR_OPT | |||||
| }; | }; | ||||
| //incompatable options for other logging options | //incompatable options for other logging options | ||||
| @@ -96,6 +98,9 @@ public class CLIMain | |||||
| ///List of user supplied parameters for builder | ///List of user supplied parameters for builder | ||||
| private Parameters m_builderParameters = new Parameters(); | private Parameters m_builderParameters = new Parameters(); | ||||
| ///Determine whether tasks are actually executed | |||||
| private boolean m_dryRun = false; | |||||
| /** | /** | ||||
| * Main entry point called to run standard Myrmidon. | * Main entry point called to run standard Myrmidon. | ||||
| * | * | ||||
| @@ -132,7 +137,7 @@ public class CLIMain | |||||
| private CLOptionDescriptor[] createCLOptions() | private CLOptionDescriptor[] createCLOptions() | ||||
| { | { | ||||
| //TODO: localise | //TODO: localise | ||||
| final CLOptionDescriptor[] options = new CLOptionDescriptor[ 12 ]; | |||||
| final CLOptionDescriptor[] options = new CLOptionDescriptor[ 13 ]; | |||||
| options[0] = | options[0] = | ||||
| new CLOptionDescriptor( "help", | new CLOptionDescriptor( "help", | ||||
| @@ -210,6 +215,11 @@ public class CLIMain | |||||
| BUILDER_PARAM_OPT, | BUILDER_PARAM_OPT, | ||||
| "Define a builder parameter (ie -Bfoo=var)" ); | "Define a builder parameter (ie -Bfoo=var)" ); | ||||
| options[12] = | |||||
| new CLOptionDescriptor( "dry-run", | |||||
| CLOptionDescriptor.ARGUMENT_DISALLOWED, | |||||
| DRY_RUN_OPT, | |||||
| "Do not execute tasks - just print them out" ); | |||||
| return options; | return options; | ||||
| } | } | ||||
| @@ -259,6 +269,8 @@ public class CLIMain | |||||
| m_builderParameters.setParameter( option.getArgument( 0 ), option.getArgument( 1 ) ); | m_builderParameters.setParameter( option.getArgument( 0 ), option.getArgument( 1 ) ); | ||||
| break; | break; | ||||
| case DRY_RUN_OPT: m_dryRun = true; break; | |||||
| case 0: m_targets.add( option.getArgument() ); break; | case 0: m_targets.add( option.getArgument() ); break; | ||||
| } | } | ||||
| } | } | ||||
| @@ -318,6 +330,12 @@ public class CLIMain | |||||
| //getLogger().debug( "Ant Lib Directory: " + m_libDir ); | //getLogger().debug( "Ant Lib Directory: " + m_libDir ); | ||||
| //getLogger().debug( "Ant Task Lib Directory: " + m_taskLibDir ); | //getLogger().debug( "Ant Task Lib Directory: " + m_taskLibDir ); | ||||
| if( m_dryRun ) | |||||
| { | |||||
| m_parameters.setParameter( Executor.ROLE, | |||||
| "org.apache.myrmidon.components.executor.PrintingExecutor" ); | |||||
| } | |||||
| final Embeddor embeddor = new DefaultEmbeddor(); | final Embeddor embeddor = new DefaultEmbeddor(); | ||||
| setupLogger( embeddor ); | setupLogger( embeddor ); | ||||
| embeddor.parameterize( m_parameters ); | embeddor.parameterize( m_parameters ); | ||||