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 2e775dd1fb..7ac0c5ca07 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 @@ -22,15 +22,22 @@ import java.util.Map; public class DefaultLifecycleMapping implements LifecycleMapping { + private List lifecycles; private Map lifecycleMap; - public Map getLifecycles() + /** @deprecated use lifecycles instead */ + private Map phases; + + /** + * Populates the lifecycle map from the injected list of lifecycle mappings (if not already done). + */ + private void initLifecycleMap() { if ( lifecycleMap == null ) { - lifecycleMap = new HashMap(); + lifecycleMap = new HashMap(); if ( lifecycles != null ) { @@ -39,8 +46,62 @@ public class DefaultLifecycleMapping lifecycleMap.put( lifecycle.getId(), lifecycle ); } } + else + { + /* + * NOTE: This is to provide a migration path for implementors of the legacy API which did not know about + * getLifecycles(). + */ + + String[] lifecycleIds = { "default", "clean", "site" }; + + for ( String lifecycleId : lifecycleIds ) + { + Map phases = getPhases( lifecycleId ); + if ( phases != null ) + { + Lifecycle lifecycle = new Lifecycle(); + + lifecycle.setId( lifecycleId ); + lifecycle.setPhases( phases ); + + lifecycleMap.put( lifecycleId, lifecycle ); + } + } + } } + } + + public Map getLifecycles() + { + initLifecycleMap(); return lifecycleMap; } + + public List getOptionalMojos( String lifecycle ) + { + return null; + } + + public Map getPhases( String lifecycle ) + { + initLifecycleMap(); + + Lifecycle lifecycleMapping = lifecycleMap.get( lifecycle ); + + if ( lifecycleMapping != null ) + { + return lifecycleMapping.getPhases(); + } + else if ( "default".equals( lifecycle ) ) + { + return phases; + } + else + { + return null; + } + } + } 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 4fd294671e..164f69e776 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 @@ -19,9 +19,18 @@ package org.apache.maven.lifecycle.mapping; * under the License. */ +import java.util.List; import java.util.Map; public interface LifecycleMapping { - Map getLifecycles(); + + Map getLifecycles(); + + @Deprecated + List getOptionalMojos( String lifecycle ); + + @Deprecated + Map getPhases( String lifecycle ); + }