You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sc...@apache.org on 2016/12/21 04:09:22 UTC
[2/3] maven-resolver git commit: [MRESOLVER-8]
ScopeDependencySelector incorrectly de-selects direct dependencies.
[MRESOLVER-8] ScopeDependencySelector incorrectly de-selects direct dependencies.
o Reverted any changes to the 'OptionalDependencySelector' to match release 1.0.2.v20150114.
o Updated class 'ScopeDependencySelector' to correctly decide a node is direct vs. transitive.
Project: http://git-wip-us.apache.org/repos/asf/maven-resolver/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-resolver/commit/9855af4f
Tree: http://git-wip-us.apache.org/repos/asf/maven-resolver/tree/9855af4f
Diff: http://git-wip-us.apache.org/repos/asf/maven-resolver/diff/9855af4f
Branch: refs/heads/master
Commit: 9855af4fbd6bb0f64750d27b2eee2e03b25b58ba
Parents: 65e1e5f
Author: Christian Schulte <sc...@apache.org>
Authored: Wed Dec 21 03:36:03 2016 +0100
Committer: Christian Schulte <sc...@apache.org>
Committed: Wed Dec 21 03:43:08 2016 +0100
----------------------------------------------------------------------
.../selector/OptionalDependencySelector.java | 31 ++++++----------
.../graph/selector/ScopeDependencySelector.java | 39 ++++++++------------
2 files changed, 27 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/9855af4f/maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/selector/OptionalDependencySelector.java
----------------------------------------------------------------------
diff --git a/maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/selector/OptionalDependencySelector.java b/maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/selector/OptionalDependencySelector.java
index d1a98dc..c377f24 100644
--- a/maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/selector/OptionalDependencySelector.java
+++ b/maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/selector/OptionalDependencySelector.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
@@ -32,41 +32,34 @@ public final class OptionalDependencySelector
implements DependencySelector
{
- private final boolean transitive;
+ private final int depth;
/**
* Creates a new selector to exclude optional transitive dependencies.
*/
public OptionalDependencySelector()
{
- this( false );
+ depth = 0;
}
- private OptionalDependencySelector( final boolean transitive )
+ private OptionalDependencySelector( int depth )
{
- super();
- this.transitive = transitive;
+ this.depth = depth;
}
public boolean selectDependency( Dependency dependency )
{
- return !this.transitive || !dependency.isOptional();
+ return depth < 2 || !dependency.isOptional();
}
public DependencySelector deriveChildSelector( DependencyCollectionContext context )
{
- OptionalDependencySelector child = this;
-
- if ( context.getDependency() != null && !child.transitive )
- {
- child = new OptionalDependencySelector( true );
- }
- if ( context.getDependency() == null && child.transitive )
+ if ( depth >= 2 )
{
- child = new OptionalDependencySelector( false );
+ return this;
}
- return child;
+ return new OptionalDependencySelector( depth + 1 );
}
@Override
@@ -82,14 +75,14 @@ public final class OptionalDependencySelector
}
OptionalDependencySelector that = (OptionalDependencySelector) obj;
- return this.transitive == that.transitive;
+ return depth == that.depth;
}
@Override
public int hashCode()
{
int hash = getClass().hashCode();
- hash = hash * 31 + ( ( (Boolean) this.transitive ).hashCode() );
+ hash = hash * 31 + depth;
return hash;
}
http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/9855af4f/maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/selector/ScopeDependencySelector.java
----------------------------------------------------------------------
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 b2ce23a..92db141 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
@@ -24,7 +24,6 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.TreeSet;
-
import org.eclipse.aether.collection.DependencyCollectionContext;
import org.eclipse.aether.collection.DependencySelector;
import org.eclipse.aether.graph.Dependency;
@@ -33,14 +32,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;
@@ -48,14 +47,14 @@ 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 )
{
super();
- this.transitive = false;
+ this.depth = 0;
this.included = clone( included );
this.excluded = clone( excluded );
}
@@ -82,7 +81,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,17 +89,17 @@ 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 )
{
super();
- this.transitive = transitive;
+ this.depth = depth;
this.included = included;
this.excluded = excluded;
}
public boolean selectDependency( Dependency dependency )
{
- return !this.transitive
+ return this.depth < 2
|| ( ( included == null || included.contains( dependency.getScope() ) )
&& ( excluded == null || !excluded.contains( dependency.getScope() ) ) );
@@ -108,18 +107,10 @@ public final class ScopeDependencySelector
public DependencySelector deriveChildSelector( DependencyCollectionContext context )
{
- ScopeDependencySelector child = this;
-
- if ( context.getDependency() != null && !child.transitive )
- {
- child = new ScopeDependencySelector( true, this.included, this.excluded );
- }
- if ( context.getDependency() == null && child.transitive )
- {
- child = new ScopeDependencySelector( false, this.included, this.excluded );
- }
+ return this.depth >= 2
+ ? this
+ : new ScopeDependencySelector( this.depth + 1, this.included, this.excluded );
- return child;
}
@Override
@@ -135,7 +126,7 @@ public final class ScopeDependencySelector
}
ScopeDependencySelector that = (ScopeDependencySelector) obj;
- return this.transitive == that.transitive && eq( included, that.included ) && eq( excluded, that.excluded );
+ return this.depth == that.depth && eq( included, that.included ) && eq( excluded, that.excluded );
}
private static <T> boolean eq( T o1, T o2 )
@@ -147,7 +138,7 @@ public final class ScopeDependencySelector
public int hashCode()
{
int hash = 17;
- hash = hash * 31 + ( ( (Boolean) this.transitive ).hashCode() );
+ hash = hash * 31 + this.depth;
hash = hash * 31 + ( included != null ? included.hashCode() : 0 );
hash = hash * 31 + ( excluded != null ? excluded.hashCode() : 0 );
return hash;