diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index 42684b9ec9..6759a0a106 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -42,7 +42,6 @@ import org.apache.maven.plugin.PluginManagerException; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.lifecycle.Execution; -import org.apache.maven.plugin.lifecycle.Lifecycle; import org.apache.maven.plugin.lifecycle.Phase; import org.apache.maven.plugin.version.PluginVersionResolutionException; import org.apache.maven.project.MavenProject; @@ -84,12 +83,14 @@ public class DefaultLifecycleExecutor private ExtensionManager extensionManager; - private List phases; + private List lifecycles; private ArtifactHandlerManager artifactHandlerManager; private List defaultReports; + private Map phaseToLifecycleMap; + // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- @@ -416,7 +417,7 @@ public class DefaultLifecycleExecutor // if it's a phase, then we don't need to check whether it's an aggregator. // simply add it to the current task partition. - if ( phases.contains( task ) ) + if ( getPhaseToLifecycleMap().containsKey( task ) ) { if ( currentSegment != null && currentSegment.aggregate() ) { @@ -507,11 +508,13 @@ public class DefaultLifecycleExecutor throws LifecycleExecutionException, ArtifactNotFoundException, MojoExecutionException, ArtifactResolutionException, MojoFailureException { - if ( phases.contains( task ) ) + if ( getPhaseToLifecycleMap().containsKey( task ) ) { + Lifecycle lifecycle = getLifecycleForPhase( task ); + // we have a lifecycle phase, so lets bind all the necessary goals - Map lifecycleMappings = constructLifecycleMappings( session, task, project ); - executeGoalWithLifecycle( task, session, lifecycleMappings, project, response ); + Map lifecycleMappings = constructLifecycleMappings( session, task, project, lifecycle ); + executeGoalWithLifecycle( task, session, lifecycleMappings, project, response, lifecycle ); } else { @@ -520,11 +523,11 @@ public class DefaultLifecycleExecutor } private void executeGoalWithLifecycle( String task, MavenSession session, Map lifecycleMappings, - MavenProject project, MavenExecutionResponse response ) + MavenProject project, MavenExecutionResponse response, Lifecycle lifecycle ) throws ArtifactResolutionException, LifecycleExecutionException, MojoExecutionException, MojoFailureException, ArtifactNotFoundException { - List goals = processGoalChain( task, lifecycleMappings ); + List goals = processGoalChain( task, lifecycleMappings, lifecycle ); executeGoals( goals, session, project, response ); } @@ -759,13 +762,15 @@ public class DefaultLifecycleExecutor Map lifecycleMappings = null; if ( targetPhase != null ) { + Lifecycle lifecycle = getLifecycleForPhase( targetPhase ); + // Create new lifecycle - lifecycleMappings = constructLifecycleMappings( session, targetPhase, project ); + lifecycleMappings = constructLifecycleMappings( session, targetPhase, project, lifecycle ); String executeLifecycle = mojoDescriptor.getExecuteLifecycle(); if ( executeLifecycle != null ) { - Lifecycle lifecycleOverlay; + org.apache.maven.plugin.lifecycle.Lifecycle lifecycleOverlay; try { lifecycleOverlay = pluginDescriptor.getLifecycleMapping( executeLifecycle ); @@ -810,7 +815,9 @@ public class DefaultLifecycleExecutor MavenProject executionProject = new MavenProject( project ); if ( targetPhase != null ) { - executeGoalWithLifecycle( targetPhase, session, lifecycleMappings, executionProject, response ); + Lifecycle lifecycle = getLifecycleForPhase( targetPhase ); + + executeGoalWithLifecycle( targetPhase, session, lifecycleMappings, executionProject, response, lifecycle ); } else { @@ -821,6 +828,18 @@ public class DefaultLifecycleExecutor project.setExecutionProject( executionProject ); } + private Lifecycle getLifecycleForPhase( String phase ) + throws LifecycleExecutionException + { + Lifecycle lifecycle = (Lifecycle) getPhaseToLifecycleMap().get( phase ); + + if ( lifecycle == null ) + { + throw new LifecycleExecutionException( "Unable to find lifecycle for phase '" + phase + "'" ); + } + return lifecycle; + } + private MojoDescriptor getMojoDescriptor( PluginDescriptor pluginDescriptor, String goal ) throws LifecycleExecutionException { @@ -866,11 +885,12 @@ public class DefaultLifecycleExecutor } } - private Map constructLifecycleMappings( MavenSession session, String selectedPhase, MavenProject project ) + private Map constructLifecycleMappings( MavenSession session, String selectedPhase, MavenProject project, + Lifecycle lifecycle ) throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException { // first, bind those associated with the packaging - Map lifecycleMappings = bindLifecycleForPackaging( session, selectedPhase, project ); + 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(); ) @@ -883,14 +903,15 @@ public class DefaultLifecycleExecutor return lifecycleMappings; } - private Map bindLifecycleForPackaging( MavenSession session, String selectedPhase, MavenProject project ) + private Map bindLifecycleForPackaging( MavenSession session, String selectedPhase, MavenProject project, + Lifecycle lifecycle ) throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException { - Map mappings = findMappingsForLifecycle( session, project ); + Map mappings = findMappingsForLifecycle( session, project, lifecycle ); Map lifecycleMappings = new HashMap(); - for ( Iterator i = phases.iterator(); i.hasNext(); ) + for ( Iterator i = lifecycle.getPhases().iterator(); i.hasNext(); ) { String phase = (String) i.next(); @@ -926,16 +947,21 @@ public class DefaultLifecycleExecutor return lifecycleMappings; } - private Map findMappingsForLifecycle( MavenSession session, MavenProject project ) + private Map findMappingsForLifecycle( MavenSession session, MavenProject project, Lifecycle lifecycle ) throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException { String packaging = project.getPackaging(); - LifecycleMapping m; + Map mappings = null; try { - m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, session.getSettings(), - session.getLocalRepository() ); + LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, + session.getSettings(), + session.getLocalRepository() ); + if ( m != null ) + { + mappings = m.getPhases( lifecycle.getId() ); + } } catch ( PluginVersionResolutionException e ) { @@ -948,20 +974,39 @@ public class DefaultLifecycleExecutor "Cannot load extension plugin obtaining lifecycle mappings for: \'" + packaging + "\'.", e ); } - if ( m == null ) + Map defaultMappings = lifecycle.getDefaultPhases(); + + if ( mappings == null ) { try { - m = (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, packaging ); + LifecycleMapping m = (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, packaging ); + mappings = m.getPhases( lifecycle.getId() ); } catch ( ComponentLookupException e ) { - throw new LifecycleExecutionException( - "Cannot find lifecycle mapping for packaging: \'" + packaging + "\'.", e ); + if ( defaultMappings == null ) + { + throw new LifecycleExecutionException( + "Cannot find lifecycle mapping for packaging: \'" + packaging + "\'.", e ); + } } } - return m.getPhases(); + if ( mappings == null ) + { + if ( defaultMappings == null ) + { + throw new LifecycleExecutionException( + "Cannot find lifecycle mapping for packaging: \'" + packaging + "\', and there is no default" ); + } + else + { + mappings = defaultMappings; + } + } + + return mappings; } private Object findExtension( MavenProject project, String role, String roleHint, Settings settings, @@ -1159,16 +1204,16 @@ public class DefaultLifecycleExecutor } } - private List processGoalChain( String task, Map phaseMap ) + private List processGoalChain( String task, Map phaseMap, Lifecycle lifecycle ) { List goals = new ArrayList(); // only execute up to the given phase - int index = phases.indexOf( task ); + int index = lifecycle.getPhases().indexOf( task ); for ( int i = 0; i <= index; i++ ) { - String p = (String) phases.get( i ); + String p = (String) lifecycle.getPhases().get( i ); List phaseGoals = (List) phaseMap.get( p ); @@ -1185,7 +1230,7 @@ public class DefaultLifecycleExecutor throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException { String goal; - Plugin plugin = null; + Plugin plugin; PluginDescriptor pluginDescriptor = null; @@ -1333,6 +1378,38 @@ public class DefaultLifecycleExecutor getLogger().info( "----------------------------------------------------------------------------" ); } + public Map getPhaseToLifecycleMap() + throws LifecycleExecutionException + { + if ( phaseToLifecycleMap == null ) + { + phaseToLifecycleMap = new HashMap(); + + for ( Iterator i = lifecycles.iterator(); i.hasNext(); ) + { + Lifecycle lifecycle = (Lifecycle) i.next(); + + for ( Iterator p = lifecycle.getPhases().iterator(); p.hasNext(); ) + { + String phase = (String) p.next(); + + if ( phaseToLifecycleMap.containsKey( phase ) ) + { + Lifecycle prevLifecycle = (Lifecycle) phaseToLifecycleMap.get( phase ); + throw new LifecycleExecutionException( "Phase '" + phase + + "' is defined in more than one lifecycle: '" + lifecycle.getId() + "' and '" + + prevLifecycle.getId() + "'" ); + } + else + { + phaseToLifecycleMap.put( phase, lifecycle ); + } + } + } + } + return phaseToLifecycleMap; + } + private static class TaskSegment { private boolean aggregate; diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java b/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java new file mode 100644 index 0000000000..90c22e3648 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java @@ -0,0 +1,98 @@ +package org.apache.maven.lifecycle; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed 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.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Class Lifecycle. + */ +public class Lifecycle +{ + /** + * Field id + */ + private String id; + + /** + * Field phases + */ + private List phases; + + /** + * default phases. + */ + private Map defaultPhases; + + /** + * Method addPhase + * + * @param phase + */ + public void addPhase( String phase ) + { + getPhases().add( phase ); + } //-- void addPhase(Phase) + + /** + * Method getId + */ + public String getId() + { + return this.id; + } //-- String getId() + + /** + * Method getPhases + */ + public List getPhases() + { + if ( this.phases == null ) + { + this.phases = new ArrayList(); + } + + return this.phases; + } //-- java.util.List getPhases() + + /** + * Method setId + * + * @param id + */ + public void setId( String id ) + { + this.id = id; + } //-- void setId(String) + + /** + * Method setPhases + * + * @param phases + */ + public void setPhases( List phases ) + { + this.phases = phases; + } //-- void setPhases(java.util.List) + + public Map getDefaultPhases() + { + return defaultPhases; + } +} diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/DefaultLifecycleMapping.java b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/DefaultLifecycleMapping.java index 775bfb55db..a7e12ad71d 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/DefaultLifecycleMapping.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/DefaultLifecycleMapping.java @@ -16,8 +16,10 @@ package org.apache.maven.lifecycle.mapping; * limitations under the License. */ -import java.util.Map; import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; /** * Lifecycle mapping for a POM. @@ -28,10 +30,24 @@ import java.util.HashMap; public class DefaultLifecycleMapping implements LifecycleMapping { - private Map phases = new HashMap(); + private List lifecycles; - public Map getPhases() + private Map lifecycleMap; + + public Map getPhases( String lifecycle ) { - return phases; + if ( lifecycleMap == null ) + { + lifecycleMap = new HashMap(); + + for ( Iterator i = lifecycles.iterator(); i.hasNext(); ) + { + Lifecycle l = (Lifecycle) i.next(); + lifecycleMap.put( l.getId(), l ); + } + } + Lifecycle l = (Lifecycle) lifecycleMap.get( lifecycle ); + return l != null ? l.getPhases() : null; } + } diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/Lifecycle.java b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/Lifecycle.java new file mode 100644 index 0000000000..f05b4b49aa --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/Lifecycle.java @@ -0,0 +1,61 @@ +package org.apache.maven.lifecycle.mapping; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed 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 phases; + + /** + * Method getId + */ + public String getId() + { + return this.id; + } //-- String getId() + + /** + * Method getPhases + */ + public Map getPhases() + { + return this.phases; + } + + /** + * Method setId + * + * @param id + */ + public void setId( String id ) + { + this.id = id; + } //-- void setId(String) +} diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecycleMapping.java b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecycleMapping.java index be291253ef..4bc1457f9d 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecycleMapping.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecycleMapping.java @@ -24,7 +24,7 @@ import java.util.Map; */ public interface LifecycleMapping { - static String ROLE = LifecycleMapping.class.getName(); + String ROLE = LifecycleMapping.class.getName(); - Map getPhases(); + Map getPhases( String lifecycle ); } diff --git a/maven-core/src/main/resources/META-INF/plexus/components.xml b/maven-core/src/main/resources/META-INF/plexus/components.xml index be2011fdfc..a4151fea60 100644 --- a/maven-core/src/main/resources/META-INF/plexus/components.xml +++ b/maven-core/src/main/resources/META-INF/plexus/components.xml @@ -182,40 +182,67 @@ - - - validate - initialize - generate-sources - process-sources - generate-resources - process-resources - compile - process-classes - generate-test-sources - process-test-sources - generate-test-resources - process-test-resources - test-compile - test - package - integration-test - verify - install - deploy - - + + + default + + + validate + initialize + generate-sources + process-sources + generate-resources + process-resources + compile + process-classes + generate-test-sources + process-test-sources + generate-test-resources + process-test-resources + test-compile + test + package + integration-test + verify + install + deploy + + + + + clean + + pre-clean + clean + post-clean + + + org.apache.maven.plugins:maven-clean-plugin:clean + + + + site + + pre-site + site + post-site + + + org.apache.maven.plugins:maven-site-plugin:site + + + - org.apache.maven.plugins:maven-project-info-reports-plugin + org.apache.maven.plugins:maven-project-info-reports-plugin @@ -247,12 +274,17 @@ pom org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping - - - org.apache.maven.plugins:maven-install-plugin:install - org.apache.maven.plugins:maven-deploy-plugin:deploy - - + + + default + + + org.apache.maven.plugins:maven-install-plugin:install + org.apache.maven.plugins:maven-deploy-plugin:deploy + + + + @@ -261,20 +293,26 @@ jar org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping - - - org.apache.maven.plugins:maven-resources-plugin:resources - org.apache.maven.plugins:maven-compiler-plugin:compile - org.apache.maven.plugins:maven-resources-plugin:testResources - org.apache.maven.plugins:maven-compiler-plugin:testCompile - org.apache.maven.plugins:maven-surefire-plugin:test - - org.apache.maven.plugins:maven-jar-plugin:jar - - org.apache.maven.plugins:maven-install-plugin:install - org.apache.maven.plugins:maven-deploy-plugin:deploy - - + + + default + + + org.apache.maven.plugins:maven-resources-plugin:resources + org.apache.maven.plugins:maven-compiler-plugin:compile + + org.apache.maven.plugins:maven-resources-plugin:testResources + org.apache.maven.plugins:maven-compiler-plugin:testCompile + org.apache.maven.plugins:maven-surefire-plugin:test + + org.apache.maven.plugins:maven-jar-plugin:jar + + org.apache.maven.plugins:maven-install-plugin:install + org.apache.maven.plugins:maven-deploy-plugin:deploy + + + + @@ -283,27 +321,33 @@ maven-plugin org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping - - - org.apache.maven.plugins:maven-plugin-plugin:descriptor - org.apache.maven.plugins:maven-resources-plugin:resources - org.apache.maven.plugins:maven-compiler-plugin:compile - org.apache.maven.plugins:maven-resources-plugin:testResources - org.apache.maven.plugins:maven-compiler-plugin:testCompile - org.apache.maven.plugins:maven-surefire-plugin:test - - org.apache.maven.plugins:maven-jar-plugin:jar, - org.apache.maven.plugins:maven-plugin-plugin:addPluginArtifactMetadata - - - org.apache.maven.plugins:maven-install-plugin:install, - org.apache.maven.plugins:maven-plugin-plugin:updateRegistry - - - org.apache.maven.plugins:maven-deploy-plugin:deploy - - - + + + default + + + org.apache.maven.plugins:maven-plugin-plugin:descriptor + org.apache.maven.plugins:maven-resources-plugin:resources + org.apache.maven.plugins:maven-compiler-plugin:compile + + org.apache.maven.plugins:maven-resources-plugin:testResources + org.apache.maven.plugins:maven-compiler-plugin:testCompile + org.apache.maven.plugins:maven-surefire-plugin:test + + org.apache.maven.plugins:maven-jar-plugin:jar, + org.apache.maven.plugins:maven-plugin-plugin:addPluginArtifactMetadata + + + org.apache.maven.plugins:maven-install-plugin:install, + org.apache.maven.plugins:maven-plugin-plugin:updateRegistry + + + org.apache.maven.plugins:maven-deploy-plugin:deploy + + + + + @@ -312,20 +356,26 @@ ejb org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping - - - org.apache.maven.plugins:maven-resources-plugin:resources - org.apache.maven.plugins:maven-compiler-plugin:compile - org.apache.maven.plugins:maven-resources-plugin:testResources - org.apache.maven.plugins:maven-compiler-plugin:testCompile - org.apache.maven.plugins:maven-surefire-plugin:test - - org.apache.maven.plugins:maven-ejb-plugin:ejb - - org.apache.maven.plugins:maven-install-plugin:install - org.apache.maven.plugins:maven-deploy-plugin:deploy - - + + + default + + + org.apache.maven.plugins:maven-resources-plugin:resources + org.apache.maven.plugins:maven-compiler-plugin:compile + + org.apache.maven.plugins:maven-resources-plugin:testResources + org.apache.maven.plugins:maven-compiler-plugin:testCompile + org.apache.maven.plugins:maven-surefire-plugin:test + + org.apache.maven.plugins:maven-ejb-plugin:ejb + + org.apache.maven.plugins:maven-install-plugin:install + org.apache.maven.plugins:maven-deploy-plugin:deploy + + + + @@ -334,18 +384,24 @@ war org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping - - - org.apache.maven.plugins:maven-resources-plugin:resources - org.apache.maven.plugins:maven-compiler-plugin:compile - org.apache.maven.plugins:maven-resources-plugin:testResources - org.apache.maven.plugins:maven-compiler-plugin:testCompile - org.apache.maven.plugins:maven-surefire-plugin:test - org.apache.maven.plugins:maven-war-plugin:war - org.apache.maven.plugins:maven-install-plugin:install - org.apache.maven.plugins:maven-deploy-plugin:deploy - - + + + default + + + org.apache.maven.plugins:maven-resources-plugin:resources + org.apache.maven.plugins:maven-compiler-plugin:compile + + org.apache.maven.plugins:maven-resources-plugin:testResources + org.apache.maven.plugins:maven-compiler-plugin:testCompile + org.apache.maven.plugins:maven-surefire-plugin:test + org.apache.maven.plugins:maven-war-plugin:war + org.apache.maven.plugins:maven-install-plugin:install + org.apache.maven.plugins:maven-deploy-plugin:deploy + + + + @@ -354,15 +410,21 @@ ear org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping - - - org.apache.maven.plugins:maven-ear-plugin:generate-application-xml - org.apache.maven.plugins:maven-resources-plugin:resources - org.apache.maven.plugins:maven-ear-plugin:ear - org.apache.maven.plugins:maven-install-plugin:install - org.apache.maven.plugins:maven-deploy-plugin:deploy - - + + + default + + + + org.apache.maven.plugins:maven-ear-plugin:generate-application-xml + org.apache.maven.plugins:maven-resources-plugin:resources + org.apache.maven.plugins:maven-ear-plugin:ear + org.apache.maven.plugins:maven-install-plugin:install + org.apache.maven.plugins:maven-deploy-plugin:deploy + + + + @@ -371,18 +433,24 @@ rar org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping - - - org.apache.maven.plugins:maven-resources-plugin:resources - org.apache.maven.plugins:maven-compiler-plugin:compile - org.apache.maven.plugins:maven-resources-plugin:testResources - org.apache.maven.plugins:maven-compiler-plugin:testCompile - org.apache.maven.plugins:maven-surefire-plugin:test - org.apache.maven.plugins:maven-rar-plugin:rar - org.apache.maven.plugins:maven-install-plugin:install - org.apache.maven.plugins:maven-deploy-plugin:deploy - - + + + default + + + org.apache.maven.plugins:maven-resources-plugin:resources + org.apache.maven.plugins:maven-compiler-plugin:compile + + org.apache.maven.plugins:maven-resources-plugin:testResources + org.apache.maven.plugins:maven-compiler-plugin:testCompile + org.apache.maven.plugins:maven-surefire-plugin:test + org.apache.maven.plugins:maven-rar-plugin:rar + org.apache.maven.plugins:maven-install-plugin:install + org.apache.maven.plugins:maven-deploy-plugin:deploy + + + +