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 index 54aefc4eaa..5fc99d532c 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java @@ -68,10 +68,16 @@ public class Lifecycle return this.phases; } - public Map getDefaultPhases() + public Map getDefaultLifecyclePhases() { return defaultPhases; } + + @Deprecated + public Map getDefaultPhases() + { + return LifecyclePhase.toLegacyMap( getDefaultLifecyclePhases() ); + } @Override public String toString() diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecyclePluginAnalyzer.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecyclePluginAnalyzer.java index e71d2004ad..a72ce8edd4 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecyclePluginAnalyzer.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecyclePluginAnalyzer.java @@ -104,11 +104,11 @@ public class DefaultLifecyclePluginAnalyzer if ( lifecycleConfiguration != null ) { - phaseToGoalMapping = lifecycleConfiguration.getPhases(); + phaseToGoalMapping = lifecycleConfiguration.getLifecyclePhases(); } - else if ( lifecycle.getDefaultPhases() != null ) + else if ( lifecycle.getDefaultLifecyclePhases() != null ) { - phaseToGoalMapping = lifecycle.getDefaultPhases(); + phaseToGoalMapping = lifecycle.getDefaultLifecyclePhases(); } if ( phaseToGoalMapping != null ) 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 3deca003a4..e6845a36e3 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 @@ -61,13 +61,13 @@ public class DefaultLifecycleMapping for ( String lifecycleId : lifecycleIds ) { - Map phases = getPhases( lifecycleId ); + Map phases = getLifecyclePhases( lifecycleId ); if ( phases != null ) { Lifecycle lifecycle = new Lifecycle(); lifecycle.setId( lifecycleId ); - lifecycle.setPhases( phases ); + lifecycle.setLifecyclePhases( phases ); lifecycleMap.put( lifecycleId, lifecycle ); } @@ -88,7 +88,7 @@ public class DefaultLifecycleMapping return null; } - public Map getPhases( String lifecycle ) + private Map getLifecyclePhases( String lifecycle ) { initLifecycleMap(); @@ -96,7 +96,7 @@ public class DefaultLifecycleMapping if ( lifecycleMapping != null ) { - return lifecycleMapping.getPhases(); + return lifecycleMapping.getLifecyclePhases(); } else if ( "default".equals( lifecycle ) ) { @@ -107,5 +107,11 @@ public class DefaultLifecycleMapping return null; } } + + @Deprecated + public Map getPhases( String lifecycle ) + { + return LifecyclePhase.toLegacyMap( getLifecyclePhases( lifecycle ) ); + } } 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 index c80ed2f19a..d2b6d6cd8f 100644 --- 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 @@ -19,9 +19,12 @@ package org.apache.maven.lifecycle.mapping; * under the License. */ +import java.util.Collections; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; + /** * Class Lifecycle. */ @@ -35,7 +38,7 @@ public class Lifecycle /** * Field phases */ - private Map phases; + private Map lifecyclePhases; /* * NOTE: This exists merely for backward-compat with legacy-style lifecycle definitions and allows configuration @@ -53,13 +56,13 @@ public class Lifecycle } /** - * Method getPhases + * Method getLifecyclePhases */ - public Map getPhases() + public Map getLifecyclePhases() { - return this.phases; + return this.lifecyclePhases; } - + /** * Method setId * @@ -71,13 +74,40 @@ public class Lifecycle } /** - * Method setPhases + * Method setLifecyclePhases * * @param phases */ + public void setLifecyclePhases( Map lifecyclePhases ) + { + this.lifecyclePhases = lifecyclePhases; + } + + @Deprecated + public Map getPhases() + { + Map lphases = getLifecyclePhases(); + if ( lphases == null ) + { + return null; + } + + if ( lphases.isEmpty() ) + { + return Collections.emptyMap(); + } + + Map phases = new LinkedHashMap<>(); + for ( Map.Entry e: lphases.entrySet() ) + { + phases.put( e.getKey(), e.getValue().toString() ); + } + return phases; + } + + @Deprecated public void setPhases( Map phases ) { - this.phases = phases; - } //-- void setPhases(java.util.List) - + setLifecyclePhases( phases ); + } } 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 3248f70266..e656cc9fdc 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 @@ -34,6 +34,6 @@ public interface LifecycleMapping List getOptionalMojos( String lifecycle ); @Deprecated - Map getPhases( String lifecycle ); + Map getPhases( String lifecycle ); } diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecyclePhase.java b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecyclePhase.java index e0cc8ddcdf..d9afcf5056 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecyclePhase.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecyclePhase.java @@ -20,7 +20,10 @@ package org.apache.maven.lifecycle.mapping; */ import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import org.codehaus.plexus.util.StringUtils; @@ -61,4 +64,46 @@ public class LifecyclePhase mojos.add( lifecycleMojo ); } } + + @Override + public String toString() + { + StringBuilder sb = new StringBuilder(); + boolean first = true; + for ( LifecycleMojo mojo: getMojos() ) + { + if ( first ) + { + first = false; + } + else + { + sb.append( "," ); + } + sb.append( mojo.getGoal() ); + } + return sb.toString(); + } + + @Deprecated + public static Map toLegacyMap( Map lifecyclePhases ) + { + if ( lifecyclePhases == null ) + { + return null; + } + + if ( lifecyclePhases.isEmpty() ) + { + return Collections.emptyMap(); + } + + Map phases = new LinkedHashMap<>(); + for ( Map.Entry e: lifecyclePhases.entrySet() ) + { + phases.put( e.getKey(), e.getValue().toString() ); + } + return phases; + } + }