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 org.eclipse.aether.collection.DependencyCollectionContext;
22 import org.eclipse.aether.collection.DependencyManagement;
23 import org.eclipse.aether.collection.DependencyManager;
24 import org.eclipse.aether.graph.Dependency;
25
26 import static java.util.Objects.requireNonNull;
27
28 /**
29 * A dependency manager that performs no dependency management operations.
30 *
31 * <h2>Overview</h2>
32 * <p>
33 * This is a null-object implementation of {@link DependencyManager} that effectively
34 * disables all dependency management. It always returns null for management operations
35 * and returns itself for child manager derivation, making it a true no-op implementation.
36 * </p>
37 *
38 * <h2>When to Use</h2>
39 * <ul>
40 * <li><strong>Testing:</strong> When you want to disable dependency management for tests</li>
41 * <li><strong>Simple Resolution:</strong> When you want pure dependency resolution without management</li>
42 * <li><strong>Performance:</strong> When dependency management overhead is not needed</li>
43 * <li><strong>Legacy Systems:</strong> When working with systems that handle management externally</li>
44 * </ul>
45 *
46 * <h2>Thread Safety</h2>
47 * <p>
48 * This implementation is completely thread-safe and stateless. The {@link #INSTANCE} can be
49 * safely shared across multiple threads and throughout the entire application lifecycle.
50 * </p>
51 *
52 * <h2>Comparison with Other Managers</h2>
53 * <ul>
54 * <li>{@link ClassicDependencyManager}: Maven 2.x compatibility with limited management</li>
55 * <li>{@link TransitiveDependencyManager}: Modern transitive management</li>
56 * <li>{@link DefaultDependencyManager}: Aggressive management at all levels</li>
57 * <li><strong>This manager:</strong> No management at all (fastest, simplest)</li>
58 * </ul>
59 *
60 * @see ClassicDependencyManager
61 * @see TransitiveDependencyManager
62 * @see DefaultDependencyManager
63 */
64 public final class NoopDependencyManager implements DependencyManager {
65
66 /**
67 * A ready-made singleton instance of this dependency manager.
68 * <p>
69 * This instance can be safely reused throughout an entire application regardless of
70 * multi-threading, as this implementation is completely stateless and thread-safe.
71 * Using this instance is preferred over creating new instances for performance reasons.
72 * </p>
73 */
74 public static final DependencyManager INSTANCE = new NoopDependencyManager();
75
76 /**
77 * Creates a new instance of this dependency manager.
78 * <p>
79 * <strong>Note:</strong> Usually, {@link #INSTANCE} should be used instead of creating
80 * new instances, as this implementation is stateless and the singleton provides better
81 * performance characteristics.
82 * </p>
83 */
84 public NoopDependencyManager() {}
85
86 /**
87 * Returns this same instance as the child manager (no-op behavior).
88 *
89 * @param context the dependency collection context (validated but not used)
90 * @return this same instance
91 * @throws NullPointerException if context is null
92 */
93 public DependencyManager deriveChildManager(DependencyCollectionContext context) {
94 requireNonNull(context, "context cannot be null");
95 return this;
96 }
97
98 /**
99 * Returns null, indicating no dependency management should be applied.
100 *
101 * @param dependency the dependency to manage (validated but not used)
102 * @return null (no management)
103 * @throws NullPointerException if dependency is null
104 */
105 public DependencyManagement manageDependency(Dependency dependency) {
106 requireNonNull(dependency, "dependency cannot be null");
107 return null;
108 }
109
110 @Override
111 public boolean equals(Object obj) {
112 if (this == obj) {
113 return true;
114 } else if (null == obj || !getClass().equals(obj.getClass())) {
115 return false;
116 }
117 return true;
118 }
119
120 @Override
121 public int hashCode() {
122 return getClass().hashCode();
123 }
124 }