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 fcfde95148..54aefc4eaa 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 @@ -22,6 +22,8 @@ package org.apache.maven.lifecycle; import java.util.List; import java.util.Map; +import org.apache.maven.lifecycle.mapping.LifecyclePhase; + /** * Class Lifecycle. */ @@ -31,7 +33,7 @@ public class Lifecycle { } - public Lifecycle( String id, List phases, Map defaultPhases ) + public Lifecycle( String id, List phases, Map defaultPhases ) { this.id = id; this.phases = phases; @@ -54,7 +56,7 @@ public class Lifecycle private List phases; - private Map defaultPhases; + private Map defaultPhases; public String getId() { @@ -66,7 +68,7 @@ public class Lifecycle return this.phases; } - public Map getDefaultPhases() + public Map getDefaultPhases() { return defaultPhases; } 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 a5e6a34c2e..52f3e8574a 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 @@ -23,6 +23,8 @@ import org.apache.maven.lifecycle.DefaultLifecycles; import org.apache.maven.lifecycle.LifeCyclePluginAnalyzer; import org.apache.maven.lifecycle.Lifecycle; import org.apache.maven.lifecycle.mapping.LifecycleMapping; +import org.apache.maven.lifecycle.mapping.LifecycleMojo; +import org.apache.maven.lifecycle.mapping.LifecyclePhase; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; import org.codehaus.plexus.component.annotations.Component; @@ -98,7 +100,7 @@ public class DefaultLifecyclePluginAnalyzer org.apache.maven.lifecycle.mapping.Lifecycle lifecycleConfiguration = lifecycleMappingForPackaging.getLifecycles().get( lifecycle.getId() ); - Map phaseToGoalMapping = null; + Map phaseToGoalMapping = null; if ( lifecycleConfiguration != null ) { @@ -111,14 +113,10 @@ public class DefaultLifecyclePluginAnalyzer if ( phaseToGoalMapping != null ) { - // These are of the form: - // - // compile -> org.apache.maven.plugins:maven-compiler-plugin:compile[,gid:aid:goal,...] - // - for ( Map.Entry goalsForLifecyclePhase : phaseToGoalMapping.entrySet() ) + for ( Map.Entry goalsForLifecyclePhase : phaseToGoalMapping.entrySet() ) { String phase = goalsForLifecyclePhase.getKey(); - String goals = goalsForLifecyclePhase.getValue(); + LifecyclePhase goals = goalsForLifecyclePhase.getValue(); if ( goals != null ) { parseLifecyclePhaseDefinitions( plugins, phase, goals ); @@ -149,47 +147,54 @@ public class DefaultLifecyclePluginAnalyzer return lifecycles; } - private void parseLifecyclePhaseDefinitions( Map plugins, String phase, String goals ) + private void parseLifecyclePhaseDefinitions( Map plugins, String phase, LifecyclePhase goals ) { - String[] mojos = StringUtils.split( goals, "," ); - - for ( int i = 0; i < mojos.length; i++ ) + List mojos = goals.getMojos(); + if ( mojos != null ) { - GoalSpec gs = parseGoalSpec( mojos[i].trim() ); - - if ( gs == null ) + + for ( int i = 0; i < mojos.size(); i++ ) { - logger.warn( "Ignored invalid goal specification '" + mojos[i] + "' from lifecycle mapping for phase " - + phase ); - continue; - } - - Plugin plugin = new Plugin(); - plugin.setGroupId( gs.groupId ); - plugin.setArtifactId( gs.artifactId ); - plugin.setVersion( gs.version ); - - Plugin existing = plugins.get( plugin ); - if ( existing != null ) - { - if ( existing.getVersion() == null ) + LifecycleMojo mojo = mojos.get( i ); + + GoalSpec gs = parseGoalSpec( mojo.getGoal() ); + + if ( gs == null ) { - existing.setVersion( plugin.getVersion() ); + logger.warn( "Ignored invalid goal specification '" + mojo.getGoal() + + "' from lifecycle mapping for phase " + phase ); + continue; } - plugin = existing; + + Plugin plugin = new Plugin(); + plugin.setGroupId( gs.groupId ); + plugin.setArtifactId( gs.artifactId ); + plugin.setVersion( gs.version ); + + Plugin existing = plugins.get( plugin ); + if ( existing != null ) + { + if ( existing.getVersion() == null ) + { + existing.setVersion( plugin.getVersion() ); + } + plugin = existing; + } + else + { + plugins.put( plugin, plugin ); + } + + PluginExecution execution = new PluginExecution(); + execution.setId( getExecutionId( plugin, gs.goal ) ); + execution.setPhase( phase ); + execution.setPriority( i - mojos.size() ); + execution.getGoals().add( gs.goal ); + execution.setConfiguration( mojo.getConfiguration() ); + + plugin.setDependencies( mojo.getDependencies() ); + plugin.getExecutions().add( execution ); } - else - { - plugins.put( plugin, plugin ); - } - - PluginExecution execution = new PluginExecution(); - execution.setId( getExecutionId( plugin, gs.goal ) ); - execution.setPhase( phase ); - execution.setPriority( i - mojos.length ); - execution.getGoals().add( gs.goal ); - - plugin.getExecutions().add( execution ); } } 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 9947e2fcce..d3e11fd9f8 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 @@ -32,7 +32,7 @@ public class DefaultLifecycleMapping private Map lifecycleMap; /** @deprecated use lifecycles instead */ - private Map phases; + private Map phases; /** * Populates the lifecycle map from the injected list of lifecycle mappings (if not already done). @@ -61,7 +61,7 @@ public class DefaultLifecycleMapping for ( String lifecycleId : lifecycleIds ) { - Map phases = getPhases( lifecycleId ); + Map phases = getPhases( lifecycleId ); if ( phases != null ) { Lifecycle lifecycle = new Lifecycle(); @@ -88,7 +88,7 @@ public class DefaultLifecycleMapping return null; } - public Map getPhases( String lifecycle ) + public Map getPhases( String lifecycle ) { initLifecycleMap(); 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 6adf4f341d..c80ed2f19a 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 @@ -35,7 +35,7 @@ public class Lifecycle /** * Field phases */ - private Map phases; + private Map phases; /* * NOTE: This exists merely for backward-compat with legacy-style lifecycle definitions and allows configuration @@ -55,7 +55,7 @@ public class Lifecycle /** * Method getPhases */ - public Map getPhases() + public Map getPhases() { return this.phases; } @@ -75,7 +75,7 @@ public class Lifecycle * * @param phases */ - public void setPhases( Map phases ) + public void setPhases( Map phases ) { this.phases = phases; } //-- void setPhases(java.util.List) 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 e656cc9fdc..3248f70266 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/LifecycleMojo.java b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecycleMojo.java new file mode 100644 index 0000000000..f2af879516 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecycleMojo.java @@ -0,0 +1,63 @@ +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.List; + +import org.apache.maven.model.Dependency; +import org.codehaus.plexus.util.xml.Xpp3Dom; + +public class LifecycleMojo +{ + + private String goal; + private Xpp3Dom configuration; + private List dependencies; + + public String getGoal() + { + return goal; + } + + public Xpp3Dom getConfiguration() + { + return configuration; + } + + public List getDependencies() + { + return dependencies; + } + + public void setGoal( String goal ) + { + this.goal = goal; + } + + public void setConfiguration( Xpp3Dom configuration ) + { + this.configuration = configuration; + } + + public void setDependencies( List dependencies ) + { + this.dependencies = dependencies; + } +} 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 new file mode 100644 index 0000000000..a68a71c00f --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecyclePhase.java @@ -0,0 +1,64 @@ +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.ArrayList; +import java.util.List; + +import org.codehaus.plexus.util.StringUtils; + +public class LifecyclePhase +{ + + private List mojos; + + public LifecyclePhase() + { + } + + public LifecyclePhase( String goals ) + { + set( goals ); + } + + public List getMojos() + { + return mojos; + } + + public void setMojos( List mojos ) + { + this.mojos = mojos; + } + + public void set( String goals ) + { + mojos = new ArrayList(); + + String[] mojoGoals = StringUtils.split( goals, "," ); + + for ( String mojoGoal: mojoGoals ) + { + LifecycleMojo lifecycleMojo = new LifecycleMojo(); + lifecycleMojo.setGoal( mojoGoal.trim() ); + mojos.add( lifecycleMojo ); + } + } +}