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