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} (default),
36       * {@code interval:XXX} (in minutes) or
37       * {@code never} (only if it doesn't exist locally).
38       */
39      final String updatePolicy;
40      /**
41       * What to do when verification of an artifact checksum fails. Valid values are
42       * {@code ignore},
43       * {@code fail} (default for Maven 4 and above) or
44       * {@code warn} (default for Maven 2 and 3).
45       */
46      final String checksumPolicy;
47      /** Locations */
48      final Map<Object, InputLocation> locations;
49  
50      /**
51        * Constructor for this class, package protected.
52        * @see Builder#build()
53        */
54      RepositoryPolicy(
55          String enabled,
56          String updatePolicy,
57          String checksumPolicy,
58          Map<Object, InputLocation> locations
59      ) {
60          this.enabled = enabled;
61          this.updatePolicy = updatePolicy;
62          this.checksumPolicy = checksumPolicy;
63          this.locations = ImmutableCollections.copy(locations);
64      }
65  
66      /**
67       * Whether to use this repository for downloading this type of artifact. Note: While the type
68       * of this field is {@code String} for technical reasons, the semantic type is actually
69       * {@code Boolean}. Default value is {@code true}.
70       *
71       * @return a {@code String}
72       */
73      public String getEnabled() {
74          return this.enabled;
75      }
76  
77      /**
78       * The frequency for downloading updates - can be
79       * {@code always},
80       * {@code daily} (default),
81       * {@code interval:XXX} (in minutes) or
82       * {@code never} (only if it doesn't exist locally).
83       *
84       * @return a {@code String}
85       */
86      public String getUpdatePolicy() {
87          return this.updatePolicy;
88      }
89  
90      /**
91       * What to do when verification of an artifact checksum fails. Valid values are
92       * {@code ignore},
93       * {@code fail} (default for Maven 4 and above) or
94       * {@code warn} (default for Maven 2 and 3).
95       *
96       * @return a {@code String}
97       */
98      public String getChecksumPolicy() {
99          return this.checksumPolicy;
100     }
101 
102     /**
103      * Gets the location of the specified field in the input source.
104      */
105     public InputLocation getLocation(Object key) {
106         return locations != null ? locations.get(key) : null;
107     }
108 
109     /**
110      * Creates a new builder with this object as the basis.
111      *
112      * @return a {@code Builder}
113      */
114     @Nonnull
115     public Builder with() {
116         return newBuilder(this);
117     }
118     /**
119      * Creates a new {@code RepositoryPolicy} instance using the specified enabled.
120      *
121      * @param enabled the new {@code String} to use
122      * @return a {@code RepositoryPolicy} with the specified enabled
123      */
124     @Nonnull
125     public RepositoryPolicy withEnabled(String enabled) {
126         return newBuilder(this, true).enabled(enabled).build();
127     }
128     /**
129      * Creates a new {@code RepositoryPolicy} instance using the specified updatePolicy.
130      *
131      * @param updatePolicy the new {@code String} to use
132      * @return a {@code RepositoryPolicy} with the specified updatePolicy
133      */
134     @Nonnull
135     public RepositoryPolicy withUpdatePolicy(String updatePolicy) {
136         return newBuilder(this, true).updatePolicy(updatePolicy).build();
137     }
138     /**
139      * Creates a new {@code RepositoryPolicy} instance using the specified checksumPolicy.
140      *
141      * @param checksumPolicy the new {@code String} to use
142      * @return a {@code RepositoryPolicy} with the specified checksumPolicy
143      */
144     @Nonnull
145     public RepositoryPolicy withChecksumPolicy(String checksumPolicy) {
146         return newBuilder(this, true).checksumPolicy(checksumPolicy).build();
147     }
148 
149     /**
150      * Creates a new {@code RepositoryPolicy} instance.
151      * Equivalent to {@code newInstance(true)}.
152      * @see #newInstance(boolean)
153      *
154      * @return a new {@code RepositoryPolicy}
155      */
156     @Nonnull
157     public static RepositoryPolicy newInstance() {
158         return newInstance(true);
159     }
160 
161     /**
162      * Creates a new {@code RepositoryPolicy} instance using default values or not.
163      * Equivalent to {@code newBuilder(withDefaults).build()}.
164      *
165      * @param withDefaults the boolean indicating whether default values should be used
166      * @return a new {@code RepositoryPolicy}
167      */
168     @Nonnull
169     public static RepositoryPolicy newInstance(boolean withDefaults) {
170         return newBuilder(withDefaults).build();
171     }
172 
173     /**
174      * Creates a new {@code RepositoryPolicy} builder instance.
175      * Equivalent to {@code newBuilder(true)}.
176      * @see #newBuilder(boolean)
177      *
178      * @return a new {@code Builder}
179      */
180     @Nonnull
181     public static Builder newBuilder() {
182         return newBuilder(true);
183     }
184 
185     /**
186      * Creates a new {@code RepositoryPolicy} builder instance using default values or not.
187      *
188      * @param withDefaults the boolean indicating whether default values should be used
189      * @return a new {@code Builder}
190      */
191     @Nonnull
192     public static Builder newBuilder(boolean withDefaults) {
193         return new Builder(withDefaults);
194     }
195 
196     /**
197      * Creates a new {@code RepositoryPolicy} builder instance using the specified object as a basis.
198      * Equivalent to {@code newBuilder(from, false)}.
199      *
200      * @param from the {@code RepositoryPolicy} instance to use as a basis
201      * @return a new {@code Builder}
202      */
203     @Nonnull
204     public static Builder newBuilder(RepositoryPolicy from) {
205         return newBuilder(from, false);
206     }
207 
208     /**
209      * Creates a new {@code RepositoryPolicy} builder instance using the specified object as a basis.
210      *
211      * @param from the {@code RepositoryPolicy} 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(RepositoryPolicy from, boolean forceCopy) {
217         return new Builder(from, forceCopy);
218     }
219 
220     /**
221      * Builder class used to create RepositoryPolicy instances.
222      * @see #with()
223      * @see #newBuilder()
224      */
225     @NotThreadSafe
226     public static class Builder
227     {
228         RepositoryPolicy base;
229         String enabled;
230         String updatePolicy;
231         String checksumPolicy;
232         Map<Object, InputLocation> locations;
233 
234         Builder(boolean withDefaults) {
235             if (withDefaults) {
236             }
237         }
238 
239         Builder(RepositoryPolicy base, boolean forceCopy) {
240             if (forceCopy) {
241                 this.enabled = base.enabled;
242                 this.updatePolicy = base.updatePolicy;
243                 this.checksumPolicy = base.checksumPolicy;
244                 this.locations = base.locations;
245             } else {
246                 this.base = base;
247             }
248         }
249 
250         @Nonnull
251         public Builder enabled(String enabled) {
252             this.enabled = enabled;
253             return this;
254         }
255 
256         @Nonnull
257         public Builder updatePolicy(String updatePolicy) {
258             this.updatePolicy = updatePolicy;
259             return this;
260         }
261 
262         @Nonnull
263         public Builder checksumPolicy(String checksumPolicy) {
264             this.checksumPolicy = checksumPolicy;
265             return this;
266         }
267 
268 
269         @Nonnull
270         public Builder location(Object key, InputLocation location) {
271             if (location != null) {
272                 if (!(this.locations instanceof HashMap)) {
273                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
274                 }
275                 this.locations.put(key, location);
276             }
277             return this;
278         }
279 
280         @Nonnull
281         public RepositoryPolicy build() {
282             if (base != null
283                     && (enabled == null || enabled == base.enabled)
284                     && (updatePolicy == null || updatePolicy == base.updatePolicy)
285                     && (checksumPolicy == null || checksumPolicy == base.checksumPolicy)
286             ) {
287                 return base;
288             }
289             Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
290             Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
291             Map<Object, InputLocation> locations = new HashMap<>();
292             locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
293             locations.put("enabled", newlocs.containsKey("enabled") ? newlocs.get("enabled") : oldlocs.get("enabled"));
294             locations.put("updatePolicy", newlocs.containsKey("updatePolicy") ? newlocs.get("updatePolicy") : oldlocs.get("updatePolicy"));
295             locations.put("checksumPolicy", newlocs.containsKey("checksumPolicy") ? newlocs.get("checksumPolicy") : oldlocs.get("checksumPolicy"));
296             return new RepositoryPolicy(
297                 enabled != null ? enabled : (base != null ? base.enabled : null),
298                 updatePolicy != null ? updatePolicy : (base != null ? base.updatePolicy : null),
299                 checksumPolicy != null ? checksumPolicy : (base != null ? base.checksumPolicy : null),
300                 locations
301             );
302         }
303     }
304 
305 
306             
307     public boolean isEnabled() {
308         return (getEnabled() != null) ? Boolean.parseBoolean(getEnabled()) : true;
309     }
310 
311             
312           
313 }