Repository: maven Updated Branches: refs/heads/master cc006b544 -> 029af3a39
[MNG-5359] Declared execution in PluginMgmt gets bound to lifecycle (regression) o Updated to use a 'LifecycleMappingNotFoundException' instead of returning 'null'. o Updated to also inject lifecycle plugins for project default goals. Project: http://git-wip-us.apache.org/repos/asf/maven/repo Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/029af3a3 Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/029af3a3 Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/029af3a3 Branch: refs/heads/master Commit: 029af3a394b37610ecfb97c07b4f62895f7d2eb7 Parents: cc006b5 Author: Christian Schulte <[email protected]> Authored: Mon Dec 21 01:09:38 2015 +0100 Committer: Christian Schulte <[email protected]> Committed: Mon Dec 21 02:19:47 2015 +0100 ---------------------------------------------------------------------- .../lifecycle/DefaultLifecycleExecutor.java | 3 + .../lifecycle/LifeCyclePluginAnalyzer.java | 10 ++- .../maven/lifecycle/LifecycleExecutor.java | 3 +- .../LifecycleMappingNotFoundException.java | 45 +++++++++++ .../DefaultLifecyclePluginAnalyzer.java | 27 ++++--- .../DefaultLifecycleBindingsInjector.java | 79 +++++++++++++------- 6 files changed, 123 insertions(+), 44 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven/blob/029af3a3/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java ---------------------------------------------------------------------- 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 6f994b3..8d0405c 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 @@ -100,7 +100,10 @@ public class DefaultLifecycleExecutor // TODO: This whole method could probably removed by injecting lifeCyclePluginAnalyzer straight into client site. // TODO: But for some reason the whole plexus appcontext refuses to start when I try this. + @Override + @Deprecated public Set<Plugin> getPluginsBoundByDefaultToAllLifecycles( String packaging ) + throws LifecycleMappingNotFoundException { return lifeCyclePluginAnalyzer.getPluginsBoundByDefaultToAllLifecycles( packaging ); } http://git-wip-us.apache.org/repos/asf/maven/blob/029af3a3/maven-core/src/main/java/org/apache/maven/lifecycle/LifeCyclePluginAnalyzer.java ---------------------------------------------------------------------- diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/LifeCyclePluginAnalyzer.java b/maven-core/src/main/java/org/apache/maven/lifecycle/LifeCyclePluginAnalyzer.java index 1d4e7f8..ef17560 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/LifeCyclePluginAnalyzer.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/LifeCyclePluginAnalyzer.java @@ -30,7 +30,8 @@ public interface LifeCyclePluginAnalyzer { @Deprecated - Set<Plugin> getPluginsBoundByDefaultToAllLifecycles( String packaging ); + Set<Plugin> getPluginsBoundByDefaultToAllLifecycles( String packaging ) + throws LifecycleMappingNotFoundException; /** * Gets the lifecycle {@code Plugin}s for a given packaging and set of phases. @@ -38,11 +39,12 @@ public interface LifeCyclePluginAnalyzer * @param packaging The packaging to get plugins for. * @param phases The phases to get plugins for. * - * @return All lifecycle {@code Plugin}s for the given {@code packaging} and {@code phases} - * or {@code null}, if {@code packaging} does not identify a supported packaging. + * @return All lifecycle {@code Plugin}s for the given {@code packaging} and {@code phases}. * + * @throws LifecycleMappingNotFoundException if {@code packaging} does not identify a supported packaging. * @since 3.4 */ - Set<Plugin> getPlugins( String packaging, Set<String> phases ); + Set<Plugin> getPlugins( String packaging, Set<String> phases ) + throws LifecycleMappingNotFoundException; } http://git-wip-us.apache.org/repos/asf/maven/blob/029af3a3/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java ---------------------------------------------------------------------- diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java index 15c9c54..9e74ba2 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java @@ -54,7 +54,8 @@ public interface LifecycleExecutor * @deprecated Please use {@link LifeCyclePluginAnalyzer}. */ @Deprecated - Set<Plugin> getPluginsBoundByDefaultToAllLifecycles( String packaging ); + Set<Plugin> getPluginsBoundByDefaultToAllLifecycles( String packaging ) + throws LifecycleMappingNotFoundException; MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks ) throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, http://git-wip-us.apache.org/repos/asf/maven/blob/029af3a3/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleMappingNotFoundException.java ---------------------------------------------------------------------- diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleMappingNotFoundException.java b/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleMappingNotFoundException.java new file mode 100644 index 0000000..983f052 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleMappingNotFoundException.java @@ -0,0 +1,45 @@ +package org.apache.maven.lifecycle; + +/* + * 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. + */ + +/** + * Signals a failure to locate a lifecycle mapping. + * + * @author Christian Schulte + * + * @since 3.4 + */ +public final class LifecycleMappingNotFoundException extends Exception +{ + + private String packaging; + + public LifecycleMappingNotFoundException( final String packaging ) + { + super( String.format( "No lifecycle mapping found for packaging '%s'.", packaging ) ); + this.packaging = packaging; + } + + public String getPackaging() + { + return this.packaging; + } + +} http://git-wip-us.apache.org/repos/asf/maven/blob/029af3a3/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecyclePluginAnalyzer.java ---------------------------------------------------------------------- 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 27159e4..340af62 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 @@ -19,9 +19,20 @@ package org.apache.maven.lifecycle.internal; * under the License. */ +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + import org.apache.maven.lifecycle.DefaultLifecycles; import org.apache.maven.lifecycle.LifeCyclePluginAnalyzer; import org.apache.maven.lifecycle.Lifecycle; +import org.apache.maven.lifecycle.LifecycleMappingNotFoundException; import org.apache.maven.lifecycle.mapping.LifecycleMapping; import org.apache.maven.lifecycle.mapping.LifecycleMojo; import org.apache.maven.lifecycle.mapping.LifecyclePhase; @@ -32,16 +43,6 @@ import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.StringUtils; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - /** * @since 3.0 * @author Benjamin Bentmann @@ -80,6 +81,7 @@ public class DefaultLifecyclePluginAnalyzer // public Set<Plugin> getPluginsBoundByDefaultToAllLifecycles( String packaging ) + throws LifecycleMappingNotFoundException { if ( logger.isDebugEnabled() ) { @@ -91,7 +93,7 @@ public class DefaultLifecyclePluginAnalyzer if ( lifecycleMappingForPackaging == null ) { - return null; + throw new LifecycleMappingNotFoundException( packaging ); } Map<Plugin, Plugin> plugins = new LinkedHashMap<>(); @@ -131,6 +133,7 @@ public class DefaultLifecyclePluginAnalyzer @Override public Set<Plugin> getPlugins( final String packaging, final Set<String> phases ) + throws LifecycleMappingNotFoundException { if ( logger.isDebugEnabled() ) { @@ -142,7 +145,7 @@ public class DefaultLifecyclePluginAnalyzer if ( lifecycleMappingForPackaging == null ) { - return null; + throw new LifecycleMappingNotFoundException( packaging ); } final Map<Plugin, Plugin> plugins = new LinkedHashMap<>(); http://git-wip-us.apache.org/repos/asf/maven/blob/029af3a3/maven-core/src/main/java/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjector.java ---------------------------------------------------------------------- diff --git a/maven-core/src/main/java/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjector.java b/maven-core/src/main/java/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjector.java index 3933e14..69190fb 100644 --- a/maven-core/src/main/java/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjector.java +++ b/maven-core/src/main/java/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjector.java @@ -20,15 +20,17 @@ package org.apache.maven.model.plugin; */ import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; - import java.util.Set; + import org.apache.maven.lifecycle.LifeCyclePluginAnalyzer; +import org.apache.maven.lifecycle.LifecycleMappingNotFoundException; import org.apache.maven.model.Build; import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; @@ -43,6 +45,7 @@ import org.apache.maven.model.building.ModelProblemCollectorRequest; import org.apache.maven.model.merge.MavenModelMerger; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; +import org.codehaus.plexus.util.StringUtils; /** * Handles injection of plugin executions induced by the lifecycle bindings for a packaging. @@ -61,43 +64,65 @@ public class DefaultLifecycleBindingsInjector public void injectLifecycleBindings( Model model, ModelBuildingRequest request, ModelProblemCollector problems ) { - final Set<String> phases = new HashSet<>(); - - if ( request.getGoals() != null ) + try { - for ( final String goal : request.getGoals() ) + final Set<String> phases = new HashSet<>(); + + if ( request.getGoals() != null ) { - if ( !this.isGoalSpecification( goal ) ) + if ( !request.getGoals().isEmpty() ) { - phases.add( goal ); + // Command line goals. + for ( final String goal : request.getGoals() ) + { + if ( !this.isGoalSpecification( goal ) ) + { + phases.add( goal ); + } + } + } + else if ( model.getBuild() != null && model.getBuild().getDefaultGoal() != null ) + { + // No command line goals -> default goal(s). + // Copied from 'DefaultLifecycleTaskSegmentCalculator'. + if ( !StringUtils.isEmpty( model.getBuild().getDefaultGoal() ) ) + { + for ( final String goal + : Arrays.asList( StringUtils.split( model.getBuild().getDefaultGoal() ) ) ) + { + if ( !this.isGoalSpecification( goal ) ) + { + phases.add( goal ); + } + } + } } } - } - - final String packaging = model.getPackaging(); - // MNG-5359: request.setGoals() may not have been called since the goals got added for MNG-5359 in 3.4. In this - // case fall back to the pre 3.4 behaviour. Usages of ProjectBuildingRequest and ModelBuildingRequest - // without setting the goals should behave the same way as before. - final Collection<Plugin> defaultPlugins = - request.getGoals() == null - ? lifecyclePluginAnalyzer.getPluginsBoundByDefaultToAllLifecycles( packaging ) - : lifecyclePluginAnalyzer.getPlugins( packaging, phases ); + // MNG-5359: request.setGoals() may not have been called since the goals got added for MNG-5359 in 3.4. In + // this case fall back to the pre 3.4 behaviour. Usages of ProjectBuildingRequest and + // ModelBuildingRequest without setting the goals should behave the same way as before. + final Collection<Plugin> defaultPlugins = + request.getGoals() == null + ? lifecyclePluginAnalyzer.getPluginsBoundByDefaultToAllLifecycles( model.getPackaging() ) + : lifecyclePluginAnalyzer.getPlugins( model.getPackaging(), phases ); - if ( defaultPlugins == null ) - { - problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE ). - setMessage( "Unknown packaging: " + packaging ). - setLocation( model.getLocation( "packaging" ) ) ); + if ( !defaultPlugins.isEmpty() ) + { + Model lifecycleModel = new Model(); + lifecycleModel.setBuild( new Build() ); + lifecycleModel.getBuild().getPlugins().addAll( defaultPlugins ); + merger.merge( model, lifecycleModel ); + } } - else if ( !defaultPlugins.isEmpty() ) + catch ( final LifecycleMappingNotFoundException e ) { - Model lifecycleModel = new Model(); - lifecycleModel.setBuild( new Build() ); - lifecycleModel.getBuild().getPlugins().addAll( defaultPlugins ); + problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE ). + setException( e ). + setMessage( "Unknown packaging: " + model.getPackaging() ). + setLocation( model.getLocation( "packaging" ) ) ); - merger.merge( model, lifecycleModel ); } }
