You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2017/01/22 14:02:10 UTC
[15/54] [abbrv] [partial] maven-resolver git commit: [MNG-6007]
renamed Aether to Maven Artifact Resolver
http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/AndDependencySelector.java
----------------------------------------------------------------------
diff --git a/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/AndDependencySelector.java b/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/AndDependencySelector.java
deleted file mode 100644
index f2a7e38..0000000
--- a/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/AndDependencySelector.java
+++ /dev/null
@@ -1,206 +0,0 @@
-package org.eclipse.aether.util.graph.selector;
-
-/*
- * 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.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-import org.eclipse.aether.collection.DependencyCollectionContext;
-import org.eclipse.aether.collection.DependencySelector;
-import org.eclipse.aether.graph.Dependency;
-
-/**
- * A dependency selector that combines zero or more other selectors using a logical {@code AND}. The resulting selector
- * selects a given dependency if and only if all constituent selectors do so.
- */
-public final class AndDependencySelector
- implements DependencySelector
-{
-
- private final Set<? extends DependencySelector> selectors;
-
- private int hashCode;
-
- /**
- * Creates a new selector from the specified selectors. Prefer
- * {@link #newInstance(DependencySelector, DependencySelector)} if any of the input selectors might be {@code null}.
- *
- * @param selectors The selectors to combine, may be {@code null} but must not contain {@code null} elements.
- */
- public AndDependencySelector( DependencySelector... selectors )
- {
- if ( selectors != null && selectors.length > 0 )
- {
- this.selectors = new LinkedHashSet<DependencySelector>( Arrays.asList( selectors ) );
- }
- else
- {
- this.selectors = Collections.emptySet();
- }
- }
-
- /**
- * Creates a new selector from the specified selectors.
- *
- * @param selectors The selectors to combine, may be {@code null} but must not contain {@code null} elements.
- */
- public AndDependencySelector( Collection<? extends DependencySelector> selectors )
- {
- if ( selectors != null && !selectors.isEmpty() )
- {
- this.selectors = new LinkedHashSet<DependencySelector>( selectors );
- }
- else
- {
- this.selectors = Collections.emptySet();
- }
- }
-
- private AndDependencySelector( Set<DependencySelector> selectors )
- {
- if ( selectors != null && !selectors.isEmpty() )
- {
- this.selectors = selectors;
- }
- else
- {
- this.selectors = Collections.emptySet();
- }
- }
-
- /**
- * Creates a new selector from the specified selectors.
- *
- * @param selector1 The first selector to combine, may be {@code null}.
- * @param selector2 The second selector to combine, may be {@code null}.
- * @return The combined selector or {@code null} if both selectors were {@code null}.
- */
- public static DependencySelector newInstance( DependencySelector selector1, DependencySelector selector2 )
- {
- if ( selector1 == null )
- {
- return selector2;
- }
- else if ( selector2 == null || selector2.equals( selector1 ) )
- {
- return selector1;
- }
- return new AndDependencySelector( selector1, selector2 );
- }
-
- public boolean selectDependency( Dependency dependency )
- {
- for ( DependencySelector selector : selectors )
- {
- if ( !selector.selectDependency( dependency ) )
- {
- return false;
- }
- }
- return true;
- }
-
- public DependencySelector deriveChildSelector( DependencyCollectionContext context )
- {
- int seen = 0;
- Set<DependencySelector> childSelectors = null;
-
- for ( DependencySelector selector : selectors )
- {
- DependencySelector childSelector = selector.deriveChildSelector( context );
- if ( childSelectors != null )
- {
- if ( childSelector != null )
- {
- childSelectors.add( childSelector );
- }
- }
- else if ( selector != childSelector )
- {
- childSelectors = new LinkedHashSet<DependencySelector>();
- if ( seen > 0 )
- {
- for ( DependencySelector s : selectors )
- {
- if ( childSelectors.size() >= seen )
- {
- break;
- }
- childSelectors.add( s );
- }
- }
- if ( childSelector != null )
- {
- childSelectors.add( childSelector );
- }
- }
- else
- {
- seen++;
- }
- }
-
- if ( childSelectors == null )
- {
- return this;
- }
- if ( childSelectors.size() <= 1 )
- {
- if ( childSelectors.isEmpty() )
- {
- return null;
- }
- return childSelectors.iterator().next();
- }
- return new AndDependencySelector( childSelectors );
- }
-
- @Override
- public boolean equals( Object obj )
- {
- if ( this == obj )
- {
- return true;
- }
- else if ( null == obj || !getClass().equals( obj.getClass() ) )
- {
- return false;
- }
-
- AndDependencySelector that = (AndDependencySelector) obj;
- return selectors.equals( that.selectors );
- }
-
- @Override
- public int hashCode()
- {
- if ( hashCode == 0 )
- {
- int hash = 17;
- hash = hash * 31 + selectors.hashCode();
- hashCode = hash;
- }
- return hashCode;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/ExclusionDependencySelector.java
----------------------------------------------------------------------
diff --git a/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/ExclusionDependencySelector.java b/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/ExclusionDependencySelector.java
deleted file mode 100644
index 221cf4f..0000000
--- a/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/ExclusionDependencySelector.java
+++ /dev/null
@@ -1,227 +0,0 @@
-package org.eclipse.aether.util.graph.selector;
-
-/*
- * 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.Arrays;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.TreeSet;
-
-import org.eclipse.aether.artifact.Artifact;
-import org.eclipse.aether.collection.DependencyCollectionContext;
-import org.eclipse.aether.collection.DependencySelector;
-import org.eclipse.aether.graph.Dependency;
-import org.eclipse.aether.graph.Exclusion;
-
-/**
- * A dependency selector that applies exclusions based on artifact coordinates.
- *
- * @see Dependency#getExclusions()
- */
-public final class ExclusionDependencySelector
- implements DependencySelector
-{
-
- // sorted and dupe-free array, faster to iterate than LinkedHashSet
- private final Exclusion[] exclusions;
-
- private int hashCode;
-
- /**
- * Creates a new selector without any exclusions.
- */
- public ExclusionDependencySelector()
- {
- this.exclusions = new Exclusion[0];
- }
-
- /**
- * Creates a new selector with the specified exclusions.
- *
- * @param exclusions The exclusions, may be {@code null}.
- */
- public ExclusionDependencySelector( Collection<Exclusion> exclusions )
- {
- if ( exclusions != null && !exclusions.isEmpty() )
- {
- TreeSet<Exclusion> sorted = new TreeSet<Exclusion>( ExclusionComparator.INSTANCE );
- sorted.addAll( exclusions );
- this.exclusions = sorted.toArray( new Exclusion[sorted.size()] );
- }
- else
- {
- this.exclusions = new Exclusion[0];
- }
- }
-
- private ExclusionDependencySelector( Exclusion[] exclusions )
- {
- this.exclusions = exclusions;
- }
-
- public boolean selectDependency( Dependency dependency )
- {
- Artifact artifact = dependency.getArtifact();
- for ( Exclusion exclusion : exclusions )
- {
- if ( matches( exclusion, artifact ) )
- {
- return false;
- }
- }
- return true;
- }
-
- private boolean matches( Exclusion exclusion, Artifact artifact )
- {
- if ( !matches( exclusion.getArtifactId(), artifact.getArtifactId() ) )
- {
- return false;
- }
- if ( !matches( exclusion.getGroupId(), artifact.getGroupId() ) )
- {
- return false;
- }
- if ( !matches( exclusion.getExtension(), artifact.getExtension() ) )
- {
- return false;
- }
- if ( !matches( exclusion.getClassifier(), artifact.getClassifier() ) )
- {
- return false;
- }
- return true;
- }
-
- private boolean matches( String pattern, String value )
- {
- return "*".equals( pattern ) || pattern.equals( value );
- }
-
- public DependencySelector deriveChildSelector( DependencyCollectionContext context )
- {
- Dependency dependency = context.getDependency();
- Collection<Exclusion> exclusions = ( dependency != null ) ? dependency.getExclusions() : null;
- if ( exclusions == null || exclusions.isEmpty() )
- {
- return this;
- }
-
- Exclusion[] merged = this.exclusions;
- int count = merged.length;
- for ( Exclusion exclusion : exclusions )
- {
- int index = Arrays.binarySearch( merged, exclusion, ExclusionComparator.INSTANCE );
- if ( index < 0 )
- {
- index = -( index + 1 );
- if ( count >= merged.length )
- {
- Exclusion[] tmp = new Exclusion[merged.length + exclusions.size()];
- System.arraycopy( merged, 0, tmp, 0, index );
- tmp[index] = exclusion;
- System.arraycopy( merged, index, tmp, index + 1, count - index );
- merged = tmp;
- }
- else
- {
- System.arraycopy( merged, index, merged, index + 1, count - index );
- merged[index] = exclusion;
- }
- count++;
- }
- }
- if ( merged == this.exclusions )
- {
- return this;
- }
- if ( merged.length != count )
- {
- Exclusion[] tmp = new Exclusion[count];
- System.arraycopy( merged, 0, tmp, 0, count );
- merged = tmp;
- }
-
- return new ExclusionDependencySelector( merged );
- }
-
- @Override
- public boolean equals( Object obj )
- {
- if ( this == obj )
- {
- return true;
- }
- else if ( null == obj || !getClass().equals( obj.getClass() ) )
- {
- return false;
- }
-
- ExclusionDependencySelector that = (ExclusionDependencySelector) obj;
- return Arrays.equals( exclusions, that.exclusions );
- }
-
- @Override
- public int hashCode()
- {
- if ( hashCode == 0 )
- {
- int hash = getClass().hashCode();
- hash = hash * 31 + Arrays.hashCode( exclusions );
- hashCode = hash;
- }
- return hashCode;
- }
-
- private static class ExclusionComparator
- implements Comparator<Exclusion>
- {
-
- static final ExclusionComparator INSTANCE = new ExclusionComparator();
-
- public int compare( Exclusion e1, Exclusion e2 )
- {
- if ( e1 == null )
- {
- return ( e2 == null ) ? 0 : 1;
- }
- else if ( e2 == null )
- {
- return -1;
- }
- int rel = e1.getArtifactId().compareTo( e2.getArtifactId() );
- if ( rel == 0 )
- {
- rel = e1.getGroupId().compareTo( e2.getGroupId() );
- if ( rel == 0 )
- {
- rel = e1.getExtension().compareTo( e2.getExtension() );
- if ( rel == 0 )
- {
- rel = e1.getClassifier().compareTo( e2.getClassifier() );
- }
- }
- }
- return rel;
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/OptionalDependencySelector.java
----------------------------------------------------------------------
diff --git a/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/OptionalDependencySelector.java b/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/OptionalDependencySelector.java
deleted file mode 100644
index 69bbda4..0000000
--- a/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/OptionalDependencySelector.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package org.eclipse.aether.util.graph.selector;
-
-/*
- * 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 org.eclipse.aether.collection.DependencyCollectionContext;
-import org.eclipse.aether.collection.DependencySelector;
-import org.eclipse.aether.graph.Dependency;
-
-/**
- * A dependency selector that excludes optional dependencies which occur beyond level one of the dependency graph.
- *
- * @see Dependency#isOptional()
- */
-public final class OptionalDependencySelector
- implements DependencySelector
-{
-
- private final int depth;
-
- /**
- * Creates a new selector to exclude optional transitive dependencies.
- */
- public OptionalDependencySelector()
- {
- depth = 0;
- }
-
- private OptionalDependencySelector( int depth )
- {
- this.depth = depth;
- }
-
- public boolean selectDependency( Dependency dependency )
- {
- return depth < 2 || !dependency.isOptional();
- }
-
- public DependencySelector deriveChildSelector( DependencyCollectionContext context )
- {
- if ( depth >= 2 )
- {
- return this;
- }
-
- return new OptionalDependencySelector( depth + 1 );
- }
-
- @Override
- public boolean equals( Object obj )
- {
- if ( this == obj )
- {
- return true;
- }
- else if ( null == obj || !getClass().equals( obj.getClass() ) )
- {
- return false;
- }
-
- OptionalDependencySelector that = (OptionalDependencySelector) obj;
- return depth == that.depth;
- }
-
- @Override
- public int hashCode()
- {
- int hash = getClass().hashCode();
- hash = hash * 31 + depth;
- return hash;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/ScopeDependencySelector.java
----------------------------------------------------------------------
diff --git a/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/ScopeDependencySelector.java b/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/ScopeDependencySelector.java
deleted file mode 100644
index 552fc09..0000000
--- a/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/ScopeDependencySelector.java
+++ /dev/null
@@ -1,151 +0,0 @@
-package org.eclipse.aether.util.graph.selector;
-
-/*
- * 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.ArrayList;
-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;
-
-/**
- * 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 Collection<String> included;
-
- private final Collection<String> excluded;
-
- /**
- * 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.included = clone( included );
- this.excluded = clone( excluded );
- }
-
- private static Collection<String> clone( Collection<String> scopes )
- {
- Collection<String> copy;
- if ( scopes == null || scopes.isEmpty() )
- {
- // checking for null is faster than isEmpty()
- copy = null;
- }
- else
- {
- copy = new HashSet<String>( scopes );
- if ( copy.size() <= 2 )
- {
- // contains() is faster for smallish array (sorted for equals()!)
- copy = new ArrayList<String>( new TreeSet<String>( copy ) );
- }
- }
- return copy;
- }
-
- /**
- * 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 )
- {
- this( null, ( excluded != null ) ? Arrays.asList( excluded ) : null );
- }
-
- private ScopeDependencySelector( boolean transitive, Collection<String> included, Collection<String> excluded )
- {
- this.transitive = transitive;
- 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 ) );
- }
-
- public DependencySelector deriveChildSelector( DependencyCollectionContext context )
- {
- if ( this.transitive || context.getDependency() == null )
- {
- return this;
- }
-
- return new ScopeDependencySelector( true, included, excluded );
- }
-
- @Override
- public boolean equals( Object obj )
- {
- if ( this == obj )
- {
- return true;
- }
- else if ( null == obj || !getClass().equals( obj.getClass() ) )
- {
- return false;
- }
-
- ScopeDependencySelector that = (ScopeDependencySelector) obj;
- return transitive == that.transitive && eq( included, that.included ) && eq( excluded, that.excluded );
- }
-
- private static <T> boolean eq( T o1, T o2 )
- {
- return ( o1 != null ) ? o1.equals( o2 ) : o2 == null;
- }
-
- @Override
- public int hashCode()
- {
- int hash = 17;
- hash = hash * 31 + ( transitive ? 1 : 0 );
- hash = hash * 31 + ( included != null ? included.hashCode() : 0 );
- hash = hash * 31 + ( excluded != null ? excluded.hashCode() : 0 );
- return hash;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/StaticDependencySelector.java
----------------------------------------------------------------------
diff --git a/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/StaticDependencySelector.java b/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/StaticDependencySelector.java
deleted file mode 100644
index 41ce0e0..0000000
--- a/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/StaticDependencySelector.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package org.eclipse.aether.util.graph.selector;
-
-/*
- * 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 org.eclipse.aether.collection.DependencyCollectionContext;
-import org.eclipse.aether.collection.DependencySelector;
-import org.eclipse.aether.graph.Dependency;
-
-/**
- * A dependency selector that always includes or excludes dependencies.
- */
-public final class StaticDependencySelector
- implements DependencySelector
-{
-
- private final boolean select;
-
- /**
- * Creates a new selector with the specified selection behavior.
- *
- * @param select {@code true} to select all dependencies, {@code false} to exclude all dependencies.
- */
- public StaticDependencySelector( boolean select )
- {
- this.select = select;
- }
-
- public boolean selectDependency( Dependency dependency )
- {
- return select;
- }
-
- public DependencySelector deriveChildSelector( DependencyCollectionContext context )
- {
- return this;
- }
-
- @Override
- public boolean equals( Object obj )
- {
- if ( this == obj )
- {
- return true;
- }
- else if ( null == obj || !getClass().equals( obj.getClass() ) )
- {
- return false;
- }
-
- StaticDependencySelector that = (StaticDependencySelector) obj;
- return select == that.select;
- }
-
- @Override
- public int hashCode()
- {
- int hash = getClass().hashCode();
- hash = hash * 31 + ( select ? 1 : 0 );
- return hash;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/package-info.java
----------------------------------------------------------------------
diff --git a/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/package-info.java b/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/package-info.java
deleted file mode 100644
index 3c3cf3c..0000000
--- a/aether-util/src/main/java/org/eclipse/aether/util/graph/selector/package-info.java
+++ /dev/null
@@ -1,24 +0,0 @@
-// CHECKSTYLE_OFF: RegexpHeader
-/*
- * 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.
- */
-/**
- * Various dependency selectors for building a dependency graph.
- */
-package org.eclipse.aether.util.graph.selector;
-
http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/graph/transformer/ChainedDependencyGraphTransformer.java
----------------------------------------------------------------------
diff --git a/aether-util/src/main/java/org/eclipse/aether/util/graph/transformer/ChainedDependencyGraphTransformer.java b/aether-util/src/main/java/org/eclipse/aether/util/graph/transformer/ChainedDependencyGraphTransformer.java
deleted file mode 100644
index d7f1771..0000000
--- a/aether-util/src/main/java/org/eclipse/aether/util/graph/transformer/ChainedDependencyGraphTransformer.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package org.eclipse.aether.util.graph.transformer;
-
-/*
- * 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 org.eclipse.aether.RepositoryException;
-import org.eclipse.aether.collection.DependencyGraphTransformationContext;
-import org.eclipse.aether.collection.DependencyGraphTransformer;
-import org.eclipse.aether.graph.DependencyNode;
-
-/**
- * A dependency graph transformer that chains other transformers.
- */
-public final class ChainedDependencyGraphTransformer
- implements DependencyGraphTransformer
-{
-
- private final DependencyGraphTransformer[] transformers;
-
- /**
- * Creates a new transformer that chains the specified transformers.
- *
- * @param transformers The transformers to chain, may be {@code null} or empty.
- */
- public ChainedDependencyGraphTransformer( DependencyGraphTransformer... transformers )
- {
- if ( transformers == null )
- {
- this.transformers = new DependencyGraphTransformer[0];
- }
- else
- {
- this.transformers = transformers;
- }
- }
-
- /**
- * Creates a new transformer that chains the specified transformers or simply returns one of them if the other one
- * is {@code null}.
- *
- * @param transformer1 The first transformer of the chain, may be {@code null}.
- * @param transformer2 The second transformer of the chain, may be {@code null}.
- * @return The chained transformer or {@code null} if both input transformers are {@code null}.
- */
- public static DependencyGraphTransformer newInstance( DependencyGraphTransformer transformer1,
- DependencyGraphTransformer transformer2 )
- {
- if ( transformer1 == null )
- {
- return transformer2;
- }
- else if ( transformer2 == null )
- {
- return transformer1;
- }
- return new ChainedDependencyGraphTransformer( transformer1, transformer2 );
- }
-
- public DependencyNode transformGraph( DependencyNode node, DependencyGraphTransformationContext context )
- throws RepositoryException
- {
- for ( DependencyGraphTransformer transformer : transformers )
- {
- node = transformer.transformGraph( node, context );
- }
- return node;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/graph/transformer/ConflictIdSorter.java
----------------------------------------------------------------------
diff --git a/aether-util/src/main/java/org/eclipse/aether/util/graph/transformer/ConflictIdSorter.java b/aether-util/src/main/java/org/eclipse/aether/util/graph/transformer/ConflictIdSorter.java
deleted file mode 100644
index c2122fa..0000000
--- a/aether-util/src/main/java/org/eclipse/aether/util/graph/transformer/ConflictIdSorter.java
+++ /dev/null
@@ -1,370 +0,0 @@
-package org.eclipse.aether.util.graph.transformer;
-
-/*
- * 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.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.IdentityHashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.aether.RepositoryException;
-import org.eclipse.aether.collection.DependencyGraphTransformationContext;
-import org.eclipse.aether.collection.DependencyGraphTransformer;
-import org.eclipse.aether.graph.DependencyNode;
-
-/**
- * A dependency graph transformer that creates a topological sorting of the conflict ids which have been assigned to the
- * dependency nodes. Conflict ids are sorted according to the dependency relation induced by the dependency graph. This
- * transformer will query the key {@link TransformationContextKeys#CONFLICT_IDS} in the transformation context for an
- * existing mapping of nodes to their conflicts ids. In absence of this map, the transformer will automatically invoke
- * the {@link ConflictMarker} to calculate the conflict ids. When this transformer has executed, the transformation
- * context holds a {@code List<Object>} that denotes the topologically sorted conflict ids. The list will be stored
- * using the key {@link TransformationContextKeys#SORTED_CONFLICT_IDS}. In addition, the transformer will store a
- * {@code Collection<Collection<Object>>} using the key {@link TransformationContextKeys#CYCLIC_CONFLICT_IDS} that
- * describes cycles among conflict ids.
- */
-public final class ConflictIdSorter
- implements DependencyGraphTransformer
-{
-
- public DependencyNode transformGraph( DependencyNode node, DependencyGraphTransformationContext context )
- throws RepositoryException
- {
- Map<?, ?> conflictIds = (Map<?, ?>) context.get( TransformationContextKeys.CONFLICT_IDS );
- if ( conflictIds == null )
- {
- ConflictMarker marker = new ConflictMarker();
- marker.transformGraph( node, context );
-
- conflictIds = (Map<?, ?>) context.get( TransformationContextKeys.CONFLICT_IDS );
- }
-
- @SuppressWarnings( "unchecked" )
- Map<String, Object> stats = (Map<String, Object>) context.get( TransformationContextKeys.STATS );
- long time1 = System.currentTimeMillis();
-
- Map<Object, ConflictId> ids = new LinkedHashMap<Object, ConflictId>( 256 );
-
- {
- ConflictId id = null;
- Object key = conflictIds.get( node );
- if ( key != null )
- {
- id = new ConflictId( key, 0 );
- ids.put( key, id );
- }
-
- Map<DependencyNode, Object> visited = new IdentityHashMap<DependencyNode, Object>( conflictIds.size() );
-
- buildConflitIdDAG( ids, node, id, 0, visited, conflictIds );
- }
-
- long time2 = System.currentTimeMillis();
-
- int cycles = topsortConflictIds( ids.values(), context );
-
- if ( stats != null )
- {
- long time3 = System.currentTimeMillis();
- stats.put( "ConflictIdSorter.graphTime", time2 - time1 );
- stats.put( "ConflictIdSorter.topsortTime", time3 - time2 );
- stats.put( "ConflictIdSorter.conflictIdCount", ids.size() );
- stats.put( "ConflictIdSorter.conflictIdCycleCount", cycles );
- }
-
- return node;
- }
-
- private void buildConflitIdDAG( Map<Object, ConflictId> ids, DependencyNode node, ConflictId id, int depth,
- Map<DependencyNode, Object> visited, Map<?, ?> conflictIds )
- {
- if ( visited.put( node, Boolean.TRUE ) != null )
- {
- return;
- }
-
- depth++;
-
- for ( DependencyNode child : node.getChildren() )
- {
- Object key = conflictIds.get( child );
- ConflictId childId = ids.get( key );
- if ( childId == null )
- {
- childId = new ConflictId( key, depth );
- ids.put( key, childId );
- }
- else
- {
- childId.pullup( depth );
- }
-
- if ( id != null )
- {
- id.add( childId );
- }
-
- buildConflitIdDAG( ids, child, childId, depth, visited, conflictIds );
- }
- }
-
- private int topsortConflictIds( Collection<ConflictId> conflictIds, DependencyGraphTransformationContext context )
- {
- List<Object> sorted = new ArrayList<Object>( conflictIds.size() );
-
- RootQueue roots = new RootQueue( conflictIds.size() / 2 );
- for ( ConflictId id : conflictIds )
- {
- if ( id.inDegree <= 0 )
- {
- roots.add( id );
- }
- }
-
- processRoots( sorted, roots );
-
- boolean cycle = sorted.size() < conflictIds.size();
-
- while ( sorted.size() < conflictIds.size() )
- {
- // cycle -> deal gracefully with nodes still having positive in-degree
-
- ConflictId nearest = null;
- for ( ConflictId id : conflictIds )
- {
- if ( id.inDegree <= 0 )
- {
- continue;
- }
- if ( nearest == null || id.minDepth < nearest.minDepth
- || ( id.minDepth == nearest.minDepth && id.inDegree < nearest.inDegree ) )
- {
- nearest = id;
- }
- }
-
- nearest.inDegree = 0;
- roots.add( nearest );
-
- processRoots( sorted, roots );
- }
-
- Collection<Collection<Object>> cycles = Collections.emptySet();
- if ( cycle )
- {
- cycles = findCycles( conflictIds );
- }
-
- context.put( TransformationContextKeys.SORTED_CONFLICT_IDS, sorted );
- context.put( TransformationContextKeys.CYCLIC_CONFLICT_IDS, cycles );
-
- return cycles.size();
- }
-
- private void processRoots( List<Object> sorted, RootQueue roots )
- {
- while ( !roots.isEmpty() )
- {
- ConflictId root = roots.remove();
-
- sorted.add( root.key );
-
- for ( ConflictId child : root.children )
- {
- child.inDegree--;
- if ( child.inDegree == 0 )
- {
- roots.add( child );
- }
- }
- }
- }
-
- private Collection<Collection<Object>> findCycles( Collection<ConflictId> conflictIds )
- {
- Collection<Collection<Object>> cycles = new HashSet<Collection<Object>>();
-
- Map<Object, Integer> stack = new HashMap<Object, Integer>( 128 );
- Map<ConflictId, Object> visited = new IdentityHashMap<ConflictId, Object>( conflictIds.size() );
- for ( ConflictId id : conflictIds )
- {
- findCycles( id, visited, stack, cycles );
- }
-
- return cycles;
- }
-
- private void findCycles( ConflictId id, Map<ConflictId, Object> visited, Map<Object, Integer> stack,
- Collection<Collection<Object>> cycles )
- {
- Integer depth = stack.put( id.key, stack.size() );
- if ( depth != null )
- {
- stack.put( id.key, depth );
- Collection<Object> cycle = new HashSet<Object>();
- for ( Map.Entry<Object, Integer> entry : stack.entrySet() )
- {
- if ( entry.getValue() >= depth )
- {
- cycle.add( entry.getKey() );
- }
- }
- cycles.add( cycle );
- }
- else
- {
- if ( visited.put( id, Boolean.TRUE ) == null )
- {
- for ( ConflictId childId : id.children )
- {
- findCycles( childId, visited, stack, cycles );
- }
- }
- stack.remove( id.key );
- }
- }
-
- static final class ConflictId
- {
-
- final Object key;
-
- Collection<ConflictId> children = Collections.emptySet();
-
- int inDegree;
-
- int minDepth;
-
- public ConflictId( Object key, int depth )
- {
- this.key = key;
- this.minDepth = depth;
- }
-
- public void add( ConflictId child )
- {
- if ( children.isEmpty() )
- {
- children = new HashSet<ConflictId>();
- }
- if ( children.add( child ) )
- {
- child.inDegree++;
- }
- }
-
- public void pullup( int depth )
- {
- if ( depth < minDepth )
- {
- minDepth = depth;
- depth++;
- for ( ConflictId child : children )
- {
- child.pullup( depth );
- }
- }
- }
-
- @Override
- public boolean equals( Object obj )
- {
- if ( this == obj )
- {
- return true;
- }
- else if ( !( obj instanceof ConflictId ) )
- {
- return false;
- }
- ConflictId that = (ConflictId) obj;
- return this.key.equals( that.key );
- }
-
- @Override
- public int hashCode()
- {
- return key.hashCode();
- }
-
- @Override
- public String toString()
- {
- return key + " @ " + minDepth + " <" + inDegree;
- }
-
- }
-
- static final class RootQueue
- {
-
- private int nextOut;
-
- private int nextIn;
-
- private ConflictId[] ids;
-
- RootQueue( int capacity )
- {
- ids = new ConflictId[capacity + 16];
- }
-
- boolean isEmpty()
- {
- return nextOut >= nextIn;
- }
-
- void add( ConflictId id )
- {
- if ( nextOut >= nextIn && nextOut > 0 )
- {
- nextIn -= nextOut;
- nextOut = 0;
- }
- if ( nextIn >= ids.length )
- {
- ConflictId[] tmp = new ConflictId[ids.length + ids.length / 2 + 16];
- System.arraycopy( ids, nextOut, tmp, 0, nextIn - nextOut );
- ids = tmp;
- nextIn -= nextOut;
- nextOut = 0;
- }
- int i;
- for ( i = nextIn - 1; i >= nextOut && id.minDepth < ids[i].minDepth; i-- )
- {
- ids[i + 1] = ids[i];
- }
- ids[i + 1] = id;
- nextIn++;
- }
-
- ConflictId remove()
- {
- return ids[nextOut++];
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/graph/transformer/ConflictMarker.java
----------------------------------------------------------------------
diff --git a/aether-util/src/main/java/org/eclipse/aether/util/graph/transformer/ConflictMarker.java b/aether-util/src/main/java/org/eclipse/aether/util/graph/transformer/ConflictMarker.java
deleted file mode 100644
index a3fb483..0000000
--- a/aether-util/src/main/java/org/eclipse/aether/util/graph/transformer/ConflictMarker.java
+++ /dev/null
@@ -1,315 +0,0 @@
-package org.eclipse.aether.util.graph.transformer;
-
-/*
- * 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.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.IdentityHashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.aether.RepositoryException;
-import org.eclipse.aether.artifact.Artifact;
-import org.eclipse.aether.collection.DependencyGraphTransformationContext;
-import org.eclipse.aether.collection.DependencyGraphTransformer;
-import org.eclipse.aether.graph.Dependency;
-import org.eclipse.aether.graph.DependencyNode;
-
-/**
- * A dependency graph transformer that identifies conflicting dependencies. When this transformer has executed, the
- * transformation context holds a {@code Map<DependencyNode, Object>} where dependency nodes that belong to the same
- * conflict group will have an equal conflict identifier. This map is stored using the key
- * {@link TransformationContextKeys#CONFLICT_IDS}.
- */
-public final class ConflictMarker
- implements DependencyGraphTransformer
-{
-
- /**
- * After the execution of this method, every DependencyNode with an attached dependency is member of one conflict
- * group.
- *
- * @see DependencyGraphTransformer#transformGraph(DependencyNode, DependencyGraphTransformationContext)
- */
- public DependencyNode transformGraph( DependencyNode node, DependencyGraphTransformationContext context )
- throws RepositoryException
- {
- @SuppressWarnings( "unchecked" )
- Map<String, Object> stats = (Map<String, Object>) context.get( TransformationContextKeys.STATS );
- long time1 = System.currentTimeMillis();
-
- Map<DependencyNode, Object> nodes = new IdentityHashMap<DependencyNode, Object>( 1024 );
- Map<Object, ConflictGroup> groups = new HashMap<Object, ConflictGroup>( 1024 );
-
- analyze( node, nodes, groups, new int[] { 0 } );
-
- long time2 = System.currentTimeMillis();
-
- Map<DependencyNode, Object> conflictIds = mark( nodes.keySet(), groups );
-
- context.put( TransformationContextKeys.CONFLICT_IDS, conflictIds );
-
- if ( stats != null )
- {
- long time3 = System.currentTimeMillis();
- stats.put( "ConflictMarker.analyzeTime", time2 - time1 );
- stats.put( "ConflictMarker.markTime", time3 - time2 );
- stats.put( "ConflictMarker.nodeCount", nodes.size() );
- }
-
- return node;
- }
-
- private void analyze( DependencyNode node, Map<DependencyNode, Object> nodes, Map<Object, ConflictGroup> groups,
- int[] counter )
- {
- if ( nodes.put( node, Boolean.TRUE ) != null )
- {
- return;
- }
-
- Set<Object> keys = getKeys( node );
- if ( !keys.isEmpty() )
- {
- ConflictGroup group = null;
- boolean fixMappings = false;
-
- for ( Object key : keys )
- {
- ConflictGroup g = groups.get( key );
-
- if ( group != g )
- {
- if ( group == null )
- {
- Set<Object> newKeys = merge( g.keys, keys );
- if ( newKeys == g.keys )
- {
- group = g;
- break;
- }
- else
- {
- group = new ConflictGroup( newKeys, counter[0]++ );
- fixMappings = true;
- }
- }
- else if ( g == null )
- {
- fixMappings = true;
- }
- else
- {
- Set<Object> newKeys = merge( g.keys, group.keys );
- if ( newKeys == g.keys )
- {
- group = g;
- fixMappings = false;
- break;
- }
- else if ( newKeys != group.keys )
- {
- group = new ConflictGroup( newKeys, counter[0]++ );
- fixMappings = true;
- }
- }
- }
- }
-
- if ( group == null )
- {
- group = new ConflictGroup( keys, counter[0]++ );
- fixMappings = true;
- }
- if ( fixMappings )
- {
- for ( Object key : group.keys )
- {
- groups.put( key, group );
- }
- }
- }
-
- for ( DependencyNode child : node.getChildren() )
- {
- analyze( child, nodes, groups, counter );
- }
- }
-
- private Set<Object> merge( Set<Object> keys1, Set<Object> keys2 )
- {
- int size1 = keys1.size();
- int size2 = keys2.size();
-
- if ( size1 < size2 )
- {
- if ( keys2.containsAll( keys1 ) )
- {
- return keys2;
- }
- }
- else
- {
- if ( keys1.containsAll( keys2 ) )
- {
- return keys1;
- }
- }
-
- Set<Object> keys = new HashSet<Object>();
- keys.addAll( keys1 );
- keys.addAll( keys2 );
- return keys;
- }
-
- private Set<Object> getKeys( DependencyNode node )
- {
- Set<Object> keys;
-
- Dependency dependency = node.getDependency();
-
- if ( dependency == null )
- {
- keys = Collections.emptySet();
- }
- else
- {
- Object key = toKey( dependency.getArtifact() );
-
- if ( node.getRelocations().isEmpty() && node.getAliases().isEmpty() )
- {
- keys = Collections.singleton( key );
- }
- else
- {
- keys = new HashSet<Object>();
- keys.add( key );
-
- for ( Artifact relocation : node.getRelocations() )
- {
- key = toKey( relocation );
- keys.add( key );
- }
-
- for ( Artifact alias : node.getAliases() )
- {
- key = toKey( alias );
- keys.add( key );
- }
- }
- }
-
- return keys;
- }
-
- private Map<DependencyNode, Object> mark( Collection<DependencyNode> nodes, Map<Object, ConflictGroup> groups )
- {
- Map<DependencyNode, Object> conflictIds = new IdentityHashMap<DependencyNode, Object>( nodes.size() + 1 );
-
- for ( DependencyNode node : nodes )
- {
- Dependency dependency = node.getDependency();
- if ( dependency != null )
- {
- Object key = toKey( dependency.getArtifact() );
- conflictIds.put( node, groups.get( key ).index );
- }
- }
-
- return conflictIds;
- }
-
- private static Object toKey( Artifact artifact )
- {
- return new Key( artifact );
- }
-
- static class ConflictGroup
- {
-
- final Set<Object> keys;
-
- final int index;
-
- public ConflictGroup( Set<Object> keys, int index )
- {
- this.keys = keys;
- this.index = index;
- }
-
- @Override
- public String toString()
- {
- return String.valueOf( keys );
- }
-
- }
-
- static class Key
- {
-
- private final Artifact artifact;
-
- public Key( Artifact artifact )
- {
- this.artifact = artifact;
- }
-
- @Override
- public boolean equals( Object obj )
- {
- if ( obj == this )
- {
- return true;
- }
- else if ( !( obj instanceof Key ) )
- {
- return false;
- }
- Key that = (Key) obj;
- return artifact.getArtifactId().equals( that.artifact.getArtifactId() )
- && artifact.getGroupId().equals( that.artifact.getGroupId() )
- && artifact.getExtension().equals( that.artifact.getExtension() )
- && artifact.getClassifier().equals( that.artifact.getClassifier() );
- }
-
- @Override
- public int hashCode()
- {
- int hash = 17;
- hash = hash * 31 + artifact.getArtifactId().hashCode();
- hash = hash * 31 + artifact.getGroupId().hashCode();
- hash = hash * 31 + artifact.getClassifier().hashCode();
- hash = hash * 31 + artifact.getExtension().hashCode();
- return hash;
- }
-
- @Override
- public String toString()
- {
- return artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getClassifier() + ':'
- + artifact.getExtension();
- }
-
- }
-
-}