001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.eclipse.aether.util.graph.manager;
020
021import org.eclipse.aether.collection.DependencyCollectionContext;
022import org.eclipse.aether.collection.DependencyManagement;
023import org.eclipse.aether.collection.DependencyManager;
024import org.eclipse.aether.graph.Dependency;
025
026import static java.util.Objects.requireNonNull;
027
028/**
029 * A dependency manager that performs no dependency management operations.
030 *
031 * <h2>Overview</h2>
032 * <p>
033 * This is a null-object implementation of {@link DependencyManager} that effectively
034 * disables all dependency management. It always returns null for management operations
035 * and returns itself for child manager derivation, making it a true no-op implementation.
036 * </p>
037 *
038 * <h2>When to Use</h2>
039 * <ul>
040 * <li><strong>Testing:</strong> When you want to disable dependency management for tests</li>
041 * <li><strong>Simple Resolution:</strong> When you want pure dependency resolution without management</li>
042 * <li><strong>Performance:</strong> When dependency management overhead is not needed</li>
043 * <li><strong>Legacy Systems:</strong> When working with systems that handle management externally</li>
044 * </ul>
045 *
046 * <h2>Thread Safety</h2>
047 * <p>
048 * This implementation is completely thread-safe and stateless. The {@link #INSTANCE} can be
049 * safely shared across multiple threads and throughout the entire application lifecycle.
050 * </p>
051 *
052 * <h2>Comparison with Other Managers</h2>
053 * <ul>
054 * <li>{@link ClassicDependencyManager}: Maven 2.x compatibility with limited management</li>
055 * <li>{@link TransitiveDependencyManager}: Modern transitive management</li>
056 * <li>{@link DefaultDependencyManager}: Aggressive management at all levels</li>
057 * <li><strong>This manager:</strong> No management at all (fastest, simplest)</li>
058 * </ul>
059 *
060 * @see ClassicDependencyManager
061 * @see TransitiveDependencyManager
062 * @see DefaultDependencyManager
063 */
064public final class NoopDependencyManager implements DependencyManager {
065
066    /**
067     * A ready-made singleton instance of this dependency manager.
068     * <p>
069     * This instance can be safely reused throughout an entire application regardless of
070     * multi-threading, as this implementation is completely stateless and thread-safe.
071     * Using this instance is preferred over creating new instances for performance reasons.
072     * </p>
073     */
074    public static final DependencyManager INSTANCE = new NoopDependencyManager();
075
076    /**
077     * Creates a new instance of this dependency manager.
078     * <p>
079     * <strong>Note:</strong> Usually, {@link #INSTANCE} should be used instead of creating
080     * new instances, as this implementation is stateless and the singleton provides better
081     * performance characteristics.
082     * </p>
083     */
084    public NoopDependencyManager() {}
085
086    /**
087     * Returns this same instance as the child manager (no-op behavior).
088     *
089     * @param context the dependency collection context (validated but not used)
090     * @return this same instance
091     * @throws NullPointerException if context is null
092     */
093    public DependencyManager deriveChildManager(DependencyCollectionContext context) {
094        requireNonNull(context, "context cannot be null");
095        return this;
096    }
097
098    /**
099     * 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}