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.ArrayList;
22  import java.util.Collection;
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              ArrayList<AbstractDependencyManager> path,
68              int depth,
69              int deriveUntil,
70              int applyFrom,
71              MMap<Key, String> managedVersions,
72              MMap<Key, String> managedScopes,
73              MMap<Key, Boolean> managedOptionals,
74              MMap<Key, String> managedLocalPaths,
75              MMap<Key, Holder<Collection<Exclusion>>> managedExclusions,
76              SystemDependencyScope systemDependencyScope) {
77          super(
78                  path,
79                  depth,
80                  deriveUntil,
81                  applyFrom,
82                  managedVersions,
83                  managedScopes,
84                  managedOptionals,
85                  managedLocalPaths,
86                  managedExclusions,
87                  systemDependencyScope);
88      }
89  
90      @Override
91      public DependencyManager deriveChildManager(DependencyCollectionContext context) {
92          // MNG-4720: Maven2 backward compatibility
93          // Removing this IF makes one IT fail here (read comment above):
94          // https://github.com/apache/maven-integration-testing/blob/b4e8fd52b99a058336f9c7c5ec44fdbc1427759c/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4720DependencyManagementExclusionMergeTest.java#L67
95          if (depth == 1) {
96              return newInstance(managedVersions, managedScopes, managedOptionals, managedLocalPaths, managedExclusions);
97          }
98          return super.deriveChildManager(context);
99      }
100 
101     @Override
102     protected DependencyManager newInstance(
103             MMap<Key, String> managedVersions,
104             MMap<Key, String> managedScopes,
105             MMap<Key, Boolean> managedOptionals,
106             MMap<Key, String> managedLocalPaths,
107             MMap<Key, Holder<Collection<Exclusion>>> managedExclusions) {
108         ArrayList<AbstractDependencyManager> path = new ArrayList<>(this.path);
109         path.add(this);
110         return new ClassicDependencyManager(
111                 path,
112                 depth + 1,
113                 deriveUntil,
114                 applyFrom,
115                 managedVersions,
116                 managedScopes,
117                 managedOptionals,
118                 managedLocalPaths,
119                 managedExclusions,
120                 systemDependencyScope);
121     }
122 }