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 final InputLocation idLocation;
47
48 final InputLocation activationLocation;
49
50 final InputLocation buildLocation;
51
52
53
54
55
56 Profile(
57 Collection<String> modules,
58 DistributionManagement distributionManagement,
59 Map<String, String> properties,
60 DependencyManagement dependencyManagement,
61 Collection<Dependency> dependencies,
62 Collection<Repository> repositories,
63 Collection<Repository> pluginRepositories,
64 Reporting reporting,
65 String id,
66 Activation activation,
67 BuildBase build,
68 Map<Object, InputLocation> locations,
69 InputLocation location,
70 InputLocation modulesLocation,
71 InputLocation distributionManagementLocation,
72 InputLocation propertiesLocation,
73 InputLocation dependencyManagementLocation,
74 InputLocation dependenciesLocation,
75 InputLocation repositoriesLocation,
76 InputLocation pluginRepositoriesLocation,
77 InputLocation reportingLocation,
78 InputLocation idLocation,
79 InputLocation activationLocation,
80 InputLocation buildLocation
81 )
82 {
83 super(
84 modules,
85 distributionManagement,
86 properties,
87 dependencyManagement,
88 dependencies,
89 repositories,
90 pluginRepositories,
91 reporting,
92 locations,
93 location,
94 modulesLocation,
95 distributionManagementLocation,
96 propertiesLocation,
97 dependencyManagementLocation,
98 dependenciesLocation,
99 repositoriesLocation,
100 pluginRepositoriesLocation,
101 reportingLocation
102 );
103 this.id = id;
104 this.activation = activation;
105 this.build = build;
106 this.idLocation = idLocation;
107 this.activationLocation = activationLocation;
108 this.buildLocation = buildLocation;
109 }
110
111
112
113
114
115
116
117 public String getId()
118 {
119 return this.id;
120 }
121
122
123
124
125
126
127
128 public Activation getActivation()
129 {
130 return this.activation;
131 }
132
133
134
135
136
137
138 public BuildBase getBuild()
139 {
140 return this.build;
141 }
142
143
144
145
146 public InputLocation getLocation( Object key )
147 {
148 if ( key instanceof String )
149 {
150 switch ( ( String ) key )
151 {
152 case "id":
153 return idLocation;
154 case "activation":
155 return activationLocation;
156 case "build":
157 return buildLocation;
158 }
159 }
160 return super.getLocation( key );
161 }
162
163
164
165
166
167
168 @Nonnull
169 public Builder with()
170 {
171 return newBuilder( this );
172 }
173
174
175
176
177
178
179 @Nonnull
180 public Profile withModules( Collection<String> modules )
181 {
182 return with().modules( modules ).build();
183 }
184
185
186
187
188
189
190 @Nonnull
191 public Profile withDistributionManagement( DistributionManagement distributionManagement )
192 {
193 return with().distributionManagement( distributionManagement ).build();
194 }
195
196
197
198
199
200
201 @Nonnull
202 public Profile withProperties( Map<String, String> properties )
203 {
204 return with().properties( properties ).build();
205 }
206
207
208
209
210
211
212 @Nonnull
213 public Profile withDependencyManagement( DependencyManagement dependencyManagement )
214 {
215 return with().dependencyManagement( dependencyManagement ).build();
216 }
217
218
219
220
221
222
223 @Nonnull
224 public Profile withDependencies( Collection<Dependency> dependencies )
225 {
226 return with().dependencies( dependencies ).build();
227 }
228
229
230
231
232
233
234 @Nonnull
235 public Profile withRepositories( Collection<Repository> repositories )
236 {
237 return with().repositories( repositories ).build();
238 }
239
240
241
242
243
244
245 @Nonnull
246 public Profile withPluginRepositories( Collection<Repository> pluginRepositories )
247 {
248 return with().pluginRepositories( pluginRepositories ).build();
249 }
250
251
252
253
254
255
256 @Nonnull
257 public Profile withReporting( Reporting reporting )
258 {
259 return with().reporting( reporting ).build();
260 }
261
262
263
264
265
266
267 @Nonnull
268 public Profile withId( String id )
269 {
270 return with().id( id ).build();
271 }
272
273
274
275
276
277
278 @Nonnull
279 public Profile withActivation( Activation activation )
280 {
281 return with().activation( activation ).build();
282 }
283
284
285
286
287
288
289 @Nonnull
290 public Profile withBuild( BuildBase build )
291 {
292 return with().build( build ).build();
293 }
294
295
296
297
298
299
300
301
302 @Nonnull
303 public static Profile newInstance()
304 {
305 return newInstance( true );
306 }
307
308
309
310
311
312
313
314
315 @Nonnull
316 public static Profile newInstance( boolean withDefaults )
317 {
318 return newBuilder( withDefaults ).build();
319 }
320
321
322
323
324
325
326
327
328 @Nonnull
329 public static Builder newBuilder()
330 {
331 return newBuilder( true );
332 }
333
334
335
336
337
338
339
340 @Nonnull
341 public static Builder newBuilder( boolean withDefaults )
342 {
343 return new Builder( withDefaults );
344 }
345
346
347
348
349
350
351
352
353 @Nonnull
354 public static Builder newBuilder( Profile from )
355 {
356 return newBuilder( from, false );
357 }
358
359
360
361
362
363
364
365
366 @Nonnull
367 public static Builder newBuilder( Profile from, boolean forceCopy )
368 {
369 return new Builder( from, forceCopy );
370 }
371
372
373
374
375
376
377 @NotThreadSafe
378 public static class Builder
379 extends ModelBase.Builder
380 {
381 Profile base;
382 String id;
383 Activation activation;
384 BuildBase build;
385
386 Builder( boolean withDefaults )
387 {
388 super( withDefaults );
389 if ( withDefaults )
390 {
391 this.id = "default";
392 }
393 }
394
395 Builder( Profile base, boolean forceCopy )
396 {
397 super( base, forceCopy );
398 if ( forceCopy )
399 {
400 this.id = base.id;
401 this.activation = base.activation;
402 this.build = base.build;
403 }
404 else
405 {
406 this.base = base;
407 }
408 }
409
410 @Nonnull
411 public Builder modules( Collection<String> modules )
412 {
413 this.modules = modules;
414 return this;
415 }
416
417 @Nonnull
418 public Builder distributionManagement( DistributionManagement distributionManagement )
419 {
420 this.distributionManagement = distributionManagement;
421 return this;
422 }
423
424 @Nonnull
425 public Builder properties( Map<String, String> properties )
426 {
427 this.properties = properties;
428 return this;
429 }
430
431 @Nonnull
432 public Builder dependencyManagement( DependencyManagement dependencyManagement )
433 {
434 this.dependencyManagement = dependencyManagement;
435 return this;
436 }
437
438 @Nonnull
439 public Builder dependencies( Collection<Dependency> dependencies )
440 {
441 this.dependencies = dependencies;
442 return this;
443 }
444
445 @Nonnull
446 public Builder repositories( Collection<Repository> repositories )
447 {
448 this.repositories = repositories;
449 return this;
450 }
451
452 @Nonnull
453 public Builder pluginRepositories( Collection<Repository> pluginRepositories )
454 {
455 this.pluginRepositories = pluginRepositories;
456 return this;
457 }
458
459 @Nonnull
460 public Builder reporting( Reporting reporting )
461 {
462 this.reporting = reporting;
463 return this;
464 }
465
466 @Nonnull
467 public Builder id( String id )
468 {
469 this.id = id;
470 return this;
471 }
472
473 @Nonnull
474 public Builder activation( Activation activation )
475 {
476 this.activation = activation;
477 return this;
478 }
479
480 @Nonnull
481 public Builder build( BuildBase build )
482 {
483 this.build = build;
484 return this;
485 }
486
487
488 @Nonnull
489 public Builder location( Object key, InputLocation location )
490 {
491 if ( location != null )
492 {
493 if ( this.locations == null )
494 {
495 this.locations = new HashMap<>();
496 }
497 this.locations.put( key, location );
498 }
499 return this;
500 }
501
502 @Nonnull
503 public Profile build()
504 {
505 if ( base != null
506 && ( modules == null || modules == base.modules )
507 && ( distributionManagement == null || distributionManagement == base.distributionManagement )
508 && ( properties == null || properties == base.properties )
509 && ( dependencyManagement == null || dependencyManagement == base.dependencyManagement )
510 && ( dependencies == null || dependencies == base.dependencies )
511 && ( repositories == null || repositories == base.repositories )
512 && ( pluginRepositories == null || pluginRepositories == base.pluginRepositories )
513 && ( reporting == null || reporting == base.reporting )
514 && ( id == null || id == base.id )
515 && ( activation == null || activation == base.activation )
516 && ( build == null || build == base.build )
517 )
518 {
519 return base;
520 }
521 Map<Object, InputLocation> locations = null;
522 InputLocation location = null;
523 InputLocation modulesLocation = null;
524 InputLocation distributionManagementLocation = null;
525 InputLocation propertiesLocation = null;
526 InputLocation dependencyManagementLocation = null;
527 InputLocation dependenciesLocation = null;
528 InputLocation repositoriesLocation = null;
529 InputLocation pluginRepositoriesLocation = null;
530 InputLocation reportingLocation = null;
531 InputLocation idLocation = null;
532 InputLocation activationLocation = null;
533 InputLocation buildLocation = null;
534 if ( this.locations != null )
535 {
536 locations = this.locations;
537 location = locations.remove( "" );
538 modulesLocation = locations.remove( "modules" );
539 distributionManagementLocation = locations.remove( "distributionManagement" );
540 propertiesLocation = locations.remove( "properties" );
541 dependencyManagementLocation = locations.remove( "dependencyManagement" );
542 dependenciesLocation = locations.remove( "dependencies" );
543 repositoriesLocation = locations.remove( "repositories" );
544 pluginRepositoriesLocation = locations.remove( "pluginRepositories" );
545 reportingLocation = locations.remove( "reporting" );
546 idLocation = locations.remove( "id" );
547 activationLocation = locations.remove( "activation" );
548 buildLocation = locations.remove( "build" );
549 }
550 return new Profile(
551 modules != null ? modules : ( base != null ? base.modules : null ),
552 distributionManagement != null ? distributionManagement : ( base != null ? base.distributionManagement : null ),
553 properties != null ? properties : ( base != null ? base.properties : null ),
554 dependencyManagement != null ? dependencyManagement : ( base != null ? base.dependencyManagement : null ),
555 dependencies != null ? dependencies : ( base != null ? base.dependencies : null ),
556 repositories != null ? repositories : ( base != null ? base.repositories : null ),
557 pluginRepositories != null ? pluginRepositories : ( base != null ? base.pluginRepositories : null ),
558 reporting != null ? reporting : ( base != null ? base.reporting : null ),
559 id != null ? id : ( base != null ? base.id : null ),
560 activation != null ? activation : ( base != null ? base.activation : null ),
561 build != null ? build : ( base != null ? base.build : null ),
562 locations != null ? locations : ( base != null ? base.locations : null ),
563 location != null ? location : ( base != null ? base.location : null ),
564 modulesLocation != null ? modulesLocation : ( base != null ? base.modulesLocation : null ),
565 distributionManagementLocation != null ? distributionManagementLocation : ( base != null ? base.distributionManagementLocation : null ),
566 propertiesLocation != null ? propertiesLocation : ( base != null ? base.propertiesLocation : null ),
567 dependencyManagementLocation != null ? dependencyManagementLocation : ( base != null ? base.dependencyManagementLocation : null ),
568 dependenciesLocation != null ? dependenciesLocation : ( base != null ? base.dependenciesLocation : null ),
569 repositoriesLocation != null ? repositoriesLocation : ( base != null ? base.repositoriesLocation : null ),
570 pluginRepositoriesLocation != null ? pluginRepositoriesLocation : ( base != null ? base.pluginRepositoriesLocation : null ),
571 reportingLocation != null ? reportingLocation : ( base != null ? base.reportingLocation : null ),
572 idLocation != null ? idLocation : ( base != null ? base.idLocation : null ),
573 activationLocation != null ? activationLocation : ( base != null ? base.activationLocation : null ),
574 buildLocation != null ? buildLocation : ( base != null ? base.buildLocation : null )
575 );
576 }
577 }
578
579
580
581 public static final String SOURCE_POM = "pom";
582
583 public static final String SOURCE_SETTINGS = "settings.xml";
584
585
586
587 private String source = SOURCE_POM;
588
589 public void setSource( String source )
590 {
591 this.source = source;
592 }
593
594 public String getSource()
595 {
596 return source;
597 }
598
599
600
601
602 public String toString()
603 {
604 return "Profile {id: " + getId() + ", source: " + getSource() + "}";
605 }
606
607
608 }