1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.eclipse.aether.util.graph.manager;
20
21 import java.util.Collection;
22 import java.util.Map;
23
24 import org.eclipse.aether.collection.DependencyCollectionContext;
25 import org.eclipse.aether.collection.DependencyManager;
26 import org.eclipse.aether.graph.Exclusion;
27 import org.eclipse.aether.scope.ScopeManager;
28 import org.eclipse.aether.scope.SystemDependencyScope;
29
30 /**
31 * A dependency manager that mimics the way Maven 2.x works. This manager was used throughout all Maven 3.x versions.
32 * <p>
33 * This manager has {@code deriveUntil=2} and {@code applyFrom=2}.
34 */
35 public final class ClassicDependencyManager extends AbstractDependencyManager {
36 /**
37 * Creates a new dependency manager without any management information.
38 *
39 * @deprecated Use constructor that provides consumer application specific predicate.
40 */
41 @Deprecated
42 public ClassicDependencyManager() {
43 this(null);
44 }
45
46 public ClassicDependencyManager(ScopeManager scopeManager) {
47 this(false, scopeManager);
48 }
49
50 /**
51 * Creates a new dependency manager without any management information.
52 *
53 * @param transitive If true, this manager will collect (derive) until last node on graph. If false,
54 * it will work as original Maven 3 "classic" dependency manager, collect only up to
55 * depth of 2.
56 *
57 * @since 2.0.0
58 */
59 public ClassicDependencyManager(boolean transitive, ScopeManager scopeManager) {
60 super(transitive ? Integer.MAX_VALUE : 2, 2, scopeManager);
61 }
62
63 @SuppressWarnings("checkstyle:ParameterNumber")
64 private ClassicDependencyManager(
65 int depth,
66 int deriveUntil,
67 int applyFrom,
68 Map<Object, String> managedVersions,
69 Map<Object, String> managedScopes,
70 Map<Object, Boolean> managedOptionals,
71 Map<Object, String> managedLocalPaths,
72 Map<Object, Collection<Exclusion>> managedExclusions,
73 SystemDependencyScope systemDependencyScope) {
74 super(
75 depth,
76 deriveUntil,
77 applyFrom,
78 managedVersions,
79 managedScopes,
80 managedOptionals,
81 managedLocalPaths,
82 managedExclusions,
83 systemDependencyScope);
84 }
85
86 @Override
87 public DependencyManager deriveChildManager(DependencyCollectionContext context) {
88 // MNG-4720: Maven2 backward compatibility
89 // Removing this IF makes one IT fail here (read comment above):
90 // https://github.com/apache/maven-integration-testing/blob/b4e8fd52b99a058336f9c7c5ec44fdbc1427759c/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4720DependencyManagementExclusionMergeTest.java#L67
91 if (depth == 1) {
92 return newInstance(managedVersions, managedScopes, managedOptionals, managedLocalPaths, managedExclusions);
93 }
94 return super.deriveChildManager(context);
95 }
96
97 @Override
98 protected DependencyManager newInstance(
99 Map<Object, String> managedVersions,
100 Map<Object, String> managedScopes,
101 Map<Object, Boolean> managedOptionals,
102 Map<Object, String> managedLocalPaths,
103 Map<Object, Collection<Exclusion>> managedExclusions) {
104 return new ClassicDependencyManager(
105 depth + 1,
106 deriveUntil,
107 applyFrom,
108 managedVersions,
109 managedScopes,
110 managedOptionals,
111 managedLocalPaths,
112 managedExclusions,
113 systemDependencyScope);
114 }
115 }