View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //  Generated by Modello Velocity from model.vm
3   //  template, any modifications will be overwritten.
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   * Modifications to the build process which is activated based on environmental
23   * parameters or command line arguments.
24   */
25  @Experimental
26  @Generated @ThreadSafe @Immutable
27  public class Profile
28      extends ModelBase
29      implements Serializable, InputLocationTracker
30  {
31      /**
32       * The identifier of this build profile. This is used for command line
33       * activation, and identifies profiles to be merged.
34       */
35      final String id;
36      /**
37       * The conditional logic which will automatically trigger the inclusion of this
38       * profile.
39       */
40      final Activation activation;
41      /**
42       * Information required to build the project.
43       */
44      final BuildBase build;
45      /** Location of the xml element for the field id. */
46      final InputLocation idLocation;
47      /** Location of the xml element for the field activation. */
48      final InputLocation activationLocation;
49      /** Location of the xml element for the field build. */
50      final InputLocation buildLocation;
51  
52      /**
53        * Constructor for this class, package protected.
54        * @see Builder#build()
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      * The identifier of this build profile. This is used for command line
113      * activation, and identifies profiles to be merged.
114      *
115      * @return a {@code String}
116      */
117     public String getId()
118     {
119         return this.id;
120     }
121 
122     /**
123      * The conditional logic which will automatically trigger the inclusion of this
124      * profile.
125      *
126      * @return a {@code Activation}
127      */
128     public Activation getActivation()
129     {
130         return this.activation;
131     }
132 
133     /**
134      * Information required to build the project.
135      *
136      * @return a {@code BuildBase}
137      */
138     public BuildBase getBuild()
139     {
140         return this.build;
141     }
142 
143     /**
144      * Gets the location of the specified field in the input source.
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      * Creates a new builder with this object as the basis.
165      *
166      * @return a {@code Builder}
167      */
168     @Nonnull
169     public Builder with()
170     {
171         return newBuilder( this );
172     }
173     /**
174      * Creates a new {@code Profile} instance using the specified modules.
175      *
176      * @param modules the new {@code Collection<String>} to use
177      * @return a {@code Profile} with the specified modules
178      */
179     @Nonnull
180     public Profile withModules( Collection<String> modules )
181     {
182         return with().modules( modules ).build();
183     }
184     /**
185      * Creates a new {@code Profile} instance using the specified distributionManagement.
186      *
187      * @param distributionManagement the new {@code DistributionManagement} to use
188      * @return a {@code Profile} with the specified distributionManagement
189      */
190     @Nonnull
191     public Profile withDistributionManagement( DistributionManagement distributionManagement )
192     {
193         return with().distributionManagement( distributionManagement ).build();
194     }
195     /**
196      * Creates a new {@code Profile} instance using the specified properties.
197      *
198      * @param properties the new {@code Map<String, String>} to use
199      * @return a {@code Profile} with the specified properties
200      */
201     @Nonnull
202     public Profile withProperties( Map<String, String> properties )
203     {
204         return with().properties( properties ).build();
205     }
206     /**
207      * Creates a new {@code Profile} instance using the specified dependencyManagement.
208      *
209      * @param dependencyManagement the new {@code DependencyManagement} to use
210      * @return a {@code Profile} with the specified dependencyManagement
211      */
212     @Nonnull
213     public Profile withDependencyManagement( DependencyManagement dependencyManagement )
214     {
215         return with().dependencyManagement( dependencyManagement ).build();
216     }
217     /**
218      * Creates a new {@code Profile} instance using the specified dependencies.
219      *
220      * @param dependencies the new {@code Collection<Dependency>} to use
221      * @return a {@code Profile} with the specified dependencies
222      */
223     @Nonnull
224     public Profile withDependencies( Collection<Dependency> dependencies )
225     {
226         return with().dependencies( dependencies ).build();
227     }
228     /**
229      * Creates a new {@code Profile} instance using the specified repositories.
230      *
231      * @param repositories the new {@code Collection<Repository>} to use
232      * @return a {@code Profile} with the specified repositories
233      */
234     @Nonnull
235     public Profile withRepositories( Collection<Repository> repositories )
236     {
237         return with().repositories( repositories ).build();
238     }
239     /**
240      * Creates a new {@code Profile} instance using the specified pluginRepositories.
241      *
242      * @param pluginRepositories the new {@code Collection<Repository>} to use
243      * @return a {@code Profile} with the specified pluginRepositories
244      */
245     @Nonnull
246     public Profile withPluginRepositories( Collection<Repository> pluginRepositories )
247     {
248         return with().pluginRepositories( pluginRepositories ).build();
249     }
250     /**
251      * Creates a new {@code Profile} instance using the specified reporting.
252      *
253      * @param reporting the new {@code Reporting} to use
254      * @return a {@code Profile} with the specified reporting
255      */
256     @Nonnull
257     public Profile withReporting( Reporting reporting )
258     {
259         return with().reporting( reporting ).build();
260     }
261     /**
262      * Creates a new {@code Profile} instance using the specified id.
263      *
264      * @param id the new {@code String} to use
265      * @return a {@code Profile} with the specified id
266      */
267     @Nonnull
268     public Profile withId( String id )
269     {
270         return with().id( id ).build();
271     }
272     /**
273      * Creates a new {@code Profile} instance using the specified activation.
274      *
275      * @param activation the new {@code Activation} to use
276      * @return a {@code Profile} with the specified activation
277      */
278     @Nonnull
279     public Profile withActivation( Activation activation )
280     {
281         return with().activation( activation ).build();
282     }
283     /**
284      * Creates a new {@code Profile} instance using the specified build.
285      *
286      * @param build the new {@code BuildBase} to use
287      * @return a {@code Profile} with the specified build
288      */
289     @Nonnull
290     public Profile withBuild( BuildBase build )
291     {
292         return with().build( build ).build();
293     }
294 
295     /**
296      * Creates a new {@code Profile} instance.
297      * Equivalent to {@code newInstance( true )}.
298      * @see #newInstance(boolean)
299      *
300      * @return a new {@code Profile}
301      */
302     @Nonnull
303     public static Profile newInstance()
304     {
305         return newInstance( true );
306     }
307 
308     /**
309      * Creates a new {@code Profile} instance using default values or not.
310      * Equivalent to {@code newBuilder( withDefaults ).build()}.
311      *
312      * @param withDefaults the boolean indicating whether default values should be used
313      * @return a new {@code Profile}
314      */
315     @Nonnull
316     public static Profile newInstance( boolean withDefaults )
317     {
318         return newBuilder( withDefaults ).build();
319     }
320 
321     /**
322      * Creates a new {@code Profile} builder instance.
323      * Equivalent to {@code newBuilder( true )}.
324      * @see #newBuilder(boolean)
325      *
326      * @return a new {@code Builder}
327      */
328     @Nonnull
329     public static Builder newBuilder()
330     {
331         return newBuilder( true );
332     }
333 
334     /**
335      * Creates a new {@code Profile} builder instance using default values or not.
336      *
337      * @param withDefaults the boolean indicating whether default values should be used
338      * @return a new {@code Builder}
339      */
340     @Nonnull
341     public static Builder newBuilder( boolean withDefaults )
342     {
343         return new Builder( withDefaults );
344     }
345 
346     /**
347      * Creates a new {@code Profile} builder instance using the specified object as a basis.
348      * Equivalent to {@code newBuilder( from, false )}.
349      *
350      * @param from the {@code Profile} instance to use as a basis
351      * @return a new {@code Builder}
352      */
353     @Nonnull
354     public static Builder newBuilder( Profile from )
355     {
356         return newBuilder( from, false );
357     }
358 
359     /**
360      * Creates a new {@code Profile} builder instance using the specified object as a basis.
361      *
362      * @param from the {@code Profile} instance to use as a basis
363      * @param forceCopy the boolean indicating if a copy should be forced
364      * @return a new {@code Builder}
365      */
366     @Nonnull
367     public static Builder newBuilder( Profile from, boolean forceCopy )
368     {
369         return new Builder( from, forceCopy );
370     }
371 
372     /**
373      * Builder class used to create Profile instances.
374      * @see #with()
375      * @see #newBuilder()
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     // We don't want this to be parseable...it's sort of 'hidden'
586     // default source for this profile is in the pom itself.
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      * @see java.lang.Object#toString()
601      */
602     public String toString()
603     {
604         return "Profile {id: " + getId() + ", source: " + getSource() + "}";
605     }
606             
607           
608 }