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.DependencyManager;
24  import org.eclipse.aether.graph.Exclusion;
25  import org.eclipse.aether.scope.ScopeManager;
26  import org.eclipse.aether.scope.SystemDependencyScope;
27  
28  /**
29   * A dependency manager that applies management at all levels with aggressive transitive behavior.
30   *
31   * <h2>Overview</h2>
32   * <p>
33   * This manager provides the most aggressive dependency management approach, applying management
34   * rules at every level of the dependency graph. Unlike other managers, it starts applying
35   * management from the very first level (depth=0) and continues indefinitely.
36   * </p>
37   *
38   * <h2>Key Characteristics</h2>
39   * <ul>
40   * <li><strong>Aggressive Application:</strong> {@code deriveUntil=Integer.MAX_VALUE}, {@code applyFrom=0}</li>
41   * <li><strong>First Level Management:</strong> Applies management even at the root level</li>
42   * <li><strong>ModelBuilder Interference:</strong> Ignores and overrides ModelBuilder's work</li>
43   * <li><strong>Complete Transitivity:</strong> Manages dependencies at all depths</li>
44   * </ul>
45   *
46   * <h2>When NOT to Use</h2>
47   * <p>
48   * <strong>⚠️ Warning:</strong> This manager is <em>not recommended for Maven or Maven-like use cases</em>
49   * because it interferes with ModelBuilder, potentially rewriting models that ModelBuilder has
50   * already processed correctly. This can lead to unexpected dependency resolution behavior.
51   * </p>
52   *
53   * <h2>When to Use</h2>
54   * <p>
55   * Consider this manager only for non-Maven scenarios where you need complete control over
56   * dependency management at all levels and are not using Maven's ModelBuilder.
57   * </p>
58   *
59   * <h2>Comparison with Other Managers</h2>
60   * <ul>
61   * <li>{@link ClassicDependencyManager}: Maven 2.x compatibility, limited scope</li>
62   * <li>{@link TransitiveDependencyManager}: Proper transitive management, ModelBuilder-friendly</li>
63   * <li><strong>This manager:</strong> Aggressive, all-level management (use with caution)</li>
64   * </ul>
65   *
66   * @author Christian Schulte
67   * @since 1.4.0
68   * @see ClassicDependencyManager
69   * @see TransitiveDependencyManager
70   */
71  public final class DefaultDependencyManager extends AbstractDependencyManager {
72      /**
73       * Creates a new dependency manager without any management information.
74       */
75      public DefaultDependencyManager() {
76          this(null);
77      }
78  
79      /**
80       * Creates a new dependency manager with aggressive management behavior.
81       * <p>
82       * <strong>⚠️ Warning:</strong> This manager is not recommended for Maven use cases.
83       * It initializes with the most aggressive settings:
84       * <ul>
85       * <li>deriveUntil = Integer.MAX_VALUE (always collect management rules)</li>
86       * <li>applyFrom = 0 (apply management from the very first level)</li>
87       * <li>No respect for ModelBuilder's work</li>
88       * </ul>
89       *
90       * @param scopeManager application-specific scope manager for handling system dependencies,
91       *                     may be null to use legacy system dependency scope handling
92       */
93      public DefaultDependencyManager(ScopeManager scopeManager) {
94          super(Integer.MAX_VALUE, 0, scopeManager);
95      }
96  
97      @SuppressWarnings("checkstyle:ParameterNumber")
98      private DefaultDependencyManager(
99              AbstractDependencyManager parent,
100             int depth,
101             int deriveUntil,
102             int applyFrom,
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             SystemDependencyScope systemDependencyScope) {
109         super(
110                 parent,
111                 depth,
112                 deriveUntil,
113                 applyFrom,
114                 managedVersions,
115                 managedScopes,
116                 managedOptionals,
117                 managedLocalPaths,
118                 managedExclusions,
119                 systemDependencyScope);
120     }
121 
122     @Override
123     protected DependencyManager newInstance(
124             MMap<Key, String> managedVersions,
125             MMap<Key, String> managedScopes,
126             MMap<Key, Boolean> managedOptionals,
127             MMap<Key, String> managedLocalPaths,
128             MMap<Key, Holder<Collection<Exclusion>>> managedExclusions) {
129         return new DefaultDependencyManager(
130                 this,
131                 depth + 1,
132                 deriveUntil,
133                 applyFrom,
134                 managedVersions,
135                 managedScopes,
136                 managedOptionals,
137                 managedLocalPaths,
138                 managedExclusions,
139                 systemDependencyScope);
140     }
141 }