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