001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.eclipse.aether.util.graph.manager;
020
021import java.util.ArrayList;
022import java.util.Collection;
023
024import org.eclipse.aether.collection.DependencyManager;
025import org.eclipse.aether.graph.Exclusion;
026import org.eclipse.aether.scope.ScopeManager;
027import org.eclipse.aether.scope.SystemDependencyScope;
028
029/**
030 * A dependency manager managing transitive dependencies supporting transitive dependency management.
031 * <p>
032 * This manager is similar to "classic", it has {@code deriveUntil=Integer.MAX_VALUE} (unlike 2 as in "classic") and
033 * {@code applyFrom=2}.
034 *
035 * @author Christian Schulte
036 * @since 1.4.0
037 */
038public final class TransitiveDependencyManager extends AbstractDependencyManager {
039    /**
040     * Creates a new dependency manager without any management information.
041     *
042     * @deprecated Use constructor that provides consumer application specific predicate.
043     */
044    @Deprecated
045    public TransitiveDependencyManager() {
046        this(null);
047    }
048
049    public TransitiveDependencyManager(ScopeManager scopeManager) {
050        super(Integer.MAX_VALUE, 2, scopeManager);
051    }
052
053    @SuppressWarnings("checkstyle:ParameterNumber")
054    private TransitiveDependencyManager(
055            ArrayList<AbstractDependencyManager> path,
056            int depth,
057            int deriveUntil,
058            int applyFrom,
059            MMap<Key, String> managedVersions,
060            MMap<Key, String> managedScopes,
061            MMap<Key, Boolean> managedOptionals,
062            MMap<Key, String> managedLocalPaths,
063            MMap<Key, Holder<Collection<Exclusion>>> managedExclusions,
064            SystemDependencyScope systemDependencyScope) {
065        super(
066                path,
067                depth,
068                deriveUntil,
069                applyFrom,
070                managedVersions,
071                managedScopes,
072                managedOptionals,
073                managedLocalPaths,
074                managedExclusions,
075                systemDependencyScope);
076    }
077
078    @Override
079    protected DependencyManager newInstance(
080            MMap<Key, String> managedVersions,
081            MMap<Key, String> managedScopes,
082            MMap<Key, Boolean> managedOptionals,
083            MMap<Key, String> managedLocalPaths,
084            MMap<Key, Holder<Collection<Exclusion>>> managedExclusions) {
085        ArrayList<AbstractDependencyManager> path = new ArrayList<>(this.path);
086        path.add(this);
087        return new TransitiveDependencyManager(
088                path,
089                depth + 1,
090                deriveUntil,
091                applyFrom,
092                managedVersions,
093                managedScopes,
094                managedOptionals,
095                managedLocalPaths,
096                managedExclusions,
097                systemDependencyScope);
098    }
099}