1 // =================== DO NOT EDIT THIS FILE ====================
2 // Generated by Modello Velocity from model.vm
3 // template, any modifications will be overwritten.
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.Objects;
12 import java.util.Optional;
13 import java.util.Set;
14 import java.util.stream.Collectors;
15 import java.util.stream.Stream;
16 import org.apache.maven.api.annotations.Experimental;
17 import org.apache.maven.api.annotations.Generated;
18 import org.apache.maven.api.annotations.Immutable;
19 import org.apache.maven.api.annotations.Nonnull;
20 import org.apache.maven.api.annotations.NotThreadSafe;
21 import org.apache.maven.api.annotations.ThreadSafe;
22
23 /**
24 * Contains the information needed for deploying websites.
25 */
26 @Experimental
27 @Generated @ThreadSafe @Immutable
28 public class Site
29 implements Serializable, InputLocationTracker
30 {
31 /**
32 * A unique identifier for a deployment location. This is used to match the
33 * site to configuration in the {@code settings.xml} file, for example.
34 */
35 final String id;
36 /**
37 * Human readable name of the deployment location.
38 */
39 final String name;
40 /**
41 * The url of the location where website is deployed, in the form {@code protocol://hostname/path}.
42 * <p><b>Default value is</b>: parent value [+ path adjustment] + (artifactId or project.directory property), or just parent value if
43 * site's {@code child.site.url.inherit.append.path="false"}.</p>
44 */
45 final String url;
46 /**
47 * When children inherit from distribution management site url, append path or not? Note: While the type
48 * of this field is {@code String} for technical reasons, the semantic type is actually
49 * {@code Boolean}
50 * <p><b>Default value is</b>: {@code true}</p>
51 * @since Maven 3.6.1
52 */
53 final String childSiteUrlInheritAppendPath;
54 /** Locations */
55 final Map<Object, InputLocation> locations;
56 /** Location tracking */
57 final InputLocation importedFrom;
58
59 /**
60 * Constructor for this class, to be called from its subclasses and {@link Builder}.
61 * @see Builder#build()
62 */
63 protected Site(Builder builder) {
64 this.id = builder.id != null ? builder.id : (builder.base != null ? builder.base.id : null);
65 this.name = builder.name != null ? builder.name : (builder.base != null ? builder.base.name : null);
66 this.url = builder.url != null ? builder.url : (builder.base != null ? builder.base.url : null);
67 this.childSiteUrlInheritAppendPath = builder.childSiteUrlInheritAppendPath != null ? builder.childSiteUrlInheritAppendPath : (builder.base != null ? builder.base.childSiteUrlInheritAppendPath : null);
68 this.locations = builder.computeLocations();
69 this.importedFrom = builder.importedFrom;
70 }
71
72 /**
73 * A unique identifier for a deployment location. This is used to match the
74 * site to configuration in the {@code settings.xml} file, for example.
75 *
76 * @return a {@code String}
77 */
78 public String getId() {
79 return this.id;
80 }
81
82 /**
83 * Human readable name of the deployment location.
84 *
85 * @return a {@code String}
86 */
87 public String getName() {
88 return this.name;
89 }
90
91 /**
92 * The url of the location where website is deployed, in the form {@code protocol://hostname/path}.
93 * <p><b>Default value is</b>: parent value [+ path adjustment] + (artifactId or project.directory property), or just parent value if
94 * site's {@code child.site.url.inherit.append.path="false"}.</p>
95 *
96 * @return a {@code String}
97 */
98 public String getUrl() {
99 return this.url;
100 }
101
102 /**
103 * When children inherit from distribution management site url, append path or not? Note: While the type
104 * of this field is {@code String} for technical reasons, the semantic type is actually
105 * {@code Boolean}
106 * <p><b>Default value is</b>: {@code true}</p>
107 * @since Maven 3.6.1
108 *
109 * @return a {@code String}
110 */
111 public String getChildSiteUrlInheritAppendPath() {
112 return this.childSiteUrlInheritAppendPath;
113 }
114
115 /**
116 * Gets the location of the specified field in the input source.
117 */
118 public InputLocation getLocation(Object key) {
119 return locations.get(key);
120 }
121
122 /**
123 * Gets the keys of the locations of the input source.
124 */
125 public Set<Object> getLocationKeys() {
126 return locations.keySet();
127 }
128
129 protected Stream<Object> getLocationKeyStream() {
130 return locations.keySet().stream();
131 }
132
133 /**
134 * Gets the input location that caused this model to be read.
135 */
136 public InputLocation getImportedFrom()
137 {
138 return importedFrom;
139 }
140
141 /**
142 * Creates a new builder with this object as the basis.
143 *
144 * @return a {@code Builder}
145 */
146 @Nonnull
147 public Builder with() {
148 return newBuilder(this);
149 }
150 /**
151 * Creates a new {@code Site} instance using the specified id.
152 *
153 * @param id the new {@code String} to use
154 * @return a {@code Site} with the specified id
155 */
156 @Nonnull
157 public Site withId(String id) {
158 return newBuilder(this, true).id(id).build();
159 }
160 /**
161 * Creates a new {@code Site} instance using the specified name.
162 *
163 * @param name the new {@code String} to use
164 * @return a {@code Site} with the specified name
165 */
166 @Nonnull
167 public Site withName(String name) {
168 return newBuilder(this, true).name(name).build();
169 }
170 /**
171 * Creates a new {@code Site} instance using the specified url.
172 *
173 * @param url the new {@code String} to use
174 * @return a {@code Site} with the specified url
175 */
176 @Nonnull
177 public Site withUrl(String url) {
178 return newBuilder(this, true).url(url).build();
179 }
180 /**
181 * Creates a new {@code Site} instance using the specified childSiteUrlInheritAppendPath.
182 *
183 * @param childSiteUrlInheritAppendPath the new {@code String} to use
184 * @return a {@code Site} with the specified childSiteUrlInheritAppendPath
185 */
186 @Nonnull
187 public Site withChildSiteUrlInheritAppendPath(String childSiteUrlInheritAppendPath) {
188 return newBuilder(this, true).childSiteUrlInheritAppendPath(childSiteUrlInheritAppendPath).build();
189 }
190
191 /**
192 * Creates a new {@code Site} instance.
193 * Equivalent to {@code newInstance(true)}.
194 * @see #newInstance(boolean)
195 *
196 * @return a new {@code Site}
197 */
198 @Nonnull
199 public static Site newInstance() {
200 return newInstance(true);
201 }
202
203 /**
204 * Creates a new {@code Site} instance using default values or not.
205 * Equivalent to {@code newBuilder(withDefaults).build()}.
206 *
207 * @param withDefaults the boolean indicating whether default values should be used
208 * @return a new {@code Site}
209 */
210 @Nonnull
211 public static Site newInstance(boolean withDefaults) {
212 return newBuilder(withDefaults).build();
213 }
214
215 /**
216 * Creates a new {@code Site} builder instance.
217 * Equivalent to {@code newBuilder(true)}.
218 * @see #newBuilder(boolean)
219 *
220 * @return a new {@code Builder}
221 */
222 @Nonnull
223 public static Builder newBuilder() {
224 return newBuilder(true);
225 }
226
227 /**
228 * Creates a new {@code Site} builder instance using default values or not.
229 *
230 * @param withDefaults the boolean indicating whether default values should be used
231 * @return a new {@code Builder}
232 */
233 @Nonnull
234 public static Builder newBuilder(boolean withDefaults) {
235 return new Builder(withDefaults);
236 }
237
238 /**
239 * Creates a new {@code Site} builder instance using the specified object as a basis.
240 * Equivalent to {@code newBuilder(from, false)}.
241 *
242 * @param from the {@code Site} instance to use as a basis
243 * @return a new {@code Builder}
244 */
245 @Nonnull
246 public static Builder newBuilder(Site from) {
247 return newBuilder(from, false);
248 }
249
250 /**
251 * Creates a new {@code Site} builder instance using the specified object as a basis.
252 *
253 * @param from the {@code Site} instance to use as a basis
254 * @param forceCopy the boolean indicating if a copy should be forced
255 * @return a new {@code Builder}
256 */
257 @Nonnull
258 public static Builder newBuilder(Site from, boolean forceCopy) {
259 return new Builder(from, forceCopy);
260 }
261
262 /**
263 * Builder class used to create Site instances.
264 * @see #with()
265 * @see #newBuilder()
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 // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
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 Map<Object, InputLocation> computeLocations() {
353 Map<Object, InputLocation> newlocs = locations != null ? locations : Map.of();
354 Map<Object, InputLocation> oldlocs = base != null ? base.locations : Map.of();
355 if (newlocs.isEmpty()) {
356 return Map.copyOf(oldlocs);
357 }
358 if (oldlocs.isEmpty()) {
359 return Map.copyOf(newlocs);
360 }
361 return Stream.concat(newlocs.entrySet().stream(), oldlocs.entrySet().stream())
362 // Keep value from newlocs in case of duplicates
363 .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1));
364 }
365 }
366
367
368
369
370 public boolean isChildSiteUrlInheritAppendPath() {
371 return (getChildSiteUrlInheritAppendPath() != null) ? Boolean.parseBoolean(getChildSiteUrlInheritAppendPath()) : true;
372 }
373
374
375
376 }