[MNG-6073] Addition of a core extension point to the model builder supporting model finalization.
o Updated to remove the example component. Things like that really should go into the core extension. Project: http://git-wip-us.apache.org/repos/asf/maven/repo Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/3628e966 Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/3628e966 Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/3628e966 Branch: refs/heads/MNG-6056-feature-toggle Commit: 3628e9665a6d1340da4e9b5bd6d1d05e6f9adfc2 Parents: fad97f2 Author: Christian Schulte <[email protected]> Authored: Sun Jul 31 17:31:46 2016 +0200 Committer: Christian Schulte <[email protected]> Committed: Sun Jul 31 17:44:19 2016 +0200 ---------------------------------------------------------------------- .../DependencyManagementModelFinalizer.java | 168 ------------------- 1 file changed, 168 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven/blob/3628e966/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 deleted file mode 100644 index c43e3dd..0000000 --- a/maven-model-builder/src/main/java/org/apache/maven/model/finalization/DependencyManagementModelFinalizer.java +++ /dev/null @@ -1,168 +0,0 @@ -package org.apache.maven.model.finalization; - -/* - * 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.Collection; -import java.util.HashSet; -import java.util.Set; - -import org.apache.maven.model.Dependency; -import org.apache.maven.model.DependencyManagement; -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.Requirement; - -/** - * A {@code ModelFinalizer} adding classified dependency declarations to the dependency management for all unclassified - * dependency declarations with classifiers taken from a collection of well-known classifiers. - * <p> - * 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 - */ -public final class DependencyManagementModelFinalizer - implements ModelFinalizer -{ - - @Requirement - private DependencyManagementInjector dependencyManagementInjector; - - private Collection<String> dependencyManagementClassifiers; - - public DependencyManagementModelFinalizer setDependencyManagementInjector( DependencyManagementInjector value ) - { - this.dependencyManagementInjector = value; - return this; - } - - /** - * 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() - { - if ( this.dependencyManagementClassifiers == null ) - { - this.dependencyManagementClassifiers = new HashSet<>(); - } - - return this.dependencyManagementClassifiers; - } - - /** - * Adds classified dependency declarations for all unclassified dependency declarations to the dependency management - * of the given {@code Model} with classifiers taken from set of well-known classifiers. - * - * @param model The {@code Model} to add classified dependency declarations to, must not be {@code null}. - * @param request The model building request that holds further settings, must not be {@code null}. - * @param problems The container used to collect problems that were encountered, must not be {@code null}. - */ - @Override - public void finalizeModel( final Model model, final ModelBuildingRequest request, - final ModelProblemCollector problems ) - { - if ( model.getDependencyManagement() != null ) - { - final Set<Dependency> classifiedDependencies = new HashSet<>(); - - for ( final Dependency managedDependency : model.getDependencyManagement().getDependencies() ) - { - for ( final String classifier : this.getDependencyManagementClassifiers() ) - { - Dependency classifiedDependency = - getDependency( model.getDependencyManagement(), managedDependency.getGroupId(), - managedDependency.getArtifactId(), managedDependency.getType(), - classifier ); - - if ( classifiedDependency == null ) - { - classifiedDependency = managedDependency.clone(); - classifiedDependencies.add( classifiedDependency ); - - classifiedDependency.setClassifier( classifier ); - } - } - } - - if ( !classifiedDependencies.isEmpty() ) - { - model.getDependencyManagement().getDependencies().addAll( classifiedDependencies ); - this.dependencyManagementInjector.injectManagement( model, request, problems ); - } - } - } - - private static Dependency getDependency( final DependencyManagement dependencyManagement, - final String groupId, final String artifactId, final String type, - final String classifier ) - { - Dependency dependency = null; - - for ( final Dependency candidate : dependencyManagement.getDependencies() ) - { - if ( groupId.equals( candidate.getGroupId() ) - && artifactId.equals( candidate.getArtifactId() ) - && type.equals( candidate.getType() ) - && classifier.equals( candidate.getClassifier() ) ) - { - dependency = candidate; - break; - } - } - - return dependency; - } - -}
