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 final String updatePolicy;
40
41
42
43
44
45
46 final String checksumPolicy;
47
48 final Map<Object, InputLocation> locations;
49
50
51
52
53
54 RepositoryPolicy(
55 String enabled,
56 String updatePolicy,
57 String checksumPolicy,
58 Map<Object, InputLocation> locations
59 ) {
60 this.enabled = enabled;
61 this.updatePolicy = updatePolicy;
62 this.checksumPolicy = checksumPolicy;
63 this.locations = ImmutableCollections.copy(locations);
64 }
65
66
67
68
69
70
71
72
73 public String getEnabled() {
74 return this.enabled;
75 }
76
77
78
79
80
81
82
83
84
85
86 public String getUpdatePolicy() {
87 return this.updatePolicy;
88 }
89
90
91
92
93
94
95
96
97
98 public String getChecksumPolicy() {
99 return this.checksumPolicy;
100 }
101
102
103
104
105 public InputLocation getLocation(Object key) {
106 return locations != null ? locations.get(key) : null;
107 }
108
109
110
111
112
113
114 @Nonnull
115 public Builder with() {
116 return newBuilder(this);
117 }
118
119
120
121
122
123
124 @Nonnull
125 public RepositoryPolicy withEnabled(String enabled) {
126 return newBuilder(this, true).enabled(enabled).build();
127 }
128
129
130
131
132
133
134 @Nonnull
135 public RepositoryPolicy withUpdatePolicy(String updatePolicy) {
136 return newBuilder(this, true).updatePolicy(updatePolicy).build();
137 }
138
139
140
141
142
143
144 @Nonnull
145 public RepositoryPolicy withChecksumPolicy(String checksumPolicy) {
146 return newBuilder(this, true).checksumPolicy(checksumPolicy).build();
147 }
148
149
150
151
152
153
154
155
156 @Nonnull
157 public static RepositoryPolicy newInstance() {
158 return newInstance(true);
159 }
160
161
162
163
164
165
166
167
168 @Nonnull
169 public static RepositoryPolicy newInstance(boolean withDefaults) {
170 return newBuilder(withDefaults).build();
171 }
172
173
174
175
176
177
178
179
180 @Nonnull
181 public static Builder newBuilder() {
182 return newBuilder(true);
183 }
184
185
186
187
188
189
190
191 @Nonnull
192 public static Builder newBuilder(boolean withDefaults) {
193 return new Builder(withDefaults);
194 }
195
196
197
198
199
200
201
202
203 @Nonnull
204 public static Builder newBuilder(RepositoryPolicy from) {
205 return newBuilder(from, false);
206 }
207
208
209
210
211
212
213
214
215 @Nonnull
216 public static Builder newBuilder(RepositoryPolicy from, boolean forceCopy) {
217 return new Builder(from, forceCopy);
218 }
219
220
221
222
223
224
225 @NotThreadSafe
226 public static class Builder
227 {
228 RepositoryPolicy base;
229 String enabled;
230 String updatePolicy;
231 String checksumPolicy;
232 Map<Object, InputLocation> locations;
233
234 Builder(boolean withDefaults) {
235 if (withDefaults) {
236 }
237 }
238
239 Builder(RepositoryPolicy base, boolean forceCopy) {
240 if (forceCopy) {
241 this.enabled = base.enabled;
242 this.updatePolicy = base.updatePolicy;
243 this.checksumPolicy = base.checksumPolicy;
244 this.locations = base.locations;
245 } else {
246 this.base = base;
247 }
248 }
249
250 @Nonnull
251 public Builder enabled(String enabled) {
252 this.enabled = enabled;
253 return this;
254 }
255
256 @Nonnull
257 public Builder updatePolicy(String updatePolicy) {
258 this.updatePolicy = updatePolicy;
259 return this;
260 }
261
262 @Nonnull
263 public Builder checksumPolicy(String checksumPolicy) {
264 this.checksumPolicy = checksumPolicy;
265 return this;
266 }
267
268
269 @Nonnull
270 public Builder location(Object key, InputLocation location) {
271 if (location != null) {
272 if (!(this.locations instanceof HashMap)) {
273 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
274 }
275 this.locations.put(key, location);
276 }
277 return this;
278 }
279
280 @Nonnull
281 public RepositoryPolicy build() {
282 if (base != null
283 && (enabled == null || enabled == base.enabled)
284 && (updatePolicy == null || updatePolicy == base.updatePolicy)
285 && (checksumPolicy == null || checksumPolicy == base.checksumPolicy)
286 ) {
287 return base;
288 }
289 Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
290 Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
291 Map<Object, InputLocation> locations = new HashMap<>();
292 locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
293 locations.put("enabled", newlocs.containsKey("enabled") ? newlocs.get("enabled") : oldlocs.get("enabled"));
294 locations.put("updatePolicy", newlocs.containsKey("updatePolicy") ? newlocs.get("updatePolicy") : oldlocs.get("updatePolicy"));
295 locations.put("checksumPolicy", newlocs.containsKey("checksumPolicy") ? newlocs.get("checksumPolicy") : oldlocs.get("checksumPolicy"));
296 return new RepositoryPolicy(
297 enabled != null ? enabled : (base != null ? base.enabled : null),
298 updatePolicy != null ? updatePolicy : (base != null ? base.updatePolicy : null),
299 checksumPolicy != null ? checksumPolicy : (base != null ? base.checksumPolicy : null),
300 locations
301 );
302 }
303 }
304
305
306
307 public boolean isEnabled() {
308 return (getEnabled() != null) ? Boolean.parseBoolean(getEnabled()) : true;
309 }
310
311
312
313 }