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.collection;
020
021import org.eclipse.aether.RepositorySystemSession;
022
023/**
024 * Dependency collector checker. It is able to check dependency collection result, deem it "satisfiable" or
025 * augment collection and re-execute it.
026 *
027 * @since 2.0.19
028 */
029public interface DependencyCollectionChecker {
030    /**
031     * A default "no op" implementation.
032     */
033    DependencyCollectionChecker NOOP = new DependencyCollectionChecker() {};
034
035    /**
036     * Config property for collector checker suppression. Presence of this key will suppress collection checking.
037     * This key is not meant for users, but to programmatically signal collection suppression.
038     */
039    String COLLECTOR_CHECKER_SUPPRESSED = "aether.dependencyCollector.checker.suppressed";
040
041    /**
042     * Prepares for dependency collection.
043     */
044    default RepositorySystemSession prepare(RepositorySystemSession session, CollectRequest request) {
045        return session;
046    }
047
048    /**
049     * Performs checks on finished dependency collection. It should return {@code true} if the collection was deemed
050     * "satisfactory". If should return {@code false} <em>only, if collection was not satisfactory, and checker
051     * was able to modify resolution parameters (to not repeat same work)</em>. In other cases (not satisfactory
052     * but no param change would help) it should throw {@link DependencyCollectionException}.
053     */
054    default boolean isSatisfactory(RepositorySystemSession session, CollectRequest request, CollectResult result)
055            throws DependencyCollectionException {
056        return true;
057    }
058}