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.Collections;
8   import java.util.HashMap;
9   import java.util.Map;
10  import org.apache.maven.api.annotations.Experimental;
11  import org.apache.maven.api.annotations.Generated;
12  import org.apache.maven.api.annotations.Immutable;
13  import org.apache.maven.api.annotations.Nonnull;
14  import org.apache.maven.api.annotations.NotThreadSafe;
15  import org.apache.maven.api.annotations.ThreadSafe;
16  
17  /**
18   * Download policy.
19   */
20  @Experimental
21  @Generated @ThreadSafe @Immutable
22  public class RepositoryPolicy
23      implements Serializable, InputLocationTracker
24  {
25      /**
26       * Whether to use this repository for downloading this type of artifact. Note: While the type
27       * of this field is {@code String} for technical reasons, the semantic type is actually
28       * {@code Boolean}. Default value is {@code true}.
29       */
30      final String enabled;
31      /**
32       * The frequency for downloading updates - can be
33       * {@code always,}
34       * {@code daily}
35       * (default),
36       * {@code interval:XXX}
37       * (in minutes) or
38       * {@code never}
39       * (only if it doesn't exist locally).
40       */
41      final String updatePolicy;
42      /**
43       * What to do when verification of an artifact checksum fails. Valid values are
44       * {@code ignore},
45       * {@code fail}
46       * (default for Maven 4 and above) or
47       * {@code warn}
48       * (default for Maven 2 and 3)
49       */
50      final String checksumPolicy;
51      /** Location of the xml element for this object. */
52      final InputLocation location;
53      /** Location of the xml element for the field enabled. */
54      final InputLocation enabledLocation;
55      /** Location of the xml element for the field updatePolicy. */
56      final InputLocation updatePolicyLocation;
57      /** Location of the xml element for the field checksumPolicy. */
58      final InputLocation checksumPolicyLocation;
59      /** Other locations */
60      final Map<Object, InputLocation> locations;
61  
62      /**
63        * Constructor for this class, package protected.
64        * @see Builder#build()
65        */
66      RepositoryPolicy(
67          String enabled,
68          String updatePolicy,
69          String checksumPolicy,
70          Map<Object, InputLocation> locations,
71          InputLocation location,
72          InputLocation enabledLocation,
73          InputLocation updatePolicyLocation,
74          InputLocation checksumPolicyLocation
75      )
76      {
77          this.enabled = enabled;
78          this.updatePolicy = updatePolicy;
79          this.checksumPolicy = checksumPolicy;
80          this.locations = ImmutableCollections.copy( locations );
81          this.location = location;
82          this.enabledLocation = enabledLocation;
83          this.updatePolicyLocation = updatePolicyLocation;
84          this.checksumPolicyLocation = checksumPolicyLocation;
85      }
86  
87      /**
88       * Whether to use this repository for downloading this type of artifact. Note: While the type
89       * of this field is {@code String} for technical reasons, the semantic type is actually
90       * {@code Boolean}. Default value is {@code true}.
91       *
92       * @return a {@code String}
93       */
94      public String getEnabled()
95      {
96          return this.enabled;
97      }
98  
99      /**
100      * The frequency for downloading updates - can be
101      * {@code always,}
102      * {@code daily}
103      * (default),
104      * {@code interval:XXX}
105      * (in minutes) or
106      * {@code never}
107      * (only if it doesn't exist locally).
108      *
109      * @return a {@code String}
110      */
111     public String getUpdatePolicy()
112     {
113         return this.updatePolicy;
114     }
115 
116     /**
117      * What to do when verification of an artifact checksum fails. Valid values are
118      * {@code ignore},
119      * {@code fail}
120      * (default for Maven 4 and above) or
121      * {@code warn}
122      * (default for Maven 2 and 3)
123      *
124      * @return a {@code String}
125      */
126     public String getChecksumPolicy()
127     {
128         return this.checksumPolicy;
129     }
130 
131     /**
132      * Gets the location of the specified field in the input source.
133      */
134     public InputLocation getLocation( Object key )
135     {
136         if ( key instanceof String )
137         {
138             switch ( ( String ) key )
139             {
140                 case "":
141                     return location;
142                 case "enabled":
143                     return enabledLocation;
144                 case "updatePolicy":
145                     return updatePolicyLocation;
146                 case "checksumPolicy":
147                     return checksumPolicyLocation;
148             }
149         }
150         return locations != null ? locations.get( key ) : null;
151     }
152 
153     /**
154      * Creates a new builder with this object as the basis.
155      *
156      * @return a {@code Builder}
157      */
158     @Nonnull
159     public Builder with()
160     {
161         return newBuilder( this );
162     }
163     /**
164      * Creates a new {@code RepositoryPolicy} instance using the specified enabled.
165      *
166      * @param enabled the new {@code String} to use
167      * @return a {@code RepositoryPolicy} with the specified enabled
168      */
169     @Nonnull
170     public RepositoryPolicy withEnabled( String enabled )
171     {
172         return with().enabled( enabled ).build();
173     }
174     /**
175      * Creates a new {@code RepositoryPolicy} instance using the specified updatePolicy.
176      *
177      * @param updatePolicy the new {@code String} to use
178      * @return a {@code RepositoryPolicy} with the specified updatePolicy
179      */
180     @Nonnull
181     public RepositoryPolicy withUpdatePolicy( String updatePolicy )
182     {
183         return with().updatePolicy( updatePolicy ).build();
184     }
185     /**
186      * Creates a new {@code RepositoryPolicy} instance using the specified checksumPolicy.
187      *
188      * @param checksumPolicy the new {@code String} to use
189      * @return a {@code RepositoryPolicy} with the specified checksumPolicy
190      */
191     @Nonnull
192     public RepositoryPolicy withChecksumPolicy( String checksumPolicy )
193     {
194         return with().checksumPolicy( checksumPolicy ).build();
195     }
196 
197     /**
198      * Creates a new {@code RepositoryPolicy} instance.
199      * Equivalent to {@code newInstance( true )}.
200      * @see #newInstance(boolean)
201      *
202      * @return a new {@code RepositoryPolicy}
203      */
204     @Nonnull
205     public static RepositoryPolicy newInstance()
206     {
207         return newInstance( true );
208     }
209 
210     /**
211      * Creates a new {@code RepositoryPolicy} instance using default values or not.
212      * Equivalent to {@code newBuilder( withDefaults ).build()}.
213      *
214      * @param withDefaults the boolean indicating whether default values should be used
215      * @return a new {@code RepositoryPolicy}
216      */
217     @Nonnull
218     public static RepositoryPolicy newInstance( boolean withDefaults )
219     {
220         return newBuilder( withDefaults ).build();
221     }
222 
223     /**
224      * Creates a new {@code RepositoryPolicy} builder instance.
225      * Equivalent to {@code newBuilder( true )}.
226      * @see #newBuilder(boolean)
227      *
228      * @return a new {@code Builder}
229      */
230     @Nonnull
231     public static Builder newBuilder()
232     {
233         return newBuilder( true );
234     }
235 
236     /**
237      * Creates a new {@code RepositoryPolicy} builder instance using default values or not.
238      *
239      * @param withDefaults the boolean indicating whether default values should be used
240      * @return a new {@code Builder}
241      */
242     @Nonnull
243     public static Builder newBuilder( boolean withDefaults )
244     {
245         return new Builder( withDefaults );
246     }
247 
248     /**
249      * Creates a new {@code RepositoryPolicy} builder instance using the specified object as a basis.
250      * Equivalent to {@code newBuilder( from, false )}.
251      *
252      * @param from the {@code RepositoryPolicy} instance to use as a basis
253      * @return a new {@code Builder}
254      */
255     @Nonnull
256     public static Builder newBuilder( RepositoryPolicy from )
257     {
258         return newBuilder( from, false );
259     }
260 
261     /**
262      * Creates a new {@code RepositoryPolicy} builder instance using the specified object as a basis.
263      *
264      * @param from the {@code RepositoryPolicy} instance to use as a basis
265      * @param forceCopy the boolean indicating if a copy should be forced
266      * @return a new {@code Builder}
267      */
268     @Nonnull
269     public static Builder newBuilder( RepositoryPolicy from, boolean forceCopy )
270     {
271         return new Builder( from, forceCopy );
272     }
273 
274     /**
275      * Builder class used to create RepositoryPolicy instances.
276      * @see #with()
277      * @see #newBuilder()
278      */
279     @NotThreadSafe
280     public static class Builder
281     {
282         RepositoryPolicy base;
283         String enabled;
284         String updatePolicy;
285         String checksumPolicy;
286         Map<Object, InputLocation> locations;
287 
288         Builder( boolean withDefaults )
289         {
290             if ( withDefaults )
291             {
292             }
293         }
294 
295         Builder( RepositoryPolicy base, boolean forceCopy )
296         {
297             if ( forceCopy )
298             {
299                 this.enabled = base.enabled;
300                 this.updatePolicy = base.updatePolicy;
301                 this.checksumPolicy = base.checksumPolicy;
302             }
303             else
304             {
305                 this.base = base;
306             }
307         }
308 
309         @Nonnull
310         public Builder enabled( String enabled )
311         {
312             this.enabled = enabled;
313             return this;
314         }
315 
316         @Nonnull
317         public Builder updatePolicy( String updatePolicy )
318         {
319             this.updatePolicy = updatePolicy;
320             return this;
321         }
322 
323         @Nonnull
324         public Builder checksumPolicy( String checksumPolicy )
325         {
326             this.checksumPolicy = checksumPolicy;
327             return this;
328         }
329 
330 
331         @Nonnull
332         public Builder location( Object key, InputLocation location )
333         {
334             if ( location != null )
335             {
336                 if ( this.locations == null )
337                 {
338                     this.locations = new HashMap<>();
339                 }
340                 this.locations.put( key, location );
341             }
342             return this;
343         }
344 
345         @Nonnull
346         public RepositoryPolicy build()
347         {
348             if ( base != null
349                     && ( enabled == null || enabled == base.enabled )
350                     && ( updatePolicy == null || updatePolicy == base.updatePolicy )
351                     && ( checksumPolicy == null || checksumPolicy == base.checksumPolicy )
352             )
353             {
354                 return base;
355             }
356             Map<Object, InputLocation> locations = null;
357             InputLocation location = null;
358             InputLocation enabledLocation = null;
359             InputLocation updatePolicyLocation = null;
360             InputLocation checksumPolicyLocation = null;
361             if ( this.locations != null )
362             {
363                 locations = this.locations;
364                 location = locations.remove( "" );
365                 enabledLocation = locations.remove( "enabled" );
366                 updatePolicyLocation = locations.remove( "updatePolicy" );
367                 checksumPolicyLocation = locations.remove( "checksumPolicy" );
368             }
369             return new RepositoryPolicy(
370                 enabled != null ? enabled : ( base != null ? base.enabled : null ),
371                 updatePolicy != null ? updatePolicy : ( base != null ? base.updatePolicy : null ),
372                 checksumPolicy != null ? checksumPolicy : ( base != null ? base.checksumPolicy : null ),
373                 locations != null ? locations : ( base != null ? base.locations : null ),
374                 location != null ? location : ( base != null ? base.location : null ),
375                 enabledLocation != null ? enabledLocation : ( base != null ? base.enabledLocation : null ),
376                 updatePolicyLocation != null ? updatePolicyLocation : ( base != null ? base.updatePolicyLocation : null ),
377                 checksumPolicyLocation != null ? checksumPolicyLocation : ( base != null ? base.checksumPolicyLocation : null )
378             );
379         }
380     }
381 
382 
383             
384     public boolean isEnabled()
385     {
386         return ( getEnabled() != null ) ? Boolean.parseBoolean( getEnabled() ) : true;
387     }
388 
389             
390           
391 }