maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From schu...@apache.org
Subject maven-resolver git commit: [MRESOLVER-10] New class 'TransitiveDependencyManager' supporting transitive dependency management.
Date Thu, 15 Dec 2016 17:06:16 GMT
Repository: maven-resolver
Updated Branches:
  refs/heads/master df4e96331 -> 2a3d91de5


[MRESOLVER-10] New class 'TransitiveDependencyManager' supporting transitive dependency management.

o Updated the 'TransitiveDependencyManager' to correctly detect direct dependencies
  (by applying the same logic as the selectors) correcting POM resolution requests.


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

Branch: refs/heads/master
Commit: 2a3d91de5d264d1908790029523ac0e2277f006d
Parents: df4e963
Author: Christian Schulte <schulte@apache.org>
Authored: Thu Dec 15 18:00:10 2016 +0100
Committer: Christian Schulte <schulte@apache.org>
Committed: Thu Dec 15 18:05:17 2016 +0100

----------------------------------------------------------------------
 .../impl/DefaultDependencyCollectorTest.java    | 13 ++++++++
 .../managed/gid_1_managed-by-request.ini        |  4 +++
 .../managed/management-tree.txt                 |  2 +-
 .../managed/pom-management-tree.txt             |  7 ++++
 .../manager/TransitiveDependencyManager.java    | 35 +++++++++++++++-----
 5 files changed, 51 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/2a3d91de/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultDependencyCollectorTest.java
----------------------------------------------------------------------
diff --git a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultDependencyCollectorTest.java
b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultDependencyCollectorTest.java
index b9d6c7b..b9832fc 100644
--- a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultDependencyCollectorTest.java
+++ b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultDependencyCollectorTest.java
@@ -534,10 +534,23 @@ public class DefaultDependencyCollectorTest
         session.setDependencyManager( new TransitiveDependencyManager() );
         final Dependency root = newDep( "gid:0:ext:ver" );
         CollectRequest request = new CollectRequest( root, Arrays.asList( repository ) );
+        request.addManagedDependency( newDep( "gid:0:ext:must-retain-model-builder-override"
) );
+        request.addManagedDependency( newDep( "gid:1:ext:managed-by-request" ) );
         CollectResult result = collector.collectDependencies( session, request );
 
         DependencyNode expected = parser.parseResource( "management-tree.txt" );
         assertEqualSubtree( expected, result.getRoot() );
+
+        // Ensure direct dependencies are correctly detected for root artifact (POM) requests.
+        request = new CollectRequest();
+        request.setRootArtifact( new DefaultArtifact( "gid:pom:ext:ver" ) );
+        request.setRepositories( Arrays.asList( repository ) );
+        request.addDependency( root.setScope( "compile" ) );
+        request.addManagedDependency( newDep( "gid:0:ext:must-retain-model-builder-override"
) );
+        request.addManagedDependency( newDep( "gid:1:ext:managed-by-request" ) );
+        result = collector.collectDependencies( session, request );
+        expected = parser.parseResource( "pom-management-tree.txt" );
+        assertEqualArtifactSubtree( expected, result.getRoot() );
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/2a3d91de/maven-resolver-impl/src/test/resources/artifact-descriptions/managed/gid_1_managed-by-request.ini
----------------------------------------------------------------------
diff --git a/maven-resolver-impl/src/test/resources/artifact-descriptions/managed/gid_1_managed-by-request.ini
b/maven-resolver-impl/src/test/resources/artifact-descriptions/managed/gid_1_managed-by-request.ini
new file mode 100644
index 0000000..805fd98
--- /dev/null
+++ b/maven-resolver-impl/src/test/resources/artifact-descriptions/managed/gid_1_managed-by-request.ini
@@ -0,0 +1,4 @@
+[dependencies]
+gid:2:ext:ver
+[manageddependencies]
+gid:3:ext:managed-by-1
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/2a3d91de/maven-resolver-impl/src/test/resources/artifact-descriptions/managed/management-tree.txt
----------------------------------------------------------------------
diff --git a/maven-resolver-impl/src/test/resources/artifact-descriptions/managed/management-tree.txt
b/maven-resolver-impl/src/test/resources/artifact-descriptions/managed/management-tree.txt
index 7307a19..626d1a9 100644
--- a/maven-resolver-impl/src/test/resources/artifact-descriptions/managed/management-tree.txt
+++ b/maven-resolver-impl/src/test/resources/artifact-descriptions/managed/management-tree.txt
@@ -1,5 +1,5 @@
 gid:0:ext:ver
-+- gid:1:ext:ver compile
++- gid:1:ext:managed-by-request compile
    +- gid:2:ext:managed-by-0 compile
       +- gid:3:ext:managed-by-1 compile
          +- gid:4:ext:managed-by-2 compile

http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/2a3d91de/maven-resolver-impl/src/test/resources/artifact-descriptions/managed/pom-management-tree.txt
----------------------------------------------------------------------
diff --git a/maven-resolver-impl/src/test/resources/artifact-descriptions/managed/pom-management-tree.txt
b/maven-resolver-impl/src/test/resources/artifact-descriptions/managed/pom-management-tree.txt
new file mode 100644
index 0000000..a7ca439
--- /dev/null
+++ b/maven-resolver-impl/src/test/resources/artifact-descriptions/managed/pom-management-tree.txt
@@ -0,0 +1,7 @@
+gid:pom:ext:ver
++- gid:0:ext:ver compile
+   +- gid:1:ext:managed-by-request compile
+      +- gid:2:ext:managed-by-0 compile
+         +- gid:3:ext:managed-by-1 compile
+            +- gid:4:ext:managed-by-2 compile
+               +- gid:5:ext:managed-by-3 compile

http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/2a3d91de/maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/manager/TransitiveDependencyManager.java
----------------------------------------------------------------------
diff --git a/maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/manager/TransitiveDependencyManager.java
b/maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/manager/TransitiveDependencyManager.java
index 4484aa5..aa02d47 100644
--- a/maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/manager/TransitiveDependencyManager.java
+++ b/maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/manager/TransitiveDependencyManager.java
@@ -43,8 +43,6 @@ public final class TransitiveDependencyManager
     implements DependencyManager
 {
 
-    private final int depth;
-
     private final Map<Object, String> managedVersions;
 
     private final Map<Object, String> managedScopes;
@@ -55,6 +53,8 @@ public final class TransitiveDependencyManager
 
     private final Map<Object, Collection<Exclusion>> managedExclusions;
 
+    private final boolean transitive;
+
     private int hashCode;
 
     /**
@@ -62,12 +62,12 @@ public final class TransitiveDependencyManager
      */
     public TransitiveDependencyManager()
     {
-        this( 0, Collections.<Object, String>emptyMap(), Collections.<Object, String>emptyMap(),
+        this( false, Collections.<Object, String>emptyMap(), Collections.<Object,
String>emptyMap(),
               Collections.<Object, Boolean>emptyMap(), Collections.<Object, String>emptyMap(),
               Collections.<Object, Collection<Exclusion>>emptyMap() );
     }
 
-    private TransitiveDependencyManager( final int depth,
+    private TransitiveDependencyManager( final boolean transitive,
                                          final Map<Object, String> managedVersions,
                                          final Map<Object, String> managedScopes,
                                          final Map<Object, Boolean> managedOptionals,
@@ -75,7 +75,7 @@ public final class TransitiveDependencyManager
                                          final Map<Object, Collection<Exclusion>>
managedExclusions )
     {
         super();
-        this.depth = depth;
+        this.transitive = transitive;
         this.managedVersions = managedVersions;
         this.managedScopes = managedScopes;
         this.managedOptionals = managedOptionals;
@@ -152,7 +152,24 @@ public final class TransitiveDependencyManager
             }
         }
 
-        return new TransitiveDependencyManager( this.depth + 1, versions, scopes, optionals,
localPaths, exclusions );
+        TransitiveDependencyManager child = null;
+
+        if ( context.getDependency() != null && !this.transitive )
+        {
+            child = new TransitiveDependencyManager( true, versions, scopes, optionals, localPaths,
exclusions );
+        }
+        if ( context.getDependency() == null && this.transitive )
+        {
+            child = new TransitiveDependencyManager( false, versions, scopes, optionals,
localPaths, exclusions );
+        }
+        if ( child == null )
+        {
+            child = new TransitiveDependencyManager( this.transitive, versions, scopes, optionals,
localPaths,
+                                                     exclusions );
+
+        }
+
+        return child;
     }
 
     public DependencyManagement manageDependency( Dependency dependency )
@@ -161,7 +178,7 @@ public final class TransitiveDependencyManager
 
         Object key = getKey( dependency.getArtifact() );
 
-        if ( depth >= 2 )
+        if ( this.transitive )
         {
             String version = managedVersions.get( key );
             if ( version != null )
@@ -248,7 +265,7 @@ public final class TransitiveDependencyManager
         if ( equal )
         {
             final TransitiveDependencyManager that = (TransitiveDependencyManager) obj;
-            return this.depth == that.depth
+            return this.transitive == that.transitive
                        && this.managedVersions.equals( that.managedVersions )
                        && this.managedScopes.equals( that.managedScopes )
                        && this.managedOptionals.equals( that.managedOptionals )
@@ -265,7 +282,7 @@ public final class TransitiveDependencyManager
         if ( this.hashCode == 0 )
         {
             int hash = 17;
-            hash = hash * 31 + this.depth;
+            hash = hash * 31 + ( (Boolean) this.transitive ).hashCode();
             hash = hash * 31 + this.managedVersions.hashCode();
             hash = hash * 31 + this.managedScopes.hashCode();
             hash = hash * 31 + this.managedOptionals.hashCode();


Mime
View raw message