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