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.eclipse.aether.impl.scope;
20  
21  import java.util.Arrays;
22  import java.util.Collections;
23  import java.util.HashSet;
24  import java.util.Objects;
25  import java.util.Set;
26  
27  /**
28   * Set of constants meant to be used in "common builds".
29   *
30   * @since 2.0.0
31   */
32  public final class CommonBuilds {
33      private CommonBuilds() {}
34  
35      private abstract static class Label {
36          private final String id;
37  
38          protected Label(String id) {
39              this.id = id;
40          }
41  
42          public String getId() {
43              return id;
44          }
45  
46          @Override
47          public boolean equals(Object o) {
48              if (this == o) {
49                  return true;
50              }
51              if (o == null || getClass() != o.getClass()) {
52                  return false;
53              }
54              Label label = (Label) o;
55              return Objects.equals(id, label.id);
56          }
57  
58          @Override
59          public int hashCode() {
60              return Objects.hash(id);
61          }
62  
63          @Override
64          public String toString() {
65              return id;
66          }
67      }
68  
69      private static final class ProjectPathImpl extends Label implements ProjectPath {
70          private final int order;
71          private final int reverseOrder;
72  
73          private ProjectPathImpl(String id, int order, int reverseOrder) {
74              super(id);
75              this.order = order;
76              this.reverseOrder = reverseOrder;
77          }
78  
79          @Override
80          public int order() {
81              return order;
82          }
83  
84          @Override
85          public int reverseOrder() {
86              return reverseOrder;
87          }
88      }
89  
90      private static final class BuildPathImpl extends Label implements BuildPath {
91          private final boolean reverse;
92          private final int order;
93  
94          private BuildPathImpl(String id, boolean reverse, int order) {
95              super(id);
96              this.reverse = reverse;
97              this.order = order;
98          }
99  
100         @Override
101         public boolean isReverse() {
102             return reverse;
103         }
104 
105         @Override
106         public int order() {
107             return order;
108         }
109     }
110 
111     private static final class BuildScopeImpl extends Label implements BuildScope {
112         private final Set<ProjectPath> projectPaths;
113         private final Set<BuildPath> buildPaths;
114         private final int order;
115 
116         private BuildScopeImpl(String id, Set<ProjectPath> projectPaths, Set<BuildPath> buildPaths, int order) {
117             super(id);
118             this.projectPaths = projectPaths;
119             this.buildPaths = buildPaths;
120             this.order = order;
121         }
122 
123         @Override
124         public Set<ProjectPath> getProjectPaths() {
125             return projectPaths;
126         }
127 
128         @Override
129         public Set<BuildPath> getBuildPaths() {
130             return buildPaths;
131         }
132 
133         @Override
134         public int order() {
135             return order;
136         }
137     }
138 
139     /**
140      * A common "main" project path.
141      */
142     public static final ProjectPath PROJECT_PATH_MAIN = new ProjectPathImpl("main", 1, 3);
143 
144     /**
145      * A common "test" project path.
146      */
147     public static final ProjectPath PROJECT_PATH_TEST = new ProjectPathImpl("test", 2, 1);
148 
149     /**
150      * A common "it" project path.
151      */
152     public static final ProjectPath PROJECT_PATH_IT = new ProjectPathImpl("it", 3, 2);
153 
154     /**
155      * A common "preprocess" build path.
156      */
157     public static final BuildPath BUILD_PATH_PREPROCESS = new BuildPathImpl("preprocess", false, 1);
158 
159     /**
160      * A common "compile" build path.
161      */
162     public static final BuildPath BUILD_PATH_COMPILE = new BuildPathImpl("compile", false, 2);
163 
164     /**
165      * A common "runtime" build path.
166      */
167     public static final BuildPath BUILD_PATH_RUNTIME = new BuildPathImpl("runtime", true, 3);
168 
169     /**
170      * Maven2/Maven3 special build scope: it did not distinguish between "test compile"
171      * and "test runtime", but lumped both together into "test".
172      */
173     public static final BuildScope MAVEN_TEST_BUILD_SCOPE = new BuildScopeImpl(
174             "test",
175             Collections.singleton(PROJECT_PATH_TEST),
176             Collections.unmodifiableSet(new HashSet<>(Arrays.asList(BUILD_PATH_COMPILE, BUILD_PATH_RUNTIME))),
177             10);
178 }