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.apache.maven.api;
20  
21  import java.util.Arrays;
22  import java.util.Collections;
23  import java.util.HashSet;
24  import java.util.Map;
25  import java.util.Optional;
26  import java.util.Set;
27  import java.util.stream.Collectors;
28  import java.util.stream.Stream;
29  
30  import org.apache.maven.api.annotations.Experimental;
31  
32  /**
33   * Dependencies resolution scopes available before
34   * <a href="/ref/current/maven-core/apidocs/org/apache/maven/lifecycle/internal/MojoExecutor.html">mojo execution</a>.
35   *
36   * Important note: The {@code id} values of this enum correspond to constants of
37   * {@code org.apache.maven.artifact.Artifact} class and MUST BE KEPT IN SYNC.
38   *
39   * @since 4.0.0
40   */
41  @Experimental
42  public enum ResolutionScope {
43      /**
44       * <code>compile</code> resolution scope
45       * = <code>compile-only</code> + <code>compile</code> + <code>provided</code> dependencies
46       */
47      PROJECT_COMPILE("project-compile", Scope.EMPTY, Scope.COMPILE_ONLY, Scope.COMPILE, Scope.PROVIDED),
48      /**
49       * <code>runtime</code> resolution scope
50       * = <code>compile</code> + <code>runtime</code> dependencies
51       */
52      PROJECT_RUNTIME("project-runtime", Scope.EMPTY, Scope.COMPILE, Scope.RUNTIME),
53      /**
54       * <code>test-compile</code> resolution scope
55       * = <code>compile-only</code> + <code>compile</code> + <code>provided</code> + <code>test-compile-only</code> + <code>test</code>
56       * dependencies
57       */
58      TEST_COMPILE(
59              "test-compile",
60              Scope.EMPTY,
61              Scope.COMPILE_ONLY,
62              Scope.COMPILE,
63              Scope.PROVIDED,
64              Scope.TEST_COMPILE_ONLY,
65              Scope.TEST),
66      /**
67       * <code>test</code> resolution scope
68       * = <code>compile</code> + <code>runtime</code> + <code>provided</code> + <code>test</code> + <code>test-runtime</code>
69       * dependencies
70       */
71      TEST_RUNTIME(
72              "test-runtime", Scope.EMPTY, Scope.COMPILE, Scope.RUNTIME, Scope.PROVIDED, Scope.TEST, Scope.TEST_RUNTIME);
73  
74      private static final Map<String, ResolutionScope> VALUES =
75              Stream.of(ResolutionScope.values()).collect(Collectors.toMap(ResolutionScope::id, s -> s));
76  
77      public static ResolutionScope fromString(String id) {
78          return Optional.ofNullable(VALUES.get(id))
79                  .orElseThrow(() -> new IllegalArgumentException("Unknown resolution scope " + id));
80      }
81  
82      private final String id;
83      private final Set<Scope> scopes;
84  
85      ResolutionScope(String id, Scope... scopes) {
86          this.id = id;
87          this.scopes = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(scopes)));
88      }
89  
90      public String id() {
91          return this.id;
92      }
93  
94      public Set<Scope> scopes() {
95          return scopes;
96      }
97  }