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