1
2
3
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
20
21 @Experimental
22 @Generated @ThreadSafe @Immutable
23 public class RepositoryPolicy
24 implements Serializable, InputLocationTracker
25 {
26
27
28
29
30
31 final String enabled;
32
33
34
35
36
37
38
39
40
41
42 final String updatePolicy;
43
44
45
46
47
48
49
50
51 final String checksumPolicy;
52
53 final InputLocation location;
54
55 final InputLocation enabledLocation;
56
57 final InputLocation updatePolicyLocation;
58
59 final InputLocation checksumPolicyLocation;
60
61 final Map<Object, InputLocation> locations;
62
63
64
65
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
90
91
92
93
94
95 public String getEnabled()
96 {
97 return this.enabled;
98 }
99
100
101
102
103
104
105
106
107
108
109
110
111
112 public String getUpdatePolicy()
113 {
114 return this.updatePolicy;
115 }
116
117
118
119
120
121
122
123
124
125
126
127 public String getChecksumPolicy()
128 {
129 return this.checksumPolicy;
130 }
131
132
133
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
156
157
158
159 @Nonnull
160 public Builder with()
161 {
162 return newBuilder( this );
163 }
164
165
166
167
168
169
170 @Nonnull
171 public RepositoryPolicy withEnabled( String enabled )
172 {
173 return with().enabled( enabled ).build();
174 }
175
176
177
178
179
180
181 @Nonnull
182 public RepositoryPolicy withUpdatePolicy( String updatePolicy )
183 {
184 return with().updatePolicy( updatePolicy ).build();
185 }
186
187
188
189
190
191
192 @Nonnull
193 public RepositoryPolicy withChecksumPolicy( String checksumPolicy )
194 {
195 return with().checksumPolicy( checksumPolicy ).build();
196 }
197
198
199
200
201
202
203
204
205 @Nonnull
206 public static RepositoryPolicy newInstance()
207 {
208 return newInstance( true );
209 }
210
211
212
213
214
215
216
217
218 @Nonnull
219 public static RepositoryPolicy newInstance( boolean withDefaults )
220 {
221 return newBuilder( withDefaults ).build();
222 }
223
224
225
226
227
228
229
230
231 @Nonnull
232 public static Builder newBuilder()
233 {
234 return newBuilder( true );
235 }
236
237
238
239
240
241
242
243 @Nonnull
244 public static Builder newBuilder( boolean withDefaults )
245 {
246 return new Builder( withDefaults );
247 }
248
249
250
251
252
253
254
255
256 @Nonnull
257 public static Builder newBuilder( RepositoryPolicy from )
258 {
259 return newBuilder( from, false );
260 }
261
262
263
264
265
266
267
268
269 @Nonnull
270 public static Builder newBuilder( RepositoryPolicy from, boolean forceCopy )
271 {
272 return new Builder( from, forceCopy );
273 }
274
275
276
277
278
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 }