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