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