1
2
3
4 package org.apache.maven.api.model;
5
6 import java.io.Serializable;
7 import java.util.Collections;
8 import java.util.HashMap;
9 import java.util.Map;
10 import org.apache.maven.api.annotations.Experimental;
11 import org.apache.maven.api.annotations.Generated;
12 import org.apache.maven.api.annotations.Immutable;
13 import org.apache.maven.api.annotations.Nonnull;
14 import org.apache.maven.api.annotations.NotThreadSafe;
15 import org.apache.maven.api.annotations.ThreadSafe;
16
17
18
19
20 @Experimental
21 @Generated @ThreadSafe @Immutable
22 public class RepositoryPolicy
23 implements Serializable, InputLocationTracker
24 {
25
26
27
28
29
30 final String enabled;
31
32
33
34
35
36
37
38
39
40
41 final String updatePolicy;
42
43
44
45
46
47
48
49
50 final String checksumPolicy;
51
52 final InputLocation location;
53
54 final InputLocation enabledLocation;
55
56 final InputLocation updatePolicyLocation;
57
58 final InputLocation checksumPolicyLocation;
59
60 final Map<Object, InputLocation> locations;
61
62
63
64
65
66 RepositoryPolicy(
67 String enabled,
68 String updatePolicy,
69 String checksumPolicy,
70 Map<Object, InputLocation> locations,
71 InputLocation location,
72 InputLocation enabledLocation,
73 InputLocation updatePolicyLocation,
74 InputLocation checksumPolicyLocation
75 )
76 {
77 this.enabled = enabled;
78 this.updatePolicy = updatePolicy;
79 this.checksumPolicy = checksumPolicy;
80 this.locations = ImmutableCollections.copy( locations );
81 this.location = location;
82 this.enabledLocation = enabledLocation;
83 this.updatePolicyLocation = updatePolicyLocation;
84 this.checksumPolicyLocation = checksumPolicyLocation;
85 }
86
87
88
89
90
91
92
93
94 public String getEnabled()
95 {
96 return this.enabled;
97 }
98
99
100
101
102
103
104
105
106
107
108
109
110
111 public String getUpdatePolicy()
112 {
113 return this.updatePolicy;
114 }
115
116
117
118
119
120
121
122
123
124
125
126 public String getChecksumPolicy()
127 {
128 return this.checksumPolicy;
129 }
130
131
132
133
134 public InputLocation getLocation( Object key )
135 {
136 if ( key instanceof String )
137 {
138 switch ( ( String ) key )
139 {
140 case "":
141 return location;
142 case "enabled":
143 return enabledLocation;
144 case "updatePolicy":
145 return updatePolicyLocation;
146 case "checksumPolicy":
147 return checksumPolicyLocation;
148 }
149 }
150 return locations != null ? locations.get( key ) : null;
151 }
152
153
154
155
156
157
158 @Nonnull
159 public Builder with()
160 {
161 return newBuilder( this );
162 }
163
164
165
166
167
168
169 @Nonnull
170 public RepositoryPolicy withEnabled( String enabled )
171 {
172 return with().enabled( enabled ).build();
173 }
174
175
176
177
178
179
180 @Nonnull
181 public RepositoryPolicy withUpdatePolicy( String updatePolicy )
182 {
183 return with().updatePolicy( updatePolicy ).build();
184 }
185
186
187
188
189
190
191 @Nonnull
192 public RepositoryPolicy withChecksumPolicy( String checksumPolicy )
193 {
194 return with().checksumPolicy( checksumPolicy ).build();
195 }
196
197
198
199
200
201
202
203
204 @Nonnull
205 public static RepositoryPolicy newInstance()
206 {
207 return newInstance( true );
208 }
209
210
211
212
213
214
215
216
217 @Nonnull
218 public static RepositoryPolicy newInstance( boolean withDefaults )
219 {
220 return newBuilder( withDefaults ).build();
221 }
222
223
224
225
226
227
228
229
230 @Nonnull
231 public static Builder newBuilder()
232 {
233 return newBuilder( true );
234 }
235
236
237
238
239
240
241
242 @Nonnull
243 public static Builder newBuilder( boolean withDefaults )
244 {
245 return new Builder( withDefaults );
246 }
247
248
249
250
251
252
253
254
255 @Nonnull
256 public static Builder newBuilder( RepositoryPolicy from )
257 {
258 return newBuilder( from, false );
259 }
260
261
262
263
264
265
266
267
268 @Nonnull
269 public static Builder newBuilder( RepositoryPolicy from, boolean forceCopy )
270 {
271 return new Builder( from, forceCopy );
272 }
273
274
275
276
277
278
279 @NotThreadSafe
280 public static class Builder
281 {
282 RepositoryPolicy base;
283 String enabled;
284 String updatePolicy;
285 String checksumPolicy;
286 Map<Object, InputLocation> locations;
287
288 Builder( boolean withDefaults )
289 {
290 if ( withDefaults )
291 {
292 }
293 }
294
295 Builder( RepositoryPolicy base, boolean forceCopy )
296 {
297 if ( forceCopy )
298 {
299 this.enabled = base.enabled;
300 this.updatePolicy = base.updatePolicy;
301 this.checksumPolicy = base.checksumPolicy;
302 }
303 else
304 {
305 this.base = base;
306 }
307 }
308
309 @Nonnull
310 public Builder enabled( String enabled )
311 {
312 this.enabled = enabled;
313 return this;
314 }
315
316 @Nonnull
317 public Builder updatePolicy( String updatePolicy )
318 {
319 this.updatePolicy = updatePolicy;
320 return this;
321 }
322
323 @Nonnull
324 public Builder checksumPolicy( String checksumPolicy )
325 {
326 this.checksumPolicy = checksumPolicy;
327 return this;
328 }
329
330
331 @Nonnull
332 public Builder location( Object key, InputLocation location )
333 {
334 if ( location != null )
335 {
336 if ( this.locations == null )
337 {
338 this.locations = new HashMap<>();
339 }
340 this.locations.put( key, location );
341 }
342 return this;
343 }
344
345 @Nonnull
346 public RepositoryPolicy build()
347 {
348 if ( base != null
349 && ( enabled == null || enabled == base.enabled )
350 && ( updatePolicy == null || updatePolicy == base.updatePolicy )
351 && ( checksumPolicy == null || checksumPolicy == base.checksumPolicy )
352 )
353 {
354 return base;
355 }
356 Map<Object, InputLocation> locations = null;
357 InputLocation location = null;
358 InputLocation enabledLocation = null;
359 InputLocation updatePolicyLocation = null;
360 InputLocation checksumPolicyLocation = null;
361 if ( this.locations != null )
362 {
363 locations = this.locations;
364 location = locations.remove( "" );
365 enabledLocation = locations.remove( "enabled" );
366 updatePolicyLocation = locations.remove( "updatePolicy" );
367 checksumPolicyLocation = locations.remove( "checksumPolicy" );
368 }
369 return new RepositoryPolicy(
370 enabled != null ? enabled : ( base != null ? base.enabled : null ),
371 updatePolicy != null ? updatePolicy : ( base != null ? base.updatePolicy : null ),
372 checksumPolicy != null ? checksumPolicy : ( base != null ? base.checksumPolicy : null ),
373 locations != null ? locations : ( base != null ? base.locations : null ),
374 location != null ? location : ( base != null ? base.location : null ),
375 enabledLocation != null ? enabledLocation : ( base != null ? base.enabledLocation : null ),
376 updatePolicyLocation != null ? updatePolicyLocation : ( base != null ? base.updatePolicyLocation : null ),
377 checksumPolicyLocation != null ? checksumPolicyLocation : ( base != null ? base.checksumPolicyLocation : null )
378 );
379 }
380 }
381
382
383
384 public boolean isEnabled()
385 {
386 return ( getEnabled() != null ) ? Boolean.parseBoolean( getEnabled() ) : true;
387 }
388
389
390
391 }