1
2
3
4 package org.apache.maven.api.model;
5
6 import java.io.Serializable;
7 import java.util.Collections;
8 import java.util.HashMap;
9 import java.util.Map;
10 import org.apache.maven.api.annotations.Experimental;
11 import org.apache.maven.api.annotations.Generated;
12 import org.apache.maven.api.annotations.Immutable;
13 import org.apache.maven.api.annotations.Nonnull;
14 import org.apache.maven.api.annotations.NotThreadSafe;
15 import org.apache.maven.api.annotations.ThreadSafe;
16
17
18
19
20 @Experimental
21 @Generated @ThreadSafe @Immutable
22 public class Site
23 implements Serializable, InputLocationTracker
24 {
25
26
27
28
29 final String id;
30
31
32
33 final String name;
34
35
36
37
38
39 final String url;
40
41
42
43
44
45
46
47 final String childSiteUrlInheritAppendPath;
48
49 final InputLocation location;
50
51 final InputLocation idLocation;
52
53 final InputLocation nameLocation;
54
55 final InputLocation urlLocation;
56
57 final InputLocation childSiteUrlInheritAppendPathLocation;
58
59 final Map<Object, InputLocation> locations;
60
61
62
63
64
65 Site(
66 String id,
67 String name,
68 String url,
69 String childSiteUrlInheritAppendPath,
70 Map<Object, InputLocation> locations,
71 InputLocation location,
72 InputLocation idLocation,
73 InputLocation nameLocation,
74 InputLocation urlLocation,
75 InputLocation childSiteUrlInheritAppendPathLocation
76 )
77 {
78 this.id = id;
79 this.name = name;
80 this.url = url;
81 this.childSiteUrlInheritAppendPath = childSiteUrlInheritAppendPath;
82 this.locations = ImmutableCollections.copy( locations );
83 this.location = location;
84 this.idLocation = idLocation;
85 this.nameLocation = nameLocation;
86 this.urlLocation = urlLocation;
87 this.childSiteUrlInheritAppendPathLocation = childSiteUrlInheritAppendPathLocation;
88 }
89
90
91
92
93
94
95
96 public String getId()
97 {
98 return this.id;
99 }
100
101
102
103
104
105
106 public String getName()
107 {
108 return this.name;
109 }
110
111
112
113
114
115
116
117
118 public String getUrl()
119 {
120 return this.url;
121 }
122
123
124
125
126
127
128
129
130
131
132 public String getChildSiteUrlInheritAppendPath()
133 {
134 return this.childSiteUrlInheritAppendPath;
135 }
136
137
138
139
140 public InputLocation getLocation( Object key )
141 {
142 if ( key instanceof String )
143 {
144 switch ( ( String ) key )
145 {
146 case "":
147 return location;
148 case "id":
149 return idLocation;
150 case "name":
151 return nameLocation;
152 case "url":
153 return urlLocation;
154 case "childSiteUrlInheritAppendPath":
155 return childSiteUrlInheritAppendPathLocation;
156 }
157 }
158 return locations != null ? locations.get( key ) : null;
159 }
160
161
162
163
164
165
166 @Nonnull
167 public Builder with()
168 {
169 return newBuilder( this );
170 }
171
172
173
174
175
176
177 @Nonnull
178 public Site withId( String id )
179 {
180 return with().id( id ).build();
181 }
182
183
184
185
186
187
188 @Nonnull
189 public Site withName( String name )
190 {
191 return with().name( name ).build();
192 }
193
194
195
196
197
198
199 @Nonnull
200 public Site withUrl( String url )
201 {
202 return with().url( url ).build();
203 }
204
205
206
207
208
209
210 @Nonnull
211 public Site withChildSiteUrlInheritAppendPath( String childSiteUrlInheritAppendPath )
212 {
213 return with().childSiteUrlInheritAppendPath( childSiteUrlInheritAppendPath ).build();
214 }
215
216
217
218
219
220
221
222
223 @Nonnull
224 public static Site newInstance()
225 {
226 return newInstance( true );
227 }
228
229
230
231
232
233
234
235
236 @Nonnull
237 public static Site newInstance( boolean withDefaults )
238 {
239 return newBuilder( withDefaults ).build();
240 }
241
242
243
244
245
246
247
248
249 @Nonnull
250 public static Builder newBuilder()
251 {
252 return newBuilder( true );
253 }
254
255
256
257
258
259
260
261 @Nonnull
262 public static Builder newBuilder( boolean withDefaults )
263 {
264 return new Builder( withDefaults );
265 }
266
267
268
269
270
271
272
273
274 @Nonnull
275 public static Builder newBuilder( Site from )
276 {
277 return newBuilder( from, false );
278 }
279
280
281
282
283
284
285
286
287 @Nonnull
288 public static Builder newBuilder( Site from, boolean forceCopy )
289 {
290 return new Builder( from, forceCopy );
291 }
292
293
294
295
296
297
298 @NotThreadSafe
299 public static class Builder
300 {
301 Site base;
302 String id;
303 String name;
304 String url;
305 String childSiteUrlInheritAppendPath;
306 Map<Object, InputLocation> locations;
307
308 Builder( boolean withDefaults )
309 {
310 if ( withDefaults )
311 {
312 }
313 }
314
315 Builder( Site base, boolean forceCopy )
316 {
317 if ( forceCopy )
318 {
319 this.id = base.id;
320 this.name = base.name;
321 this.url = base.url;
322 this.childSiteUrlInheritAppendPath = base.childSiteUrlInheritAppendPath;
323 }
324 else
325 {
326 this.base = base;
327 }
328 }
329
330 @Nonnull
331 public Builder id( String id )
332 {
333 this.id = id;
334 return this;
335 }
336
337 @Nonnull
338 public Builder name( String name )
339 {
340 this.name = name;
341 return this;
342 }
343
344 @Nonnull
345 public Builder url( String url )
346 {
347 this.url = url;
348 return this;
349 }
350
351 @Nonnull
352 public Builder childSiteUrlInheritAppendPath( String childSiteUrlInheritAppendPath )
353 {
354 this.childSiteUrlInheritAppendPath = childSiteUrlInheritAppendPath;
355 return this;
356 }
357
358
359 @Nonnull
360 public Builder location( Object key, InputLocation location )
361 {
362 if ( location != null )
363 {
364 if ( this.locations == null )
365 {
366 this.locations = new HashMap<>();
367 }
368 this.locations.put( key, location );
369 }
370 return this;
371 }
372
373 @Nonnull
374 public Site build()
375 {
376 if ( base != null
377 && ( id == null || id == base.id )
378 && ( name == null || name == base.name )
379 && ( url == null || url == base.url )
380 && ( childSiteUrlInheritAppendPath == null || childSiteUrlInheritAppendPath == base.childSiteUrlInheritAppendPath )
381 )
382 {
383 return base;
384 }
385 Map<Object, InputLocation> locations = null;
386 InputLocation location = null;
387 InputLocation idLocation = null;
388 InputLocation nameLocation = null;
389 InputLocation urlLocation = null;
390 InputLocation childSiteUrlInheritAppendPathLocation = null;
391 if ( this.locations != null )
392 {
393 locations = this.locations;
394 location = locations.remove( "" );
395 idLocation = locations.remove( "id" );
396 nameLocation = locations.remove( "name" );
397 urlLocation = locations.remove( "url" );
398 childSiteUrlInheritAppendPathLocation = locations.remove( "childSiteUrlInheritAppendPath" );
399 }
400 return new Site(
401 id != null ? id : ( base != null ? base.id : null ),
402 name != null ? name : ( base != null ? base.name : null ),
403 url != null ? url : ( base != null ? base.url : null ),
404 childSiteUrlInheritAppendPath != null ? childSiteUrlInheritAppendPath : ( base != null ? base.childSiteUrlInheritAppendPath : null ),
405 locations != null ? locations : ( base != null ? base.locations : null ),
406 location != null ? location : ( base != null ? base.location : null ),
407 idLocation != null ? idLocation : ( base != null ? base.idLocation : null ),
408 nameLocation != null ? nameLocation : ( base != null ? base.nameLocation : null ),
409 urlLocation != null ? urlLocation : ( base != null ? base.urlLocation : null ),
410 childSiteUrlInheritAppendPathLocation != null ? childSiteUrlInheritAppendPathLocation : ( base != null ? base.childSiteUrlInheritAppendPathLocation : null )
411 );
412 }
413 }
414
415
416
417
418 public boolean isChildSiteUrlInheritAppendPath()
419 {
420 return ( getChildSiteUrlInheritAppendPath() != null ) ? Boolean.parseBoolean( getChildSiteUrlInheritAppendPath() ) : true;
421 }
422
423
424
425 }