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