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