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.Collections; 22 import java.util.Map; 23 import java.util.stream.Collectors; 24 import java.util.stream.Stream; 25 26 import org.apache.maven.api.annotations.Experimental; 27 import org.apache.maven.api.annotations.Immutable; 28 import org.apache.maven.api.annotations.Nonnull; 29 30 /** 31 * Indicates when the dependency will be used. 32 * For example, it may be at compile time only, at runtime, or at test time. 33 * For a given dependency, the scope is directly derived from the 34 * {@link org.apache.maven.api.model.Dependency#getScope()} and will be used when using {@link PathScope} 35 * and the {@link org.apache.maven.api.services.DependencyResolver}. 36 * 37 * @since 4.0.0 38 * @see org.apache.maven.api.model.Dependency#getScope() 39 * @see org.apache.maven.api.services.DependencyResolver 40 */ 41 @Experimental 42 @Immutable 43 public enum DependencyScope { 44 45 /** 46 * None. Allows you to declare dependencies (for example to alter reactor build order) but in reality dependencies 47 * in this scope are not part of any path scope. 48 */ 49 NONE("none", false), 50 51 /** 52 * Undefined. When no scope is explicitly given, UNDEFINED will be used, but its meaning will depend on 53 * whether the DependencyCoordinates is used in dependency management, in which case it means the scope is not 54 * explicitly managed by this managed dependency, or as a real dependency, in which case, the scope 55 * will default to {@link #COMPILE}. 56 */ 57 UNDEFINED("", false), 58 59 /** 60 * Compile only. 61 */ 62 COMPILE_ONLY("compile-only", false), 63 64 /** 65 * Compile, runtime and test. 66 */ 67 COMPILE("compile", true), 68 69 /** 70 * Runtime and test. 71 */ 72 RUNTIME("runtime", true), 73 74 /** 75 * Provided. 76 */ 77 PROVIDED("provided", false), 78 79 /** 80 * Test compile only. 81 */ 82 TEST_ONLY("test-only", false), 83 84 /** 85 * Test compile and test runtime. 86 */ 87 TEST("test", false), 88 89 /** 90 * Test runtime. 91 */ 92 TEST_RUNTIME("test-runtime", false), 93 94 /** 95 * System scope. 96 */ 97 SYSTEM("system", false); 98 99 private static final Map<String, DependencyScope> IDS = Collections.unmodifiableMap( 100 Stream.of(DependencyScope.values()).collect(Collectors.toMap(s -> s.id, s -> s))); 101 102 public static DependencyScope forId(String id) { 103 return IDS.get(id); 104 } 105 106 private final String id; 107 private final boolean transitive; 108 109 DependencyScope(String id, boolean transitive) { 110 this.id = id; 111 this.transitive = transitive; 112 } 113 114 /** 115 * The {@code id} uniquely represents a value for this extensible enum. 116 * This id should be used to compute the equality and hash code for the instance. 117 * 118 * @return the id 119 */ 120 @Nonnull 121 public String id() { 122 return id; 123 } 124 125 public boolean isTransitive() { 126 return transitive; 127 } 128 129 public boolean is(String id) { 130 return id().equals(id); 131 } 132 }