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.Collections;
9   import java.util.HashMap;
10  import java.util.Map;
11  import org.apache.maven.api.annotations.Experimental;
12  import org.apache.maven.api.annotations.Generated;
13  import org.apache.maven.api.annotations.Immutable;
14  import org.apache.maven.api.annotations.Nonnull;
15  import org.apache.maven.api.annotations.NotThreadSafe;
16  import org.apache.maven.api.annotations.ThreadSafe;
17  
18  /**
19   * This is the file specification used to activate the profile. The {@code missing} value
20   * is the location of a file that needs to exist, and if it doesn't, the profile will be
21   * activated. On the other hand, {@code exists} will test for the existence of the file and if it is
22   * there, the profile will be activated.<br>
23   * Variable interpolation for these file specifications is limited to {@code ${basedir}},
24   * system properties and user properties.
25   */
26  @Experimental
27  @Generated @ThreadSafe @Immutable
28  public class ActivationFile
29      implements Serializable, InputLocationTracker
30  {
31      /**
32       * The name of the file that must be missing to activate the
33       * profile.
34       */
35      final String missing;
36      /**
37       * The name of the file that must exist to activate the profile.
38       */
39      final String exists;
40      /** Location of the xml element for this object. */
41      final InputLocation location;
42      /** Location of the xml element for the field missing. */
43      final InputLocation missingLocation;
44      /** Location of the xml element for the field exists. */
45      final InputLocation existsLocation;
46      /** Other locations */
47      final Map<Object, InputLocation> locations;
48  
49      /**
50        * Constructor for this class, package protected.
51        * @see Builder#build()
52        */
53      ActivationFile(
54          String missing,
55          String exists,
56          Map<Object, InputLocation> locations,
57          InputLocation location,
58          InputLocation missingLocation,
59          InputLocation existsLocation
60      )
61      {
62          this.missing = missing;
63          this.exists = exists;
64          this.locations = ImmutableCollections.copy( locations );
65          this.location = location;
66          this.missingLocation = missingLocation;
67          this.existsLocation = existsLocation;
68      }
69  
70      /**
71       * The name of the file that must be missing to activate the
72       * profile.
73       *
74       * @return a {@code String}
75       */
76      public String getMissing()
77      {
78          return this.missing;
79      }
80  
81      /**
82       * The name of the file that must exist to activate the profile.
83       *
84       * @return a {@code String}
85       */
86      public String getExists()
87      {
88          return this.exists;
89      }
90  
91      /**
92       * Gets the location of the specified field in the input source.
93       */
94      public InputLocation getLocation( Object key )
95      {
96          if ( key instanceof String )
97          {
98              switch ( ( String ) key )
99              {
100                 case "":
101                     return location;
102                 case "missing":
103                     return missingLocation;
104                 case "exists":
105                     return existsLocation;
106             }
107         }
108         return locations != null ? locations.get( key ) : null;
109     }
110 
111     /**
112      * Creates a new builder with this object as the basis.
113      *
114      * @return a {@code Builder}
115      */
116     @Nonnull
117     public Builder with()
118     {
119         return newBuilder( this );
120     }
121     /**
122      * Creates a new {@code ActivationFile} instance using the specified missing.
123      *
124      * @param missing the new {@code String} to use
125      * @return a {@code ActivationFile} with the specified missing
126      */
127     @Nonnull
128     public ActivationFile withMissing( String missing )
129     {
130         return with().missing( missing ).build();
131     }
132     /**
133      * Creates a new {@code ActivationFile} instance using the specified exists.
134      *
135      * @param exists the new {@code String} to use
136      * @return a {@code ActivationFile} with the specified exists
137      */
138     @Nonnull
139     public ActivationFile withExists( String exists )
140     {
141         return with().exists( exists ).build();
142     }
143 
144     /**
145      * Creates a new {@code ActivationFile} instance.
146      * Equivalent to {@code newInstance( true )}.
147      * @see #newInstance(boolean)
148      *
149      * @return a new {@code ActivationFile}
150      */
151     @Nonnull
152     public static ActivationFile newInstance()
153     {
154         return newInstance( true );
155     }
156 
157     /**
158      * Creates a new {@code ActivationFile} instance using default values or not.
159      * Equivalent to {@code newBuilder( withDefaults ).build()}.
160      *
161      * @param withDefaults the boolean indicating whether default values should be used
162      * @return a new {@code ActivationFile}
163      */
164     @Nonnull
165     public static ActivationFile newInstance( boolean withDefaults )
166     {
167         return newBuilder( withDefaults ).build();
168     }
169 
170     /**
171      * Creates a new {@code ActivationFile} builder instance.
172      * Equivalent to {@code newBuilder( true )}.
173      * @see #newBuilder(boolean)
174      *
175      * @return a new {@code Builder}
176      */
177     @Nonnull
178     public static Builder newBuilder()
179     {
180         return newBuilder( true );
181     }
182 
183     /**
184      * Creates a new {@code ActivationFile} builder instance using default values or not.
185      *
186      * @param withDefaults the boolean indicating whether default values should be used
187      * @return a new {@code Builder}
188      */
189     @Nonnull
190     public static Builder newBuilder( boolean withDefaults )
191     {
192         return new Builder( withDefaults );
193     }
194 
195     /**
196      * Creates a new {@code ActivationFile} builder instance using the specified object as a basis.
197      * Equivalent to {@code newBuilder( from, false )}.
198      *
199      * @param from the {@code ActivationFile} instance to use as a basis
200      * @return a new {@code Builder}
201      */
202     @Nonnull
203     public static Builder newBuilder( ActivationFile from )
204     {
205         return newBuilder( from, false );
206     }
207 
208     /**
209      * Creates a new {@code ActivationFile} builder instance using the specified object as a basis.
210      *
211      * @param from the {@code ActivationFile} instance to use as a basis
212      * @param forceCopy the boolean indicating if a copy should be forced
213      * @return a new {@code Builder}
214      */
215     @Nonnull
216     public static Builder newBuilder( ActivationFile from, boolean forceCopy )
217     {
218         return new Builder( from, forceCopy );
219     }
220 
221     /**
222      * Builder class used to create ActivationFile instances.
223      * @see #with()
224      * @see #newBuilder()
225      */
226     @NotThreadSafe
227     public static class Builder
228     {
229         ActivationFile base;
230         String missing;
231         String exists;
232         Map<Object, InputLocation> locations;
233 
234         Builder( boolean withDefaults )
235         {
236             if ( withDefaults )
237             {
238             }
239         }
240 
241         Builder( ActivationFile base, boolean forceCopy )
242         {
243             if ( forceCopy )
244             {
245                 this.missing = base.missing;
246                 this.exists = base.exists;
247             }
248             else
249             {
250                 this.base = base;
251             }
252         }
253 
254         @Nonnull
255         public Builder missing( String missing )
256         {
257             this.missing = missing;
258             return this;
259         }
260 
261         @Nonnull
262         public Builder exists( String exists )
263         {
264             this.exists = exists;
265             return this;
266         }
267 
268 
269         @Nonnull
270         public Builder location( Object key, InputLocation location )
271         {
272             if ( location != null )
273             {
274                 if ( this.locations == null )
275                 {
276                     this.locations = new HashMap<>();
277                 }
278                 this.locations.put( key, location );
279             }
280             return this;
281         }
282 
283         @Nonnull
284         public ActivationFile build()
285         {
286             if ( base != null
287                     && ( missing == null || missing == base.missing )
288                     && ( exists == null || exists == base.exists )
289             )
290             {
291                 return base;
292             }
293             Map<Object, InputLocation> locations = null;
294             InputLocation location = null;
295             InputLocation missingLocation = null;
296             InputLocation existsLocation = null;
297             if ( this.locations != null )
298             {
299                 locations = this.locations;
300                 location = locations.remove( "" );
301                 missingLocation = locations.remove( "missing" );
302                 existsLocation = locations.remove( "exists" );
303             }
304             return new ActivationFile(
305                 missing != null ? missing : ( base != null ? base.missing : null ),
306                 exists != null ? exists : ( base != null ? base.exists : null ),
307                 locations != null ? locations : ( base != null ? base.locations : null ),
308                 location != null ? location : ( base != null ? base.location : null ),
309                 missingLocation != null ? missingLocation : ( base != null ? base.missingLocation : null ),
310                 existsLocation != null ? existsLocation : ( base != null ? base.existsLocation : null )
311             );
312         }
313     }
314 
315 }