View Javadoc
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   * <p>
35   * Note regarding transitivity: it is broken, and should not be used.
36   */
37  public final class ClassicDependencyManager extends AbstractDependencyManager {
38      /**
39       * Creates a new dependency manager without any management information.
40       *
41       * @deprecated Use constructor that provides consumer application specific predicate.
42       */
43      @Deprecated
44      public ClassicDependencyManager() {
45          this(null);
46      }
47  
48      public ClassicDependencyManager(ScopeManager scopeManager) {
49          this(false, scopeManager);
50      }
51  
52      /**
53       * Creates a new dependency manager without any management information.
54       *
55       * @param transitive If true, this manager will collect (derive) until last node on graph. If false,
56       *                   it will work as original Maven 3 "classic" dependency manager, collect only up to
57       *                   depth of 2.
58       *
59       * @since 2.0.0
60       */
61      public ClassicDependencyManager(boolean transitive, ScopeManager scopeManager) {
62          super(transitive ? Integer.MAX_VALUE : 2, 2, scopeManager);
63      }
64  
65      @SuppressWarnings("checkstyle:ParameterNumber")
66      private ClassicDependencyManager(
67              int depth,
68              int deriveUntil,
69              int applyFrom,
70              Map<Object, Holder<String>> managedVersions,
71              Map<Object, Holder<String>> managedScopes,
72              Map<Object, Holder<Boolean>> managedOptionals,
73              Map<Object, Holder<String>> managedLocalPaths,
74              Map<Object, Collection<Holder<Collection<Exclusion>>>> managedExclusions,
75              SystemDependencyScope systemDependencyScope) {
76          super(
77                  depth,
78                  deriveUntil,
79                  applyFrom,
80                  managedVersions,
81                  managedScopes,
82                  managedOptionals,
83                  managedLocalPaths,
84                  managedExclusions,
85                  systemDependencyScope);
86      }
87  
88      @Override
89      public DependencyManager deriveChildManager(DependencyCollectionContext context) {
90          // MNG-4720: Maven2 backward compatibility
91          // Removing this IF makes one IT fail here (read comment above):
92          // https://github.com/apache/maven-integration-testing/blob/b4e8fd52b99a058336f9c7c5ec44fdbc1427759c/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4720DependencyManagementExclusionMergeTest.java#L67
93          if (depth == 1) {
94              return newInstance(managedVersions, managedScopes, managedOptionals, managedLocalPaths, managedExclusions);
95          }
96          return super.deriveChildManager(context);
97      }
98  
99      @Override
100     protected DependencyManager newInstance(
101             Map<Object, Holder<String>> managedVersions,
102             Map<Object, Holder<String>> managedScopes,
103             Map<Object, Holder<Boolean>> managedOptionals,
104             Map<Object, Holder<String>> managedLocalPaths,
105             Map<Object, Collection<Holder<Collection<Exclusion>>>> managedExclusions) {
106         return new ClassicDependencyManager(
107                 depth + 1,
108                 deriveUntil,
109                 applyFrom,
110                 managedVersions,
111                 managedScopes,
112                 managedOptionals,
113                 managedLocalPaths,
114                 managedExclusions,
115                 systemDependencyScope);
116     }
117 }