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