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
40   */
41  @Experimental
42  public enum ResolutionScope {
43      /**
44       * empty resolution scope
45       */
46      NONE(null),
47      /**
48       * <code>compile</code> resolution scope
49       * = <code>compile</code> + <code>system</code> + <code>provided</code> dependencies
50       */
51      COMPILE("compile", Scope.COMPILE, Scope.SYSTEM, Scope.PROVIDED),
52      /**
53       * <code>compile+runtime</code> resolution scope (Maven 3 only)
54       * = <code>compile</code> + <code>system</code> + <code>provided</code> + <code>runtime</code> dependencies
55       */
56      COMPILE_PLUS_RUNTIME("compile+runtime", Scope.COMPILE, Scope.SYSTEM, Scope.PROVIDED, Scope.RUNTIME),
57      /**
58       * <code>runtime</code> resolution scope
59       * = <code>compile</code> + <code>runtime</code> dependencies
60       */
61      RUNTIME("runtime", Scope.COMPILE, Scope.RUNTIME),
62      /**
63       * <code>runtime+system</code> resolution scope (Maven 3 only)
64       * = <code>compile</code> + <code>system</code> + <code>runtime</code> dependencies
65       */
66      RUNTIME_PLUS_SYSTEM("runtime+system", Scope.COMPILE, Scope.SYSTEM, Scope.RUNTIME),
67      /**
68       * <code>test</code> resolution scope
69       * = <code>compile</code> + <code>system</code> + <code>provided</code> + <code>runtime</code> + <code>test</code>
70       * dependencies
71       */
72      TEST("test", Scope.COMPILE, Scope.SYSTEM, Scope.PROVIDED, Scope.RUNTIME, Scope.TEST);
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  }