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