slachiewicz commented on a change in pull request #35: [MRESOLVER-10] New class 'TransitiveDependencyManager' URL: https://github.com/apache/maven-resolver/pull/35#discussion_r283651200
########## File path: maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/manager/TransitiveDependencyManager.java ########## @@ -0,0 +1,307 @@ +package org.eclipse.aether.util.graph.manager; + +/* + * 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.LinkedHashSet; +import java.util.Map; +import java.util.Objects; + +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.artifact.ArtifactProperties; +import org.eclipse.aether.collection.DependencyCollectionContext; +import org.eclipse.aether.collection.DependencyManagement; +import org.eclipse.aether.collection.DependencyManager; +import org.eclipse.aether.graph.Dependency; +import org.eclipse.aether.graph.Exclusion; +import org.eclipse.aether.util.artifact.JavaScopes; + +/** + * A dependency manager managing transitive dependencies supporting transitive dependency management. + * + * @author Christian Schulte + * @since 1.4.0 + */ +public final class TransitiveDependencyManager + implements DependencyManager +{ + + private final Map<Object, String> managedVersions; + + private final Map<Object, String> managedScopes; + + private final Map<Object, Boolean> managedOptionals; + + private final Map<Object, String> managedLocalPaths; + + private final Map<Object, Collection<Exclusion>> managedExclusions; + + private final int depth; + + private int hashCode; + + /** + * Creates a new dependency manager without any management information. + */ + public TransitiveDependencyManager() + { + this( 0, 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, + final Map<Object, String> managedVersions, + final Map<Object, String> managedScopes, + final Map<Object, Boolean> managedOptionals, + final Map<Object, String> managedLocalPaths, + final Map<Object, Collection<Exclusion>> managedExclusions ) + { + super(); + this.depth = depth; + this.managedVersions = managedVersions; + this.managedScopes = managedScopes; + this.managedOptionals = managedOptionals; + this.managedLocalPaths = managedLocalPaths; + this.managedExclusions = managedExclusions; + } + + public DependencyManager deriveChildManager( final DependencyCollectionContext context ) + { + Map<Object, String> versions = managedVersions; + Map<Object, String> scopes = managedScopes; + Map<Object, Boolean> optionals = managedOptionals; + Map<Object, String> localPaths = managedLocalPaths; + Map<Object, Collection<Exclusion>> exclusions = managedExclusions; + + for ( Dependency managedDependency : context.getManagedDependencies() ) + { + Artifact artifact = managedDependency.getArtifact(); + Object key = getKey( artifact ); + + String version = artifact.getVersion(); + if ( version.length() > 0 && !versions.containsKey( key ) ) + { + if ( versions == managedVersions ) Review comment: that was in original PR ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
