1
2
3
4
5 package org.apache.maven.api.model;
6
7 import java.io.Serializable;
8 import java.util.ArrayList;
9 import java.util.Collection;
10 import java.util.Collections;
11 import java.util.HashMap;
12 import java.util.List;
13 import java.util.Map;
14 import java.util.Objects;
15 import java.util.Optional;
16 import java.util.Set;
17 import java.util.stream.Collectors;
18 import java.util.stream.Stream;
19 import org.apache.maven.api.annotations.Experimental;
20 import org.apache.maven.api.annotations.Generated;
21 import org.apache.maven.api.annotations.Immutable;
22 import org.apache.maven.api.annotations.Nonnull;
23 import org.apache.maven.api.annotations.NotThreadSafe;
24 import org.apache.maven.api.annotations.ThreadSafe;
25
26
27
28
29
30 @Experimental
31 @Generated @ThreadSafe @Immutable
32 public class Profile
33 extends ModelBase
34 implements Serializable, InputLocationTracker
35 {
36
37
38
39
40 final String id;
41
42
43
44
45 final Activation activation;
46
47
48
49 final BuildBase build;
50
51
52
53
54
55 protected Profile(Builder builder) {
56 super(builder);
57 this.id = builder.id != null ? builder.id : (builder.base != null ? builder.base.id : null);
58 this.activation = builder.activation != null ? builder.activation : (builder.base != null ? builder.base.activation : null);
59 this.build = builder.build != null ? builder.build : (builder.base != null ? builder.base.build : null);
60 }
61
62
63
64
65
66
67
68 public String getId() {
69 return this.id;
70 }
71
72
73
74
75
76
77
78 public Activation getActivation() {
79 return this.activation;
80 }
81
82
83
84
85
86
87 public BuildBase getBuild() {
88 return this.build;
89 }
90
91
92
93
94
95
96 @Nonnull
97 public Builder with() {
98 return newBuilder(this);
99 }
100
101
102
103
104
105
106 @Deprecated
107 @Nonnull
108 public Profile withModules(Collection<String> modules) {
109 return newBuilder(this, true).modules(modules).build();
110 }
111
112
113
114
115
116
117 @Nonnull
118 public Profile withSubprojects(Collection<String> subprojects) {
119 return newBuilder(this, true).subprojects(subprojects).build();
120 }
121
122
123
124
125
126
127 @Nonnull
128 public Profile withDistributionManagement(DistributionManagement distributionManagement) {
129 return newBuilder(this, true).distributionManagement(distributionManagement).build();
130 }
131
132
133
134
135
136
137 @Nonnull
138 public Profile withProperties(Map<String, String> properties) {
139 return newBuilder(this, true).properties(properties).build();
140 }
141
142
143
144
145
146
147 @Nonnull
148 public Profile withDependencyManagement(DependencyManagement dependencyManagement) {
149 return newBuilder(this, true).dependencyManagement(dependencyManagement).build();
150 }
151
152
153
154
155
156
157 @Nonnull
158 public Profile withDependencies(Collection<Dependency> dependencies) {
159 return newBuilder(this, true).dependencies(dependencies).build();
160 }
161
162
163
164
165
166
167 @Nonnull
168 public Profile withRepositories(Collection<Repository> repositories) {
169 return newBuilder(this, true).repositories(repositories).build();
170 }
171
172
173
174
175
176
177 @Nonnull
178 public Profile withPluginRepositories(Collection<Repository> pluginRepositories) {
179 return newBuilder(this, true).pluginRepositories(pluginRepositories).build();
180 }
181
182
183
184
185
186
187 @Nonnull
188 public Profile withReporting(Reporting reporting) {
189 return newBuilder(this, true).reporting(reporting).build();
190 }
191
192
193
194
195
196
197 @Nonnull
198 public Profile withId(String id) {
199 return newBuilder(this, true).id(id).build();
200 }
201
202
203
204
205
206
207 @Nonnull
208 public Profile withActivation(Activation activation) {
209 return newBuilder(this, true).activation(activation).build();
210 }
211
212
213
214
215
216
217 @Nonnull
218 public Profile withBuild(BuildBase build) {
219 return newBuilder(this, true).build(build).build();
220 }
221
222
223
224
225
226
227
228
229 @Nonnull
230 public static Profile newInstance() {
231 return newInstance(true);
232 }
233
234
235
236
237
238
239
240
241 @Nonnull
242 public static Profile newInstance(boolean withDefaults) {
243 return newBuilder(withDefaults).build();
244 }
245
246
247
248
249
250
251
252
253 @Nonnull
254 public static Builder newBuilder() {
255 return newBuilder(true);
256 }
257
258
259
260
261
262
263
264 @Nonnull
265 public static Builder newBuilder(boolean withDefaults) {
266 return new Builder(withDefaults);
267 }
268
269
270
271
272
273
274
275
276 @Nonnull
277 public static Builder newBuilder(Profile from) {
278 return newBuilder(from, false);
279 }
280
281
282
283
284
285
286
287
288 @Nonnull
289 public static Builder newBuilder(Profile from, boolean forceCopy) {
290 return new Builder(from, forceCopy);
291 }
292
293
294
295
296
297
298 @NotThreadSafe
299 public static class Builder
300 extends ModelBase.Builder
301 {
302 Profile base;
303 String id;
304 Activation activation;
305 BuildBase build;
306
307 protected Builder(boolean withDefaults) {
308 super(withDefaults);
309 if (withDefaults) {
310 this.id = "default";
311 }
312 }
313
314 protected Builder(Profile base, boolean forceCopy) {
315 super(base, forceCopy);
316 if (forceCopy) {
317 this.id = base.id;
318 this.activation = base.activation;
319 this.build = base.build;
320 this.locations = base.locations;
321 this.importedFrom = base.importedFrom;
322 } else {
323 this.base = base;
324 }
325 }
326
327 @Deprecated
328 @Nonnull
329 public Builder modules(Collection<String> modules) {
330 this.modules = modules;
331 return this;
332 }
333
334 @Nonnull
335 public Builder subprojects(Collection<String> subprojects) {
336 this.subprojects = subprojects;
337 return this;
338 }
339
340 @Nonnull
341 public Builder distributionManagement(DistributionManagement distributionManagement) {
342 this.distributionManagement = distributionManagement;
343 return this;
344 }
345
346 @Nonnull
347 public Builder properties(Map<String, String> properties) {
348 this.properties = properties;
349 return this;
350 }
351
352 @Nonnull
353 public Builder dependencyManagement(DependencyManagement dependencyManagement) {
354 this.dependencyManagement = dependencyManagement;
355 return this;
356 }
357
358 @Nonnull
359 public Builder dependencies(Collection<Dependency> dependencies) {
360 this.dependencies = dependencies;
361 return this;
362 }
363
364 @Nonnull
365 public Builder repositories(Collection<Repository> repositories) {
366 this.repositories = repositories;
367 return this;
368 }
369
370 @Nonnull
371 public Builder pluginRepositories(Collection<Repository> pluginRepositories) {
372 this.pluginRepositories = pluginRepositories;
373 return this;
374 }
375
376 @Nonnull
377 public Builder reporting(Reporting reporting) {
378 this.reporting = reporting;
379 return this;
380 }
381
382 @Nonnull
383 public Builder id(String id) {
384 this.id = id;
385 return this;
386 }
387
388 @Nonnull
389 public Builder activation(Activation activation) {
390 this.activation = activation;
391 return this;
392 }
393
394 @Nonnull
395 public Builder build(BuildBase build) {
396 this.build = build;
397 return this;
398 }
399
400
401 @Nonnull
402 public Builder location(Object key, InputLocation location) {
403 if (location != null) {
404 if (!(this.locations instanceof HashMap)) {
405 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
406 }
407 this.locations.put(key, location);
408 }
409 return this;
410 }
411
412 @Nonnull
413 public Builder importedFrom(InputLocation importedFrom) {
414 this.importedFrom = importedFrom;
415 return this;
416 }
417
418 @Nonnull
419 public Profile build() {
420
421 if (base != null
422 && (modules == null || modules == base.modules)
423 && (subprojects == null || subprojects == base.subprojects)
424 && (distributionManagement == null || distributionManagement == base.distributionManagement)
425 && (properties == null || properties == base.properties)
426 && (dependencyManagement == null || dependencyManagement == base.dependencyManagement)
427 && (dependencies == null || dependencies == base.dependencies)
428 && (repositories == null || repositories == base.repositories)
429 && (pluginRepositories == null || pluginRepositories == base.pluginRepositories)
430 && (reporting == null || reporting == base.reporting)
431 && (id == null || id == base.id)
432 && (activation == null || activation == base.activation)
433 && (build == null || build == base.build)
434 ) {
435 return base;
436 }
437 return new Profile(this);
438 }
439
440 }
441
442
443
444 public static final String SOURCE_POM = "pom";
445
446 public static final String SOURCE_SETTINGS = "settings.xml";
447
448
449
450 private String source = SOURCE_POM;
451
452 public void setSource(String source) {
453 this.source = source;
454 }
455
456 public String getSource() {
457 return source;
458 }
459
460
461
462
463 public String toString() {
464 return "Profile {id: " + getId() + ", source: " + getSource() + "}";
465 }
466
467
468 }