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