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.impl.scope;
20  
21  import java.util.Collection;
22  import java.util.Collections;
23  import java.util.Optional;
24  import java.util.Set;
25  
26  import org.eclipse.aether.RepositorySystemSession;
27  import org.eclipse.aether.collection.CollectResult;
28  import org.eclipse.aether.scope.DependencyScope;
29  import org.eclipse.aether.scope.ResolutionScope;
30  import org.eclipse.aether.scope.ScopeManager;
31  import org.eclipse.aether.scope.SystemDependencyScope;
32  
33  /**
34   * Internal scope manager.
35   *
36   * @since 2.0.0
37   */
38  public interface InternalScopeManager extends ScopeManager {
39      /**
40       * The "width" of scope: is basically sum of all distinct {@link ProjectPath} and {@link BuildPath} that are
41       * in build scopes the scope is present in. The more of them, the "wider" is the scope. Transitive scopes are
42       * weighted more as well.
43       * <p>
44       * The {@link ProjectPath#order()} makes given path "weigh" more. So a scope being present only in
45       * "main" project path is wider than scope being present only in "test" project path.
46       * <p>
47       * Interpretation: the bigger the returned integer is, the "wider" the scope is. The numbers should not serve
48       * any other purposes, merely to sort scope instances by "width" (i.e. from "widest" to "narrowest").
49       */
50      int getDependencyScopeWidth(DependencyScope dependencyScope);
51  
52      /**
53       * Returns the {@link BuildScope} that this scope deem as main.
54       */
55      Optional<BuildScope> getDependencyScopeMainProjectBuildScope(DependencyScope dependencyScope);
56  
57      /**
58       * Resolver specific: post-processing to be used to support this scope (with its dependency
59       * and resolution scopes).
60       */
61      CollectResult postProcess(
62              RepositorySystemSession session, ResolutionScope resolutionScope, CollectResult collectResult);
63  
64      /**
65       * The mode of resolution scope: eliminate (remove all occurrences) or just remove.
66       */
67      enum Mode {
68          /**
69           * Mode where artifacts in non-wanted scopes are completely eliminated. In other words, this mode ensures
70           * that if a dependency was removed due unwanted scope, it is guaranteed that no such dependency will appear
71           * anywhere else in the resulting graph either.
72           */
73          ELIMINATE,
74  
75          /**
76           * Mode where artifacts in non-wanted scopes are removed only. In other words, they will NOT prevent (as in
77           * they will not "dominate") other possibly appearing occurrences of same artifact in the graph.
78           */
79          REMOVE
80      }
81  
82      /**
83       * Creates dependency scope instance.
84       * <p>
85       * Should be invoked only via {@link ScopeManagerConfiguration#buildDependencyScopes(InternalScopeManager)}.
86       */
87      DependencyScope createDependencyScope(String id, boolean transitive, Collection<BuildScopeQuery> presence);
88  
89      /**
90       * Creates system dependency scope instance. This method may be invoked only once, as there can be only one
91       * instance of {@link SystemDependencyScope}!
92       * <p>
93       * Should be invoked only via {@link ScopeManagerConfiguration#buildDependencyScopes(InternalScopeManager)}.
94       */
95      SystemDependencyScope createSystemDependencyScope(
96              String id, boolean transitive, Collection<BuildScopeQuery> presence, String systemPathProperty);
97  
98      /**
99       * Creates resolution scope instance.
100      * <p>
101      * Should be invoked only via {@link ScopeManagerConfiguration#buildResolutionScopes(InternalScopeManager)}.
102      */
103     default ResolutionScope createResolutionScope(
104             String id,
105             Mode mode,
106             Collection<BuildScopeQuery> wantedPresence,
107             Collection<DependencyScope> explicitlyIncluded,
108             Collection<DependencyScope> transitivelyExcluded) {
109         return createResolutionScope(
110                 id, Collections.emptySet(), mode, wantedPresence, explicitlyIncluded, transitivelyExcluded);
111     }
112 
113     /**
114      * Creates resolution scope instance with aliases.
115      * <p>
116      * Should be invoked only via {@link ScopeManagerConfiguration#buildResolutionScopes(InternalScopeManager)}.
117      *
118      * @since 2.0.18
119      */
120     ResolutionScope createResolutionScope(
121             String id,
122             Set<String> aliases,
123             Mode mode,
124             Collection<BuildScopeQuery> wantedPresence,
125             Collection<DependencyScope> explicitlyIncluded,
126             Collection<DependencyScope> transitivelyExcluded);
127 }