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