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