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.impl.scope;
020
021import java.util.Collection;
022import java.util.Optional;
023
024import org.eclipse.aether.collection.CollectResult;
025import org.eclipse.aether.collection.DependencyGraphTransformer;
026import org.eclipse.aether.collection.DependencySelector;
027import org.eclipse.aether.graph.DependencyFilter;
028import org.eclipse.aether.scope.DependencyScope;
029import org.eclipse.aether.scope.ResolutionScope;
030import org.eclipse.aether.scope.ScopeManager;
031import org.eclipse.aether.scope.SystemDependencyScope;
032
033/**
034 * Internal scope manager.
035 *
036 * @since 2.0.0
037 */
038public interface InternalScopeManager extends ScopeManager {
039    /**
040     * The "width" of scope: is basically sum of all distinct {@link ProjectPath} and {@link BuildPath} that are
041     * in build scopes the scope is present in. The more of them, the "wider" is the scope. Transitive scopes are
042     * weighted more as well.
043     * <p>
044     * The {@link ProjectPath#order()} makes given path "weigh" more. So a scope being present only in
045     * "main" project path is wider than scope being present only in "test" project path.
046     * <p>
047     * Interpretation: the bigger the returned integer is, the "wider" the scope is. The numbers should not serve
048     * any other purposes, merely to sort scope instances by "width" (i.e. from "widest" to "narrowest").
049     */
050    int getDependencyScopeWidth(DependencyScope dependencyScope);
051
052    /**
053     * Returns the {@link BuildScope} that this scope deem as main.
054     */
055    Optional<BuildScope> getDependencyScopeMainProjectBuildScope(DependencyScope dependencyScope);
056
057    /**
058     * Resolver specific: dependency selector to be used to support this scope (with its dependency
059     * and resolution scopes).
060     */
061    DependencySelector getDependencySelector(ResolutionScope resolutionScope);
062
063    /**
064     * Resolver specific: dependency graph transformer to be used to support this scope (with its dependency
065     * and resolution scopes).
066     */
067    DependencyGraphTransformer getDependencyGraphTransformer(ResolutionScope resolutionScope);
068
069    /**
070     * Resolver specific: post-processing to be used to support this scope (with its dependency
071     * and resolution scopes).
072     */
073    CollectResult postProcess(ResolutionScope resolutionScope, CollectResult collectResult);
074
075    /**
076     * Resolver specific: dependency filter to be used to support this scope (with its dependency
077     * and resolution scopes).
078     */
079    DependencyFilter getDependencyFilter(ResolutionScope resolutionScope);
080
081    /**
082     * The mode of resolution scope: eliminate (remove all occurrences) or just remove.
083     */
084    enum Mode {
085        /**
086         * Mode where artifacts in non-wanted scopes are completely eliminated. In other words, this mode ensures
087         * that if a dependency was removed due unwanted scope, it is guaranteed that no such dependency will appear
088         * anywhere else in the resulting graph either.
089         */
090        ELIMINATE,
091
092        /**
093         * Mode where artifacts in non-wanted scopes are removed only. In other words, they will NOT prevent (as in
094         * they will not "dominate") other possibly appearing occurrences of same artifact in the graph.
095         */
096        REMOVE
097    }
098
099    /**
100     * Creates dependency scope instance.
101     * <p>
102     * Should be invoked only via {@link ScopeManagerConfiguration#buildDependencyScopes(InternalScopeManager)}.
103     */
104    DependencyScope createDependencyScope(String id, boolean transitive, Collection<BuildScopeQuery> presence);
105
106    /**
107     * Creates system dependency scope instance. This method may be invoked only once, as there can be only one
108     * instance of {@link SystemDependencyScope}!
109     * <p>
110     * Should be invoked only via {@link ScopeManagerConfiguration#buildDependencyScopes(InternalScopeManager)}.
111     */
112    SystemDependencyScope createSystemDependencyScope(
113            String id, boolean transitive, Collection<BuildScopeQuery> presence, String systemPathProperty);
114
115    /**
116     * Creates resolution scope instance.
117     * <p>
118     * Should be invoked only via {@link ScopeManagerConfiguration#buildResolutionScopes(InternalScopeManager)}.
119     */
120    ResolutionScope createResolutionScope(
121            String id,
122            Mode mode,
123            Collection<BuildScopeQuery> wantedPresence,
124            Collection<DependencyScope> explicitlyIncluded,
125            Collection<DependencyScope> transitivelyExcluded);
126}