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