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 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
21
22 @Experimental
23 @Generated @ThreadSafe @Immutable
24 public class RepositoryPolicy
25 implements Serializable, InputLocationTracker
26 {
27
28
29
30
31
32 final String enabled;
33
34
35
36
37
38
39
40 final String updatePolicy;
41
42
43
44
45
46
47 final String checksumPolicy;
48
49 final Map<Object, InputLocation> locations;
50
51 final InputLocation importedFrom;
52
53
54
55
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
74
75
76
77
78
79 public String getEnabled() {
80 return this.enabled;
81 }
82
83
84
85
86
87
88
89
90
91
92 public String getUpdatePolicy() {
93 return this.updatePolicy;
94 }
95
96
97
98
99
100
101
102
103
104 public String getChecksumPolicy() {
105 return this.checksumPolicy;
106 }
107
108
109
110
111 public InputLocation getLocation(Object key) {
112 return locations != null ? locations.get(key) : null;
113 }
114
115
116
117
118 public Set<Object> getLocationKeys() {
119 return locations != null ? locations.keySet() : null;
120 }
121
122
123
124
125 public InputLocation getImportedFrom()
126 {
127 return importedFrom;
128 }
129
130
131
132
133
134
135 @Nonnull
136 public Builder with() {
137 return newBuilder(this);
138 }
139
140
141
142
143
144
145 @Nonnull
146 public RepositoryPolicy withEnabled(String enabled) {
147 return newBuilder(this, true).enabled(enabled).build();
148 }
149
150
151
152
153
154
155 @Nonnull
156 public RepositoryPolicy withUpdatePolicy(String updatePolicy) {
157 return newBuilder(this, true).updatePolicy(updatePolicy).build();
158 }
159
160
161
162
163
164
165 @Nonnull
166 public RepositoryPolicy withChecksumPolicy(String checksumPolicy) {
167 return newBuilder(this, true).checksumPolicy(checksumPolicy).build();
168 }
169
170
171
172
173
174
175
176
177 @Nonnull
178 public static RepositoryPolicy newInstance() {
179 return newInstance(true);
180 }
181
182
183
184
185
186
187
188
189 @Nonnull
190 public static RepositoryPolicy newInstance(boolean withDefaults) {
191 return newBuilder(withDefaults).build();
192 }
193
194
195
196
197
198
199
200
201 @Nonnull
202 public static Builder newBuilder() {
203 return newBuilder(true);
204 }
205
206
207
208
209
210
211
212 @Nonnull
213 public static Builder newBuilder(boolean withDefaults) {
214 return new Builder(withDefaults);
215 }
216
217
218
219
220
221
222
223
224 @Nonnull
225 public static Builder newBuilder(RepositoryPolicy from) {
226 return newBuilder(from, false);
227 }
228
229
230
231
232
233
234
235
236 @Nonnull
237 public static Builder newBuilder(RepositoryPolicy from, boolean forceCopy) {
238 return new Builder(from, forceCopy);
239 }
240
241
242
243
244
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
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 }