Author: jvanzyl Date: Mon Mar 23 01:27:27 2009 New Revision: 757293 URL: http://svn.apache.org/viewvc?rev=757293&view=rev Log: o lifecycle executor now strictly deals with plugins, and is 500 lines (still needs to be smaller) and is getting a lot more efficient
Added: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/ maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/DefaultLifecycleMapping.java - copied, changed from r757275, maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleMapping.java maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/Lifecycle.java (with props) maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecycleMapping.java - copied, changed from r757275, maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleMapping.java maven/components/branches/MNG-2766/maven-core/src/test/projects/ maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/ maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/ maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/pom.xml (with props) maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/ maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/main/ maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/main/java/ maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/main/java/org/ maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/main/java/org/apache/ maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/main/java/org/apache/maven/ maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/main/java/org/apache/maven/lifecycle/ maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/main/java/org/apache/maven/lifecycle/test/ maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/main/java/org/apache/maven/lifecycle/test/App.java (with props) maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/test/ maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/test/java/ maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/test/java/org/ maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/test/java/org/apache/ maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/test/java/org/apache/maven/ maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/test/java/org/apache/maven/lifecycle/ maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/test/java/org/apache/maven/lifecycle/test/ maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/test/java/org/apache/maven/lifecycle/test/AppTest.java (with props) Removed: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleMapping.java maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleMapping.java Modified: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java maven/components/branches/MNG-2766/maven-core/src/main/resources/META-INF/plexus/artifact-handlers.xml maven/components/branches/MNG-2766/maven-core/src/main/resources/META-INF/plexus/components.xml Modified: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java?rev=757293&r1=757292&r2=757293&view=diff ============================================================================== --- maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java (original) +++ maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java Mon Mar 23 01:27:27 2009 @@ -111,7 +111,7 @@ return request.getLocalRepository(); } - public List getGoals() + public List<String> getGoals() { return request.getGoals(); } Modified: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java?rev=757293&r1=757292&r2=757293&view=diff ============================================================================== --- maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java (original) +++ maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java Mon Mar 23 01:27:27 2009 @@ -18,36 +18,25 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.StringTokenizer; import org.apache.maven.BuildFailureException; -import org.apache.maven.artifact.resolver.ArtifactNotFoundException; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.ReactorManager; +import org.apache.maven.lifecycle.mapping.LifecycleMapping; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; -import org.apache.maven.model.ReportPlugin; -import org.apache.maven.model.ReportSet; import org.apache.maven.monitor.event.EventDispatcher; import org.apache.maven.monitor.event.MavenEvents; import org.apache.maven.plugin.InvalidPluginException; -import org.apache.maven.plugin.MojoExecution; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugin.PluginConfigurationException; import org.apache.maven.plugin.PluginLoaderException; import org.apache.maven.plugin.PluginManager; -import org.apache.maven.plugin.PluginManagerException; -import org.apache.maven.plugin.PluginNotFoundException; -import org.apache.maven.plugin.PluginVersionNotFoundException; -import org.apache.maven.plugin.PluginVersionResolutionException; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; -import org.apache.maven.reporting.MavenReport; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; @@ -68,8 +57,6 @@ private List<Lifecycle> lifecycles; - private List defaultReports; - private Map<String, Lifecycle> phaseToLifecycleMap; @Requirement @@ -89,7 +76,7 @@ // within the same reactor (using an inclusion pattern to gather them up)... MavenProject rootProject = rm.getTopLevelProject(); - List goals = session.getGoals(); + List<String> goals = session.getGoals(); if ( goals.isEmpty() && rootProject != null ) { @@ -115,7 +102,7 @@ { if ( lifecycle.getId().equals( "default" ) ) { - return (List<String>) lifecycle.getPhases().values(); + return (List<String>) lifecycle.getPhases(); } } @@ -283,6 +270,8 @@ // 1. Find the lifecycle given the phase (default lifecycle when given install) // 2. Find the lifecycle mapping that corresponds to the project packaging (jar lifecycle mapping given the jar packaging) // 3. Find the mojos associated with the lifecycle given the project packaging (jar lifecycle mapping for the default lifecycle) + // 4. Bind those mojos found in the lifecycle mapping for the packaging to the lifecycle + // 5. Bind mojos specified in the project itself to the lifecycle private void executeGoal( String task, MavenSession session, MavenProject project ) throws LifecycleExecutionException, BuildFailureException { @@ -290,457 +279,103 @@ Lifecycle lifecycle = phaseToLifecycleMap.get( task ); // 2. - LifecycleMapping mapping = lifecycleMappings.get( project.getPackaging() ); + LifecycleMapping lifecycleMappingForPackaging = lifecycleMappings.get( project.getPackaging() ); // 3. - Map<String,String> lifecyclePhases = mapping.getLifecycles().get( "default" ).getPhases(); + Map<String, String> lifecyclePhasesForPackaging = lifecycleMappingForPackaging.getLifecycles().get( "default" ).getPhases(); - for( String phase : lifecycle.getPhases().values() ) - { - System.out.println( ">> " + phase ); - } - - /* - try - { - if ( lifecycle != null ) - { - Map lifecycleMappings = constructLifecycleMappings( session, task, project, lifecycle ); - - executeGoalWithLifecycle( task, session, lifecycleMappings, project, lifecycle ); - } - else - { - executeStandaloneGoal( task, session, project ); - } - } - catch ( PluginNotFoundException e ) - { - throw new BuildFailureException( "A required plugin was not found: " + e.getMessage(), e ); - } - */ - } - - /* - private void executeGoalWithLifecycle( String task, MavenSession session, Map lifecycleMappings, MavenProject project, Lifecycle lifecycle ) - throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException - { - List goals = new ArrayList(); - - // only execute up to the given phase - int index = lifecycle.getPhases().indexOf( task ); - - for ( int i = 0; i <= index; i++ ) - { - String p = (String) lifecycle.getPhases().get( i ); - - List phaseGoals = (List) lifecycleMappings.get( p ); - - if ( phaseGoals != null ) - { - goals.addAll( phaseGoals ); - } - } - - if ( !goals.isEmpty() ) - { - executeGoals( goals, session, project ); - } - else - { - getLogger().info( "No goals needed for project - skipping" ); - } - } - */ - - private void executeStandaloneGoal( String task, MavenSession session, MavenProject project ) - throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException - { - // guaranteed to come from the CLI and not be part of a phase - MojoDescriptor mojoDescriptor = getMojoDescriptor( task, session, project ); - executeGoals( Collections.singletonList( new MojoExecution( mojoDescriptor ) ), session, project ); - } - - private void executeGoals( List<MojoExecution> goals, MavenSession session, MavenProject project ) - throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException - { - for ( MojoExecution mojoExecution : goals ) - { - MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); - - if ( mojoDescriptor.isRequiresReports() ) - { - List reports = getReports( project, mojoExecution, session ); - - mojoExecution.setReports( reports ); - } - - try - { - pluginManager.executeMojo( project, mojoExecution, session ); - } - catch ( PluginManagerException e ) - { - throw new LifecycleExecutionException( "Internal error in the plugin manager executing goal '" + mojoDescriptor.getId() + "': " + e.getMessage(), e ); - } - catch ( MojoFailureException e ) - { - throw new BuildFailureException( e.getMessage(), e ); - } - catch ( PluginConfigurationException e ) + // Create an order Map of the phases in the lifecycle to a list of mojos to execute. + Map<String,List<String>> phaseToMojoMapping = new LinkedHashMap<String,List<String>>(); + + // 4. + for ( String phase : lifecycle.getPhases() ) + { + List<String> mojos = new ArrayList<String>(); + + // Bind the mojos in the lifecycle mapping for the packaging to the lifecycle itself. If + // we can find the specified phase in the packaging them grab those mojos and add them to + // the list we are going to execute. + String mojo = lifecyclePhasesForPackaging.get( phase ); + + if ( mojo != null ) + { + mojos.add( mojo ); + } + + phaseToMojoMapping.put( phase, mojos ); + + // We only want to execute up to and including the specified lifecycle phase. + if ( phase.equals( task ) ) { - throw new LifecycleExecutionException( e.getMessage(), e ); + break; } } - } - - private List getReports( MavenProject project, MojoExecution mojoExecution, MavenSession session ) - throws LifecycleExecutionException, PluginNotFoundException - { - List reportPlugins = project.getReportPlugins(); - - if ( project.getModel().getReports() != null ) - { - getLogger().error( "Plugin contains a <reports/> section: this is IGNORED - please use <reporting/> instead." ); - } - - if ( project.getReporting() == null || !project.getReporting().isExcludeDefaults() ) + + // 5. + + for( Plugin plugin : project.getBuild().getPlugins() ) { - if ( reportPlugins == null ) - { - reportPlugins = new ArrayList(); - } - else - { - reportPlugins = new ArrayList( reportPlugins ); - } - - for ( Iterator i = defaultReports.iterator(); i.hasNext(); ) + for( PluginExecution execution : plugin.getExecutions() ) { - String report = (String) i.next(); - - StringTokenizer tok = new StringTokenizer( report, ":" ); - int count = tok.countTokens(); - if ( count != 2 && count != 3 ) - { - getLogger().warn( "Invalid default report ignored: '" + report + "' (must be groupId:artifactId[:version])" ); - } - else + // if the phase is specified then I don't have to go fetch the plugin yet and pull it down + // to examine the phase it is associated to. + if ( execution.getPhase() != null ) { - String groupId = tok.nextToken(); - String artifactId = tok.nextToken(); - String version = tok.hasMoreTokens() ? tok.nextToken() : null; - - boolean found = false; - for ( Iterator j = reportPlugins.iterator(); j.hasNext() && !found; ) + for( String goal : execution.getGoals() ) { - ReportPlugin reportPlugin = (ReportPlugin) j.next(); - if ( reportPlugin.getGroupId().equals( groupId ) && reportPlugin.getArtifactId().equals( artifactId ) ) - { - found = true; - } + String s = plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion() + ":" + goal; + phaseToMojoMapping.get( execution.getPhase() ).add( s ); } - - if ( !found ) - { - ReportPlugin reportPlugin = new ReportPlugin(); - reportPlugin.setGroupId( groupId ); - reportPlugin.setArtifactId( artifactId ); - reportPlugin.setVersion( version ); - reportPlugins.add( reportPlugin ); - } - } - } - } - - List reports = new ArrayList(); - if ( reportPlugins != null ) - { - for ( Iterator it = reportPlugins.iterator(); it.hasNext(); ) - { - ReportPlugin reportPlugin = (ReportPlugin) it.next(); - - List reportSets = reportPlugin.getReportSets(); - - if ( reportSets == null || reportSets.isEmpty() ) - { - reports.addAll( getReports( reportPlugin, null, project, session, mojoExecution ) ); - } + + } + // if not then i need to grab the mojo descriptor and look at + // the phase that is specified else { - for ( Iterator j = reportSets.iterator(); j.hasNext(); ) + for( String goal : execution.getGoals() ) { - ReportSet reportSet = (ReportSet) j.next(); - - reports.addAll( getReports( reportPlugin, reportSet, project, session, mojoExecution ) ); + String s = plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion() + ":" + goal; + MojoDescriptor md = getMojoDescriptor( s, session, project); + phaseToMojoMapping.get( md.getPhase() ).add( s ); } } } } - return reports; - } - - private List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, MavenSession session, MojoExecution mojoExecution ) - throws LifecycleExecutionException, PluginNotFoundException - { - PluginDescriptor pluginDescriptor = loadReport( reportPlugin, project, session ); - - List reports = new ArrayList(); - - for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext(); ) + + // We need to turn this into a set of MojoExecutions + for( List<String> mojos : phaseToMojoMapping.values() ) { - MojoDescriptor mojoDescriptor = (MojoDescriptor) i.next(); - - // TODO: check ID is correct for reports - // if the POM configured no reports, give all from plugin - if ( reportSet == null || reportSet.getReports().contains( mojoDescriptor.getGoal() ) ) + for( String mojo : mojos ) { - String id = null; - if ( reportSet != null ) - { - id = reportSet.getId(); - } - - MojoExecution reportExecution = new MojoExecution( mojoDescriptor, id ); - - try - { - MavenReport reportMojo = pluginManager.getReport( project, reportExecution, session ); - - // Comes back null if it was a plugin, not a report - these are mojos in the reporting plugins that are not reports - if ( reportMojo != null ) - { - reports.add( reportMojo ); - - mojoExecution.addMojoExecution( reportExecution ); - } - } - catch ( PluginManagerException e ) - { - throw new LifecycleExecutionException( "Error getting reports from the plugin '" + reportPlugin.getKey() + "': " + e.getMessage(), e ); - } - catch ( PluginConfigurationException e ) - { - throw new LifecycleExecutionException( "Error getting reports from the plugin '" + reportPlugin.getKey() + "'", e ); - } - catch ( ArtifactNotFoundException e ) - { - throw new LifecycleExecutionException( e.getMessage(), e ); - } - catch ( ArtifactResolutionException e ) - { - throw new LifecycleExecutionException( e.getMessage(), e ); - } + System.out.println( ">> " + mojo ); } - } - return reports; - } - - /* - private Map constructLifecycleMappings( MavenSession session, String selectedPhase, MavenProject project, Lifecycle lifecycle ) - throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException - { - // first, bind those associated with the packaging - Map lifecycleMappings = bindLifecycleForPackaging( session, selectedPhase, project, lifecycle ); - - // next, loop over plugins and for any that have a phase, bind it - for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); ) - { - Plugin plugin = (Plugin) i.next(); - - bindPluginToLifecycle( plugin, session, lifecycleMappings, project ); - } - - return lifecycleMappings; - } - */ - - /* - private Map bindLifecycleForPackaging( MavenSession session, String selectedPhase, MavenProject project, Lifecycle lifecycle ) - throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException - { - Map mappings = findMappingsForLifecycle( session, project, lifecycle ); - - Map lifecycleMappings = new HashMap(); - - for ( Iterator i = lifecycle.getPhases().iterator(); i.hasNext(); ) - { - String phase = (String) i.next(); - - String phaseTasks = (String) mappings.get( phase ); - - if ( phaseTasks != null ) - { - for ( StringTokenizer tok = new StringTokenizer( phaseTasks, "," ); tok.hasMoreTokens(); ) - { - String goal = tok.nextToken().trim(); - - // Not from the CLI, don't use prefix - MojoDescriptor mojoDescriptor = getMojoDescriptor( goal, session, project ); - - if ( mojoDescriptor == null ) - { - continue; - } - - if ( mojoDescriptor.isDirectInvocationOnly() ) - { - throw new LifecycleExecutionException( "Mojo: \'" + goal + "\' requires direct invocation. It cannot be used as part of lifecycle: \'" + project.getPackaging() + "\'." ); - } - - addToLifecycleMappings( lifecycleMappings, phase, new MojoExecution( mojoDescriptor ), session ); - } - } - - if ( phase.equals( selectedPhase ) ) - { - break; - } - } - - return lifecycleMappings; - } - */ - - private Map findMappingsForLifecycle( MavenSession session, MavenProject project, Lifecycle lifecycle ) - throws LifecycleExecutionException, PluginNotFoundException - { - String packaging = project.getPackaging(); - Map mappings = null; - - LifecycleMapping m; - - Map defaultMappings = lifecycle.getDefaultPhases(); - - if ( mappings == null ) + } + + /* + for ( MojoExecution mojoExecution : goals ) { - m = lifecycleMappings.get( packaging ); - - mappings = null; //m.getLifecycles().get( lifecycle.getId() ); - } + MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); - if ( mappings == null ) - { - if ( defaultMappings == null ) - { - throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: \'" + packaging + "\', and there is no default" ); - } - else + try { - mappings = defaultMappings; + pluginManager.executeMojo( project, mojoExecution, session ); } - } - - return mappings; - } - - /** - * Take each mojo contained with a plugin, look to see whether it contributes to a phase in the - * lifecycle and if it does place it at the end of the list of goals to execute for that given - * phase. - * - * @param project - * @param session - * @throws PluginVersionNotFoundException - * @throws PluginManagerException - * @throws InvalidPluginException - * @throws PluginVersionResolutionException - * @throws ArtifactNotFoundException - * @throws ArtifactResolutionException - */ - private void bindPluginToLifecycle( Plugin plugin, MavenSession session, Map phaseMap, MavenProject project ) - throws LifecycleExecutionException - { - PluginDescriptor pluginDescriptor = loadPlugin( plugin, project, session ); - - if ( pluginDescriptor.getMojos() != null && !pluginDescriptor.getMojos().isEmpty() ) - { - // use the plugin if inherit was true in a base class, or it is in the current POM, otherwise use the default inheritence setting - if ( plugin.isInheritanceApplied() || pluginDescriptor.isInheritedByDefault() ) + catch ( PluginManagerException e ) { - if ( plugin.getGoals() != null ) - { - getLogger().error( "Plugin contains a <goals/> section: this is IGNORED - please use <executions/> instead." ); - } - - List executions = plugin.getExecutions(); - - if ( executions != null ) - { - for ( Iterator it = executions.iterator(); it.hasNext(); ) - { - PluginExecution execution = (PluginExecution) it.next(); - - bindExecutionToLifecycle( pluginDescriptor, phaseMap, execution, session ); - } - } + throw new LifecycleExecutionException( "Internal error in the plugin manager executing goal '" + mojoDescriptor.getId() + "': " + e.getMessage(), e ); } - } - } - - private void bindExecutionToLifecycle( PluginDescriptor pluginDescriptor, Map phaseMap, PluginExecution execution, MavenSession session ) - throws LifecycleExecutionException - { - for ( Iterator i = execution.getGoals().iterator(); i.hasNext(); ) - { - String goal = (String) i.next(); - - MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal ); - if ( mojoDescriptor == null ) + catch ( MojoFailureException e ) { - throw new LifecycleExecutionException( "'" + goal + "' was specified in an execution, but not found in the plugin" ); + throw new BuildFailureException( e.getMessage(), e ); } - - // We have to check to see that the inheritance rules have been applied before binding this mojo. - if ( execution.isInheritanceApplied() || mojoDescriptor.isInheritedByDefault() ) + catch ( PluginConfigurationException e ) { - MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, execution.getId() ); - - String phase = execution.getPhase(); - - if ( phase == null ) - { - // if the phase was not in the configuration, use the phase in the descriptor - phase = mojoDescriptor.getPhase(); - } - - if ( phase != null ) - { - if ( mojoDescriptor.isDirectInvocationOnly() ) - { - throw new LifecycleExecutionException( "Mojo: \'" + goal + "\' requires direct invocation. It cannot be used as part of the lifecycle (it was included via the POM)." ); - } - - addToLifecycleMappings( phaseMap, phase, mojoExecution, session ); - } + throw new LifecycleExecutionException( e.getMessage(), e ); } - } + } + */ } - private void addToLifecycleMappings( Map lifecycleMappings, String phase, MojoExecution mojoExecution, MavenSession session ) - { - List goals = (List) lifecycleMappings.get( phase ); - - if ( goals == null ) - { - goals = new ArrayList(); - lifecycleMappings.put( phase, goals ); - } - - MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); - if ( session.isOffline() && mojoDescriptor.isOnlineRequired() ) - { - String goal = mojoDescriptor.getGoal(); - getLogger().warn( goal + " requires online mode, but maven is currently offline. Disabling " + goal + "." ); - } - else - { - goals.add( mojoExecution ); - } - } - - // all this logic should go to the plugin manager - MojoDescriptor getMojoDescriptor( String task, MavenSession session, MavenProject project ) throws LifecycleExecutionException { @@ -749,7 +384,7 @@ StringTokenizer tok = new StringTokenizer( task, ":" ); int numTokens = tok.countTokens(); - + if ( numTokens == 2 ) { String prefix = tok.nextToken(); @@ -769,10 +404,8 @@ // Search plugin in the current POM if ( plugin == null ) { - for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); ) + for ( Plugin buildPlugin : project.getBuildPlugins() ) { - Plugin buildPlugin = (Plugin) i.next(); - PluginDescriptor desc = loadPlugin( buildPlugin, project, session ); if ( prefix.equals( desc.getGoalPrefix() ) ) @@ -803,10 +436,8 @@ if ( plugin.getVersion() == null ) { - for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); ) + for ( Plugin buildPlugin : project.getBuildPlugins() ) { - Plugin buildPlugin = (Plugin) i.next(); - if ( buildPlugin.getKey().equals( plugin.getKey() ) ) { plugin = buildPlugin; @@ -845,35 +476,18 @@ } } - private PluginDescriptor loadReport( ReportPlugin plugin, MavenProject project, MavenSession session ) - throws LifecycleExecutionException - { - try - { - return pluginManager.loadReportPlugin( plugin, project, session ); - } - catch ( PluginLoaderException e ) - { - throw new LifecycleExecutionException( e.getMessage(), e ); - } - } - public void initialize() throws InitializationException { // If people are going to make their own lifecycles then we need to tell people how to namespace them correctly so // that they don't interfere with internally defined lifecycles. - phaseToLifecycleMap = new HashMap(); + phaseToLifecycleMap = new HashMap<String,Lifecycle>(); - for ( Iterator i = lifecycles.iterator(); i.hasNext(); ) + for ( Lifecycle lifecycle : lifecycles ) { - Lifecycle lifecycle = (Lifecycle) i.next(); - - for ( Iterator p = lifecycle.getPhases().values().iterator(); p.hasNext(); ) + for ( String phase : lifecycle.getPhases() ) { - String phase = (String) p.next(); - // The first definition wins. if ( !phaseToLifecycleMap.containsKey( phase ) ) { Modified: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java?rev=757293&r1=757292&r2=757293&view=diff ============================================================================== --- maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java (original) +++ maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java Mon Mar 23 01:27:27 2009 @@ -19,66 +19,31 @@ * under the License. */ -import java.util.Map; +import java.util.List; /** * Class Lifecycle. */ public class Lifecycle { - /** - * Field id - */ private String id; - /** - * Field phases - */ - private Map<String,String> phases; - - /** - * default phases. - */ - private Map defaultPhases; + private List<String> phases; + + private List<String> defaultPhases; - /** - * Method getId - */ public String getId() { return this.id; } - /** - * Method getPhases - */ - public Map<String,String> getPhases() + public List<String> getPhases() { return this.phases; } - - /** - * Method setId - * - * @param id - */ - public void setId( String id ) - { - this.id = id; - } - - /** - * Method setPhases - * - * @param phases - */ - public void setPhases( Map<String,String> phases ) - { - this.phases = phases; - } //-- void setPhases(java.util.List) - - public Map getDefaultPhases() + + public List<String> getDefaultPhases() { return defaultPhases; - } + } } Copied: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/DefaultLifecycleMapping.java (from r757275, maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleMapping.java) URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/DefaultLifecycleMapping.java?p2=maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/DefaultLifecycleMapping.java&p1=maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleMapping.java&r1=757275&r2=757293&rev=757293&view=diff ============================================================================== --- maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleMapping.java (original) +++ maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/DefaultLifecycleMapping.java Mon Mar 23 01:27:27 2009 @@ -1,4 +1,4 @@ -package org.apache.maven.lifecycle; +package org.apache.maven.lifecycle.mapping; /* * Licensed to the Apache Software Foundation (ASF) under one or more contributor license @@ -19,8 +19,6 @@ import java.util.List; import java.util.Map; -import org.apache.maven.lifecycle.Lifecycle; - public class DefaultLifecycleMapping implements LifecycleMapping { Added: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/Lifecycle.java URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/Lifecycle.java?rev=757293&view=auto ============================================================================== --- maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/Lifecycle.java (added) +++ maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/Lifecycle.java Mon Mar 23 01:27:27 2009 @@ -0,0 +1,84 @@ +package org.apache.maven.lifecycle.mapping; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.Map; + +/** + * Class Lifecycle. + */ +public class Lifecycle +{ + /** + * Field id + */ + private String id; + + /** + * Field phases + */ + private Map<String,String> phases; + + /** + * default phases. + */ + private Map defaultPhases; + + /** + * Method getId + */ + public String getId() + { + return this.id; + } + + /** + * Method getPhases + */ + public Map<String,String> getPhases() + { + return this.phases; + } + + /** + * Method setId + * + * @param id + */ + public void setId( String id ) + { + this.id = id; + } + + /** + * Method setPhases + * + * @param phases + */ + public void setPhases( Map<String,String> phases ) + { + this.phases = phases; + } //-- void setPhases(java.util.List) + + public Map getDefaultPhases() + { + return defaultPhases; + } +} Propchange: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/Lifecycle.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/Lifecycle.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Copied: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecycleMapping.java (from r757275, maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleMapping.java) URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecycleMapping.java?p2=maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecycleMapping.java&p1=maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleMapping.java&r1=757275&r2=757293&rev=757293&view=diff ============================================================================== --- maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleMapping.java (original) +++ maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecycleMapping.java Mon Mar 23 01:27:27 2009 @@ -1,4 +1,4 @@ -package org.apache.maven.lifecycle; +package org.apache.maven.lifecycle.mapping; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -21,8 +21,6 @@ import java.util.Map; -import org.apache.maven.lifecycle.Lifecycle; - public interface LifecycleMapping { Map<String,Lifecycle> getLifecycles(); Modified: maven/components/branches/MNG-2766/maven-core/src/main/resources/META-INF/plexus/artifact-handlers.xml URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/main/resources/META-INF/plexus/artifact-handlers.xml?rev=757293&r1=757292&r2=757293&view=diff ============================================================================== --- maven/components/branches/MNG-2766/maven-core/src/main/resources/META-INF/plexus/artifact-handlers.xml (original) +++ maven/components/branches/MNG-2766/maven-core/src/main/resources/META-INF/plexus/artifact-handlers.xml Mon Mar 23 01:27:27 2009 @@ -25,9 +25,9 @@ </configuration> </component> <component> - <role>org.apache.maven.lifecycle.LifecycleMapping</role> + <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role> <role-hint>pom</role-hint> - <implementation>org.apache.maven.lifecycle.DefaultLifecycleMapping</implementation> + <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation> <configuration> <lifecycles> <lifecycle> @@ -58,9 +58,9 @@ </configuration> </component> <component> - <role>org.apache.maven.lifecycle.LifecycleMapping</role> + <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role> <role-hint>jar</role-hint> - <implementation>org.apache.maven.lifecycle.DefaultLifecycleMapping</implementation> + <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation> <configuration> <lifecycles> <lifecycle> @@ -98,10 +98,10 @@ </configuration> </component> <component> - <role>org.apache.maven.lifecycle.LifecycleMapping + <role>org.apache.maven.lifecycle.mapping.LifecycleMapping </role> <role-hint>ejb</role-hint> - <implementation>org.apache.maven.lifecycle.DefaultLifecycleMapping + <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping </implementation> <configuration> <lifecycles> @@ -160,9 +160,9 @@ </configuration> </component> <component> - <role>org.apache.maven.lifecycle.LifecycleMapping</role> + <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role> <role-hint>ejb3</role-hint> - <implementation>org.apache.maven.lifecycle.DefaultLifecycleMapping</implementation> + <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation> <configuration> <!-- START SNIPPET: ejb3-lifecycle --> <phases> @@ -215,9 +215,9 @@ </configuration> </component> <component> - <role>org.apache.maven.lifecycle.LifecycleMapping</role> + <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role> <role-hint>maven-plugin</role-hint> - <implementation>org.apache.maven.lifecycle.DefaultLifecycleMapping</implementation> + <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation> <configuration> <lifecycles> <lifecycle> @@ -300,9 +300,9 @@ </configuration> </component> <component> - <role>org.apache.maven.lifecycle.LifecycleMapping</role> + <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role> <role-hint>war</role-hint> - <implementation>org.apache.maven.lifecycle.DefaultLifecycleMapping</implementation> + <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation> <configuration> <lifecycles> <lifecycle> @@ -342,9 +342,9 @@ </configuration> </component> <component> - <role>org.apache.maven.lifecycle.LifecycleMapping</role> + <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role> <role-hint>ear</role-hint> - <implementation>org.apache.maven.lifecycle.DefaultLifecycleMapping</implementation> + <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation> <configuration> <lifecycles> <lifecycle> @@ -381,9 +381,9 @@ </configuration> </component> <component> - <role>org.apache.maven.lifecycle.LifecycleMapping</role> + <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role> <role-hint>rar</role-hint> - <implementation>org.apache.maven.lifecycle.DefaultLifecycleMapping</implementation> + <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation> <configuration> <lifecycles> <lifecycle> @@ -423,9 +423,9 @@ </configuration> </component> <component> - <role>org.apache.maven.lifecycle.LifecycleMapping</role> + <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role> <role-hint>par</role-hint> - <implementation>org.apache.maven.lifecycle.DefaultLifecycleMapping</implementation> + <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation> <configuration> <!-- START SNIPPET: par-lifecycle --> <phases> Modified: maven/components/branches/MNG-2766/maven-core/src/main/resources/META-INF/plexus/components.xml URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/main/resources/META-INF/plexus/components.xml?rev=757293&r1=757292&r2=757293&view=diff ============================================================================== --- maven/components/branches/MNG-2766/maven-core/src/main/resources/META-INF/plexus/components.xml (original) +++ maven/components/branches/MNG-2766/maven-core/src/main/resources/META-INF/plexus/components.xml Mon Mar 23 01:27:27 2009 @@ -38,7 +38,7 @@ <role>org.apache.maven.plugin.PluginManager</role> </requirement> <requirement> - <role>org.apache.maven.lifecycle.LifecycleMapping</role> + <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role> <field-name>lifecycleMappings</field-name> </requirement> </requirements> Added: maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/pom.xml URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/pom.xml?rev=757293&view=auto ============================================================================== --- maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/pom.xml (added) +++ maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/pom.xml Mon Mar 23 01:27:27 2009 @@ -0,0 +1,35 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.maven.lifecycle.test</groupId> + <artifactId>project-with-additional-lifecycle-elements</artifactId> + <packaging>jar</packaging> + <version>1.0-SNAPSHOT</version> + <name>project-with-additional-lifecycle-elements</name> + <url>http://maven.apache.org</url> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-component-metadata</artifactId> + <version>1.0-beta-3.0.6</version> + <executions> + <execution> + <goals> + <goal>generate-metadata</goal> + <goal>generate-test-metadata</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> Propchange: maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/pom.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/main/java/org/apache/maven/lifecycle/test/App.java URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/main/java/org/apache/maven/lifecycle/test/App.java?rev=757293&view=auto ============================================================================== --- maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/main/java/org/apache/maven/lifecycle/test/App.java (added) +++ maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/main/java/org/apache/maven/lifecycle/test/App.java Mon Mar 23 01:27:27 2009 @@ -0,0 +1,13 @@ +package org.apache.maven.lifecycle.test; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} Propchange: maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/main/java/org/apache/maven/lifecycle/test/App.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/main/java/org/apache/maven/lifecycle/test/App.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/test/java/org/apache/maven/lifecycle/test/AppTest.java URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/test/java/org/apache/maven/lifecycle/test/AppTest.java?rev=757293&view=auto ============================================================================== --- maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/test/java/org/apache/maven/lifecycle/test/AppTest.java (added) +++ maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/test/java/org/apache/maven/lifecycle/test/AppTest.java Mon Mar 23 01:27:27 2009 @@ -0,0 +1,38 @@ +package org.apache.maven.lifecycle.test; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} Propchange: maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/test/java/org/apache/maven/lifecycle/test/AppTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/components/branches/MNG-2766/maven-core/src/test/projects/lifecycle-executor/project-with-additional-lifecycle-elements/src/test/java/org/apache/maven/lifecycle/test/AppTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision