maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From schu...@apache.org
Subject [02/16] maven git commit: [MNG-5600] Dependency management import should support exclusions.
Date Fri, 10 Feb 2017 21:54:09 GMT
[MNG-5600] Dependency management import should support exclusions.


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/c134495d
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/c134495d
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/c134495d

Branch: refs/heads/DEPMGMT-IT
Commit: c134495d11a3f3c968cf19658deaeddf50aaaf0a
Parents: 183c204
Author: Christian Schulte <schulte@apache.org>
Authored: Sun Jun 19 16:32:25 2016 +0200
Committer: Christian Schulte <schulte@apache.org>
Committed: Fri Feb 10 22:50:55 2017 +0100

----------------------------------------------------------------------
 .../model/building/DefaultModelBuilder.java     | 59 +++++++++++++++-----
 1 file changed, 45 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/c134495d/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
----------------------------------------------------------------------
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index 5fa52a6..0047c53 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -19,7 +19,16 @@ package org.apache.maven.model.building;
  * under the License.
  */
 
-
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
 import org.apache.commons.lang3.Validate;
 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
@@ -28,6 +37,7 @@ import org.apache.maven.model.Activation;
 import org.apache.maven.model.Build;
 import org.apache.maven.model.Dependency;
 import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.model.Exclusion;
 import org.apache.maven.model.InputLocation;
 import org.apache.maven.model.InputSource;
 import org.apache.maven.model.Model;
@@ -62,18 +72,6 @@ import org.apache.maven.model.superpom.SuperPomProvider;
 import org.apache.maven.model.validation.ModelValidator;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
 import static org.apache.maven.model.building.Result.error;
 import static org.apache.maven.model.building.Result.newResult;
 
@@ -1223,7 +1221,40 @@ public class DefaultModelBuilder
                     importMgmt = new DependencyManagement();
                 }
 
-                putCache( request.getModelCache(), groupId, artifactId, version, ModelCacheTag.IMPORT,
importMgmt );
+                // [MNG-5600] Dependency management import should support exclusions.
+                if ( !dependency.getExclusions().isEmpty() )
+                {
+                    for ( final Exclusion exclusion : dependency.getExclusions() )
+                    {
+                        if ( exclusion.getGroupId() != null && exclusion.getArtifactId()
!= null )
+                        {
+                            for ( final Iterator<Dependency> dependencies = importMgmt.getDependencies().iterator();
+                                  dependencies.hasNext(); )
+                            {
+                                final Dependency candidate = dependencies.next();
+
+                                if ( ( exclusion.getGroupId().equals( "*" )
+                                       || exclusion.getGroupId().equals( candidate.getGroupId()
) )
+                                         && ( exclusion.getArtifactId().equals( "*"
)
+                                              || exclusion.getArtifactId().equals( candidate.getArtifactId()
) ) )
+                                {
+                                    // Dependency excluded from import.
+                                    dependencies.remove();
+                                }
+                            }
+                        }
+                    }
+
+                    for ( final Dependency includedDependency : importMgmt.getDependencies()
)
+                    {
+                        includedDependency.getExclusions().addAll( dependency.getExclusions()
);
+                    }
+                }
+                else
+                {
+                    // Only dependency managements without exclusion processing applied can
be cached.
+                    putCache( request.getModelCache(), groupId, artifactId, version, ModelCacheTag.IMPORT,
importMgmt );
+                }
             }
 
             if ( importMgmts == null )


Mime
View raw message