[maven-resolver] branch MRESOLVER-8 updated (f956237 -> c436906)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[maven-resolver] branch MRESOLVER-8 updated (f956237 -> c436906)

michaelo
This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a change to branch MRESOLVER-8
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git.


 discard f956237  [MRESOLVER-8] ScopeDependencySelector incorrectly de-selects direct dependencies
     new c436906  [MRESOLVER-8] ScopeDependencySelector incorrectly de-selects direct dependencies

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (f956237)
            \
             N -- N -- N   refs/heads/MRESOLVER-8 (c436906)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../eclipse/aether/util/graph/selector/ScopeDependencySelector.java   | 2 +-
 .../aether/util/graph/selector/ScopeDependencySelectorTest.java       | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

Reply | Threaded
Open this post in threaded view
|

[maven-resolver] 01/01: [MRESOLVER-8] ScopeDependencySelector incorrectly de-selects direct dependencies

michaelo
This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch MRESOLVER-8
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git

commit c4369069d71a3187d968ba4c6091f02116541080
Author: Christian Schulte <[hidden email]>
AuthorDate: Sat Mar 11 22:38:14 2017 +0100

    [MRESOLVER-8] ScopeDependencySelector incorrectly de-selects direct dependencies
---
 .../graph/selector/ScopeDependencySelector.java    | 42 +++++++++-------------
 .../selector/ScopeDependencySelectorTest.java      |  4 +--
 2 files changed, 18 insertions(+), 28 deletions(-)

diff --git a/maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/selector/ScopeDependencySelector.java b/maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/selector/ScopeDependencySelector.java
index 75a8fd6..d94057a 100644
--- a/maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/selector/ScopeDependencySelector.java
+++ b/maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/selector/ScopeDependencySelector.java
@@ -8,9 +8,9 @@ package org.eclipse.aether.util.graph.selector;
  * 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
@@ -34,14 +34,14 @@ import org.eclipse.aether.graph.Dependency;
  * A dependency selector that filters transitive dependencies based on their scope. Direct dependencies are always
  * included regardless of their scope. <em>Note:</em> This filter does not assume any relationships between the scopes.
  * In particular, the filter is not aware of scopes that logically include other scopes.
- *
+ *
  * @see Dependency#getScope()
  */
 public final class ScopeDependencySelector
     implements DependencySelector
 {
 
-    private final boolean transitive;
+    private final int depth;
 
     private final Collection<String> included;
 
@@ -49,13 +49,13 @@ public final class ScopeDependencySelector
 
     /**
      * Creates a new selector using the specified includes and excludes.
-     *
+     *
      * @param included The set of scopes to include, may be {@code null} or empty to include any scope.
      * @param excluded The set of scopes to exclude, may be {@code null} or empty to exclude no scope.
      */
     public ScopeDependencySelector( Collection<String> included, Collection<String> excluded )
     {
-        transitive = false;
+        this.depth = 0;
         this.included = clone( included );
         this.excluded = clone( excluded );
     }
@@ -82,7 +82,7 @@ public final class ScopeDependencySelector
 
     /**
      * Creates a new selector using the specified excludes.
-     *
+     *
      * @param excluded The set of scopes to exclude, may be {@code null} or empty to exclude no scope.
      */
     public ScopeDependencySelector( String... excluded )
@@ -90,33 +90,23 @@ public final class ScopeDependencySelector
         this( null, ( excluded != null ) ? Arrays.asList( excluded ) : null );
     }
 
-    private ScopeDependencySelector( boolean transitive, Collection<String> included, Collection<String> excluded )
+    private ScopeDependencySelector( int depth, Collection<String> included, Collection<String> excluded )
     {
-        this.transitive = transitive;
+        this.depth = depth;
         this.included = included;
         this.excluded = excluded;
     }
 
     public boolean selectDependency( Dependency dependency )
     {
-        if ( !transitive )
-        {
-            return true;
-        }
-
-        String scope = dependency.getScope();
-        return ( included == null || included.contains( scope ) )
-                && ( excluded == null || !excluded.contains( scope ) );
+        return depth < 2
+                   || ( ( included == null || included.contains( dependency.getScope() ) )
+                        && ( excluded == null || !excluded.contains( dependency.getScope() ) ) );
     }
 
     public DependencySelector deriveChildSelector( DependencyCollectionContext context )
     {
-        if ( this.transitive || context.getDependency() == null )
-        {
-            return this;
-        }
-
-        return new ScopeDependencySelector( true, included, excluded );
+        return depth >= 2 ? this : new ScopeDependencySelector( depth + 1, included, excluded );
     }
 
     @Override
@@ -132,7 +122,7 @@ public final class ScopeDependencySelector
         }
 
         ScopeDependencySelector that = (ScopeDependencySelector) obj;
-        return transitive == that.transitive && Objects.equals( included, that.included )
+        return depth == that.depth && Objects.equals( included, that.included )
                 && Objects.equals( excluded, that.excluded );
     }
 
@@ -140,7 +130,7 @@ public final class ScopeDependencySelector
     public int hashCode()
     {
         int hash = 17;
-        hash = hash * 31 + ( transitive ? 1 : 0 );
+        hash = hash * 31 + depth;
         hash = hash * 31 + ( included != null ? included.hashCode() : 0 );
         hash = hash * 31 + ( excluded != null ? excluded.hashCode() : 0 );
         return hash;
@@ -150,7 +140,7 @@ public final class ScopeDependencySelector
     public String toString()
     {
         return String.format(
-            "%s(included: %s, excluded: %s, transitive: %s)", getClass().getSimpleName(), included, excluded, transitive
+            "%s(included: %s, excluded: %s, depth: %d)", getClass().getSimpleName(), included, excluded, depth
         );
     }
 
diff --git a/maven-resolver-util/src/test/java/org/eclipse/aether/util/graph/selector/ScopeDependencySelectorTest.java b/maven-resolver-util/src/test/java/org/eclipse/aether/util/graph/selector/ScopeDependencySelectorTest.java
index 7d84258..f8324b5 100644
--- a/maven-resolver-util/src/test/java/org/eclipse/aether/util/graph/selector/ScopeDependencySelectorTest.java
+++ b/maven-resolver-util/src/test/java/org/eclipse/aether/util/graph/selector/ScopeDependencySelectorTest.java
@@ -31,8 +31,8 @@ public class ScopeDependencySelectorTest
     public void testToString()
     {
         assertEquals(
-            "ScopeDependencySelector(included: [foo], excluded: [bar], transitive: false)",
+            "ScopeDependencySelector(included: [foo], excluded: [bar], depth: 0)",
             new ScopeDependencySelector(Collections.singleton( "foo" ), Collections.singleton( "bar" ) ).toString()
         );
     }
-}
\ No newline at end of file
+}