1
2
3
4
5 package org.apache.maven.api.cli.extensions;
6
7 import java.io.Serializable;
8 import java.util.Collections;
9 import java.util.HashMap;
10 import java.util.Map;
11 import java.util.Objects;
12 import java.util.Optional;
13 import java.util.Set;
14 import java.util.stream.Collectors;
15 import java.util.stream.Stream;
16 import org.apache.maven.api.annotations.Experimental;
17 import org.apache.maven.api.annotations.Generated;
18 import org.apache.maven.api.annotations.Immutable;
19 import org.apache.maven.api.annotations.Nonnull;
20 import org.apache.maven.api.annotations.NotThreadSafe;
21 import org.apache.maven.api.annotations.ThreadSafe;
22 import org.apache.maven.api.xml.XmlNode;
23
24
25
26
27 @Experimental
28 @Generated @ThreadSafe @Immutable
29 public class CoreExtension
30 implements Serializable
31 {
32
33
34
35 final String groupId;
36
37
38
39 final String artifactId;
40
41
42
43 final String version;
44
45
46
47 final String classLoadingStrategy;
48
49
50 final XmlNode configuration;
51
52
53
54
55
56 protected CoreExtension(Builder builder) {
57 this.groupId = builder.groupId != null ? builder.groupId : (builder.base != null ? builder.base.groupId : null);
58 this.artifactId = builder.artifactId != null ? builder.artifactId : (builder.base != null ? builder.base.artifactId : null);
59 this.version = builder.version != null ? builder.version : (builder.base != null ? builder.base.version : null);
60 this.classLoadingStrategy = builder.classLoadingStrategy != null ? builder.classLoadingStrategy : (builder.base != null ? builder.base.classLoadingStrategy : null);
61 this.configuration = builder.configuration != null ? builder.configuration : (builder.base != null ? builder.base.configuration : null);
62 }
63
64
65
66
67
68
69 public String getGroupId() {
70 return this.groupId;
71 }
72
73
74
75
76
77
78 public String getArtifactId() {
79 return this.artifactId;
80 }
81
82
83
84
85
86
87 public String getVersion() {
88 return this.version;
89 }
90
91
92
93
94
95
96 public String getClassLoadingStrategy() {
97 return this.classLoadingStrategy;
98 }
99
100
101
102
103
104 public XmlNode getConfiguration() {
105 return this.configuration;
106 }
107
108
109
110
111
112
113 @Nonnull
114 public Builder with() {
115 return newBuilder(this);
116 }
117
118
119
120
121
122
123 @Nonnull
124 public CoreExtension withGroupId(String groupId) {
125 return newBuilder(this, true).groupId(groupId).build();
126 }
127
128
129
130
131
132
133 @Nonnull
134 public CoreExtension withArtifactId(String artifactId) {
135 return newBuilder(this, true).artifactId(artifactId).build();
136 }
137
138
139
140
141
142
143 @Nonnull
144 public CoreExtension withVersion(String version) {
145 return newBuilder(this, true).version(version).build();
146 }
147
148
149
150
151
152
153 @Nonnull
154 public CoreExtension withClassLoadingStrategy(String classLoadingStrategy) {
155 return newBuilder(this, true).classLoadingStrategy(classLoadingStrategy).build();
156 }
157
158
159
160
161
162
163 @Nonnull
164 public CoreExtension withConfiguration(XmlNode configuration) {
165 return newBuilder(this, true).configuration(configuration).build();
166 }
167
168
169
170
171
172
173
174
175 @Nonnull
176 public static CoreExtension newInstance() {
177 return newInstance(true);
178 }
179
180
181
182
183
184
185
186
187 @Nonnull
188 public static CoreExtension newInstance(boolean withDefaults) {
189 return newBuilder(withDefaults).build();
190 }
191
192
193
194
195
196
197
198
199 @Nonnull
200 public static Builder newBuilder() {
201 return newBuilder(true);
202 }
203
204
205
206
207
208
209
210 @Nonnull
211 public static Builder newBuilder(boolean withDefaults) {
212 return new Builder(withDefaults);
213 }
214
215
216
217
218
219
220
221
222 @Nonnull
223 public static Builder newBuilder(CoreExtension from) {
224 return newBuilder(from, false);
225 }
226
227
228
229
230
231
232
233
234 @Nonnull
235 public static Builder newBuilder(CoreExtension from, boolean forceCopy) {
236 return new Builder(from, forceCopy);
237 }
238
239
240
241
242
243
244 @NotThreadSafe
245 public static class Builder
246 {
247 CoreExtension base;
248 String groupId;
249 String artifactId;
250 String version;
251 String classLoadingStrategy;
252 XmlNode configuration;
253
254 protected Builder(boolean withDefaults) {
255 if (withDefaults) {
256 this.classLoadingStrategy = "self-first";
257 }
258 }
259
260 protected Builder(CoreExtension base, boolean forceCopy) {
261 if (forceCopy) {
262 this.groupId = base.groupId;
263 this.artifactId = base.artifactId;
264 this.version = base.version;
265 this.classLoadingStrategy = base.classLoadingStrategy;
266 this.configuration = base.configuration;
267 } else {
268 this.base = base;
269 }
270 }
271
272 @Nonnull
273 public Builder groupId(String groupId) {
274 this.groupId = groupId;
275 return this;
276 }
277
278 @Nonnull
279 public Builder artifactId(String artifactId) {
280 this.artifactId = artifactId;
281 return this;
282 }
283
284 @Nonnull
285 public Builder version(String version) {
286 this.version = version;
287 return this;
288 }
289
290 @Nonnull
291 public Builder classLoadingStrategy(String classLoadingStrategy) {
292 this.classLoadingStrategy = classLoadingStrategy;
293 return this;
294 }
295
296 @Nonnull
297 public Builder configuration(XmlNode configuration) {
298 this.configuration = configuration;
299 return this;
300 }
301
302
303 @Nonnull
304 public CoreExtension build() {
305
306 if (base != null
307 && (groupId == null || groupId == base.groupId)
308 && (artifactId == null || artifactId == base.artifactId)
309 && (version == null || version == base.version)
310 && (classLoadingStrategy == null || classLoadingStrategy == base.classLoadingStrategy)
311 && (configuration == null || configuration == base.configuration)
312 ) {
313 return base;
314 }
315 return new CoreExtension(this);
316 }
317
318 }
319
320
321
322
323
324
325
326
327 public String getId() {
328 return (getGroupId() == null ? "[unknown-group-id]" : getGroupId())
329 + ":" + (getArtifactId() == null ? "[unknown-artifact-id]" : getArtifactId())
330 + ":" + (getVersion() == null ? "[unknown-version]" : getVersion());
331 }
332
333
334 }