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 Map<Object, InputLocation> locations;
54
55
56
57
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
73
74
75
76
77
78 public String getEnabled() {
79 return this.enabled;
80 }
81
82
83
84
85
86
87
88
89
90
91
92
93
94 public String getUpdatePolicy() {
95 return this.updatePolicy;
96 }
97
98
99
100
101
102
103
104
105
106
107
108 public String getChecksumPolicy() {
109 return this.checksumPolicy;
110 }
111
112
113
114
115 public InputLocation getLocation(Object key) {
116 return locations != null ? locations.get(key) : null;
117 }
118
119
120
121
122
123
124 @Nonnull
125 public Builder with() {
126 return newBuilder(this);
127 }
128
129
130
131
132
133
134 @Nonnull
135 public RepositoryPolicy withEnabled(String enabled) {
136 return newBuilder(this, true).enabled(enabled).build();
137 }
138
139
140
141
142
143
144 @Nonnull
145 public RepositoryPolicy withUpdatePolicy(String updatePolicy) {
146 return newBuilder(this, true).updatePolicy(updatePolicy).build();
147 }
148
149
150
151
152
153
154 @Nonnull
155 public RepositoryPolicy withChecksumPolicy(String checksumPolicy) {
156 return newBuilder(this, true).checksumPolicy(checksumPolicy).build();
157 }
158
159
160
161
162
163
164
165
166 @Nonnull
167 public static RepositoryPolicy newInstance() {
168 return newInstance(true);
169 }
170
171
172
173
174
175
176
177
178 @Nonnull
179 public static RepositoryPolicy newInstance(boolean withDefaults) {
180 return newBuilder(withDefaults).build();
181 }
182
183
184
185
186
187
188
189
190 @Nonnull
191 public static Builder newBuilder() {
192 return newBuilder(true);
193 }
194
195
196
197
198
199
200
201 @Nonnull
202 public static Builder newBuilder(boolean withDefaults) {
203 return new Builder(withDefaults);
204 }
205
206
207
208
209
210
211
212
213 @Nonnull
214 public static Builder newBuilder(RepositoryPolicy from) {
215 return newBuilder(from, false);
216 }
217
218
219
220
221
222
223
224
225 @Nonnull
226 public static Builder newBuilder(RepositoryPolicy from, boolean forceCopy) {
227 return new Builder(from, forceCopy);
228 }
229
230
231
232
233
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> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
300 Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
301 Map<Object, InputLocation> locations = new HashMap<>();
302 locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
303 locations.put("enabled", newlocs.containsKey("enabled") ? newlocs.get("enabled") : oldlocs.get("enabled"));
304 locations.put("updatePolicy", newlocs.containsKey("updatePolicy") ? newlocs.get("updatePolicy") : oldlocs.get("updatePolicy"));
305 locations.put("checksumPolicy", newlocs.containsKey("checksumPolicy") ? newlocs.get("checksumPolicy") : oldlocs.get("checksumPolicy"));
306 return new RepositoryPolicy(
307 enabled != null ? enabled : (base != null ? base.enabled : null),
308 updatePolicy != null ? updatePolicy : (base != null ? base.updatePolicy : null),
309 checksumPolicy != null ? checksumPolicy : (base != null ? base.checksumPolicy : null),
310 locations
311 );
312 }
313 }
314
315
316
317 public boolean isEnabled()
318 {
319 return ( getEnabled() != null ) ? Boolean.parseBoolean( getEnabled() ) : true;
320 }
321
322
323
324 }