[MNG-6073] Addition of a core extension point to the model builder supporting model finalization. [MNG-3825] Dependencies with classifier should not always require a version.
o Updated to stop wiring the component and to document how to make use of it. Project: http://git-wip-us.apache.org/repos/asf/maven/repo Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/fad97f21 Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/fad97f21 Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/fad97f21 Branch: refs/heads/MNG-6056-feature-toggle Commit: fad97f21e1f53210c6b8b9e7a16683b008aae2b5 Parents: 0246aed Author: Christian Schulte <[email protected]> Authored: Sat Jul 30 21:35:53 2016 +0200 Committer: Christian Schulte <[email protected]> Committed: Sat Jul 30 22:31:31 2016 +0200 ---------------------------------------------------------------------- .../DependencyManagementModelFinalizer.java | 93 +++++++++++--------- 1 file changed, 51 insertions(+), 42 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven/blob/fad97f21/maven-model-builder/src/main/java/org/apache/maven/model/finalization/DependencyManagementModelFinalizer.java ---------------------------------------------------------------------- diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/finalization/DependencyManagementModelFinalizer.java b/maven-model-builder/src/main/java/org/apache/maven/model/finalization/DependencyManagementModelFinalizer.java index c69a174..c43e3dd 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/finalization/DependencyManagementModelFinalizer.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/finalization/DependencyManagementModelFinalizer.java @@ -19,6 +19,7 @@ package org.apache.maven.model.finalization; * under the License. */ +import java.util.Collection; import java.util.HashSet; import java.util.Set; @@ -28,68 +29,76 @@ import org.apache.maven.model.Model; import org.apache.maven.model.building.ModelBuildingRequest; import org.apache.maven.model.building.ModelProblemCollector; import org.apache.maven.model.management.DependencyManagementInjector; -import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; /** * A {@code ModelFinalizer} adding classified dependency declarations to the dependency management for all unclassified - * dependency declarations with classifiers taken from set of well-known classifiers. + * dependency declarations with classifiers taken from a collection of well-known classifiers. * <p> - * This class requires the {@code Set} implementation of well-known classifiers to be provided by the runtime - * environment. By default, no such implementation exists. As a starting point, that {@code Set} implementation should - * at least contain the following classifiers corresponding to plugin defaults. - * <table> - * <tr> - * <th>Plugin</th> - * <th>Classifiers</th> - * </tr> - * <tr> - * <td>maven-jar-plugin</td> - * <td>tests</td> - * </tr> - * <tr> - * <td>maven-javadoc-plugin</td> - * <td>javadoc, test-javadoc</td> - * </tr> - * <tr> - * <td>maven-shade-plugin</td> - * <td>shaded</td> - * </tr> - * <tr> - * <td>maven-site-plugin</td> - * <td>site</td> - * </tr> - * <tr> - * <td>maven-source-plugin</td> - * <td>sources, test-sources</td> - * </tr> - * </table> + * This {@code ModelFinalizer} implementation is not wired by default. It will need to be setup manually. This can be + * done by adding a {@code META-INF/plexus/components.xml} file containing the following to the Maven core classpath, + * for example. + * <pre> + * <component-set> + * <components> + * <component> + * <role>org.apache.maven.model.finalization.ModelFinalizer</role> + * <implementation>org.apache.maven.model.finalization.DependencyManagementModelFinalizer</implementation> + * <role-hint>dependency-management</role-hint> + * <requirements> + * <requirement> + * <role>org.apache.maven.model.management.DependencyManagementInjector</role> + * <field-name>dependencyManagementInjector</field-name> + * </requirement> + * </requirements> + * <configuration> + * <dependencyManagementClassifiers> + * <dependencyManagementClassifier>tests</dependencyManagementClassifier> + * <dependencyManagementClassifier>javadoc</dependencyManagementClassifier> + * <dependencyManagementClassifier>test-javadoc</dependencyManagementClassifier> + * <dependencyManagementClassifier>shaded</dependencyManagementClassifier> + * <dependencyManagementClassifier>site</dependencyManagementClassifier> + * <dependencyManagementClassifier>sources</dependencyManagementClassifier> + * <dependencyManagementClassifier>test-sources</dependencyManagementClassifier> + * </dependencyManagementClassifiers> + * </configuration> + * </component> + * </components> + * </component-set> + * </pre> * </p> * * @author Christian Schulte * @since 3.4 */ -@Component( role = ModelFinalizer.class, hint = "dependency-management" ) -public class DependencyManagementModelFinalizer +public final class DependencyManagementModelFinalizer implements ModelFinalizer { - @Requirement( role = Set.class, hint = "dependency-management-classifiers", optional = true ) - private Set<String> dependencyManagementClassifiers; - @Requirement private DependencyManagementInjector dependencyManagementInjector; + private Collection<String> dependencyManagementClassifiers; + public DependencyManagementModelFinalizer setDependencyManagementInjector( DependencyManagementInjector value ) { this.dependencyManagementInjector = value; return this; } - public DependencyManagementModelFinalizer setDependencyManagementClassifiers( Set<String> value ) + /** + * Gets the collection of well-known classifiers to use for adding classified dependency declarations. + * + * @return The collection of well-known classifiers to use. + */ + public Collection<String> getDependencyManagementClassifiers() { - this.dependencyManagementClassifiers = value; - return this; + if ( this.dependencyManagementClassifiers == null ) + { + this.dependencyManagementClassifiers = new HashSet<>(); + } + + return this.dependencyManagementClassifiers; } /** @@ -104,18 +113,18 @@ public class DependencyManagementModelFinalizer public void finalizeModel( final Model model, final ModelBuildingRequest request, final ModelProblemCollector problems ) { - if ( this.dependencyManagementClassifiers != null && model.getDependencyManagement() != null ) + if ( model.getDependencyManagement() != null ) { final Set<Dependency> classifiedDependencies = new HashSet<>(); for ( final Dependency managedDependency : model.getDependencyManagement().getDependencies() ) { - for ( final String classifier : this.dependencyManagementClassifiers ) + for ( final String classifier : this.getDependencyManagementClassifiers() ) { Dependency classifiedDependency = getDependency( model.getDependencyManagement(), managedDependency.getGroupId(), managedDependency.getArtifactId(), managedDependency.getType(), - managedDependency.getClassifier() ); + classifier ); if ( classifiedDependency == null ) {
