1 package org.apache.maven.api; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import java.util.Arrays; 23 import java.util.Collections; 24 import java.util.HashSet; 25 import java.util.Map; 26 import java.util.Optional; 27 import java.util.Set; 28 import java.util.stream.Collectors; 29 import java.util.stream.Stream; 30 31 import org.apache.maven.api.annotations.Experimental; 32 33 /** 34 * Dependencies resolution scopes available before 35 * <a href="/ref/current/maven-core/apidocs/org/apache/maven/lifecycle/internal/MojoExecutor.html">mojo execution</a>. 36 * 37 * Important note: The {@code id} values of this enum correspond to constants of 38 * {@code org.apache.maven.artifact.Artifact} class and MUST BE KEPT IN SYNC. 39 * 40 * @since 4.0 41 */ 42 @Experimental 43 public enum ResolutionScope 44 { 45 /** 46 * empty resolution scope 47 */ 48 NONE( null ), 49 /** 50 * <code>compile</code> resolution scope 51 * = <code>compile</code> + <code>system</code> + <code>provided</code> dependencies 52 */ 53 COMPILE( "compile", Scope.COMPILE, Scope.SYSTEM, Scope.PROVIDED ), 54 /** 55 * <code>compile+runtime</code> resolution scope (Maven 3 only) 56 * = <code>compile</code> + <code>system</code> + <code>provided</code> + <code>runtime</code> dependencies 57 */ 58 COMPILE_PLUS_RUNTIME( "compile+runtime", Scope.COMPILE, Scope.SYSTEM, Scope.PROVIDED, Scope.RUNTIME ), 59 /** 60 * <code>runtime</code> resolution scope 61 * = <code>compile</code> + <code>runtime</code> dependencies 62 */ 63 RUNTIME( "runtime", Scope.COMPILE, Scope.RUNTIME ), 64 /** 65 * <code>runtime+system</code> resolution scope (Maven 3 only) 66 * = <code>compile</code> + <code>system</code> + <code>runtime</code> dependencies 67 */ 68 RUNTIME_PLUS_SYSTEM( "runtime+system", Scope.COMPILE, Scope.SYSTEM, Scope.RUNTIME ), 69 /** 70 * <code>test</code> resolution scope 71 * = <code>compile</code> + <code>system</code> + <code>provided</code> + <code>runtime</code> + <code>test</code> 72 * dependencies 73 */ 74 TEST( "test", Scope.COMPILE, Scope.SYSTEM, Scope.PROVIDED, Scope.RUNTIME, Scope.TEST ); 75 76 private static final Map<String, ResolutionScope> VALUES 77 = Stream.of( ResolutionScope.values() ).collect( Collectors.toMap( ResolutionScope::id, s -> s ) ); 78 79 public static ResolutionScope fromString( String id ) 80 { 81 return Optional.ofNullable( VALUES.get( id ) ) 82 .orElseThrow( () -> new IllegalArgumentException( "Unknown resolution scope " + id ) ); 83 } 84 85 private final String id; 86 private final Set<Scope> scopes; 87 88 ResolutionScope( String id, Scope... scopes ) 89 { 90 this.id = id; 91 this.scopes = Collections.unmodifiableSet( new HashSet<>( Arrays.asList( scopes ) ) ); 92 } 93 94 public String id() 95 { 96 return this.id; 97 } 98 99 public Set<Scope> scopes() 100 { 101 return scopes; 102 } 103 104 }