View Javadoc
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      * @param key the key of the field, must not be {@code null}
119      * @return the location of the field in the input source or {@code null} if unknown
120      * @throws NullPointerException if {@code key} is {@code null}
121      */
122     public InputLocation getLocation(Object key) {
123         Objects.requireNonNull(key, "key");
124         return locations.get(key);
125     }
126 
127     /**
128      * Gets the keys of the locations of the input source.
129      */
130     public Set<Object> getLocationKeys() {
131         return locations.keySet();
132     }
133 
134     protected Stream<Object> getLocationKeyStream() {
135         return locations.keySet().stream();
136     }
137 
138     /**
139      * Gets the input location that caused this model to be read.
140      */
141     public InputLocation getImportedFrom() {
142         return importedFrom;
143     }
144 
145     /**
146      * Creates a new builder with this object as the basis.
147      *
148      * @return a {@code Builder}
149      */
150     @Nonnull
151     public Builder with() {
152         return newBuilder(this);
153     }
154     /**
155      * Creates a new {@code Site} instance using the specified id.
156      *
157      * @param id the new {@code String} to use
158      * @return a {@code Site} with the specified id
159      */
160     @Nonnull
161     public Site withId(String id) {
162         return newBuilder(this, true).id(id).build();
163     }
164     /**
165      * Creates a new {@code Site} instance using the specified name.
166      *
167      * @param name the new {@code String} to use
168      * @return a {@code Site} with the specified name
169      */
170     @Nonnull
171     public Site withName(String name) {
172         return newBuilder(this, true).name(name).build();
173     }
174     /**
175      * Creates a new {@code Site} instance using the specified url.
176      *
177      * @param url the new {@code String} to use
178      * @return a {@code Site} with the specified url
179      */
180     @Nonnull
181     public Site withUrl(String url) {
182         return newBuilder(this, true).url(url).build();
183     }
184     /**
185      * Creates a new {@code Site} instance using the specified childSiteUrlInheritAppendPath.
186      *
187      * @param childSiteUrlInheritAppendPath the new {@code String} to use
188      * @return a {@code Site} with the specified childSiteUrlInheritAppendPath
189      */
190     @Nonnull
191     public Site withChildSiteUrlInheritAppendPath(String childSiteUrlInheritAppendPath) {
192         return newBuilder(this, true).childSiteUrlInheritAppendPath(childSiteUrlInheritAppendPath).build();
193     }
194 
195     /**
196      * Creates a new {@code Site} instance.
197      * Equivalent to {@code newInstance(true)}.
198      * @see #newInstance(boolean)
199      *
200      * @return a new {@code Site}
201      */
202     @Nonnull
203     public static Site newInstance() {
204         return newInstance(true);
205     }
206 
207     /**
208      * Creates a new {@code Site} instance using default values or not.
209      * Equivalent to {@code newBuilder(withDefaults).build()}.
210      *
211      * @param withDefaults the boolean indicating whether default values should be used
212      * @return a new {@code Site}
213      */
214     @Nonnull
215     public static Site newInstance(boolean withDefaults) {
216         return newBuilder(withDefaults).build();
217     }
218 
219     /**
220      * Creates a new {@code Site} builder instance.
221      * Equivalent to {@code newBuilder(true)}.
222      * @see #newBuilder(boolean)
223      *
224      * @return a new {@code Builder}
225      */
226     @Nonnull
227     public static Builder newBuilder() {
228         return newBuilder(true);
229     }
230 
231     /**
232      * Creates a new {@code Site} builder instance using default values or not.
233      *
234      * @param withDefaults the boolean indicating whether default values should be used
235      * @return a new {@code Builder}
236      */
237     @Nonnull
238     public static Builder newBuilder(boolean withDefaults) {
239         return new Builder(withDefaults);
240     }
241 
242     /**
243      * Creates a new {@code Site} builder instance using the specified object as a basis.
244      * Equivalent to {@code newBuilder(from, false)}.
245      *
246      * @param from the {@code Site} instance to use as a basis
247      * @return a new {@code Builder}
248      */
249     @Nonnull
250     public static Builder newBuilder(Site from) {
251         return newBuilder(from, false);
252     }
253 
254     /**
255      * Creates a new {@code Site} builder instance using the specified object as a basis.
256      *
257      * @param from the {@code Site} instance to use as a basis
258      * @param forceCopy the boolean indicating if a copy should be forced
259      * @return a new {@code Builder}
260      */
261     @Nonnull
262     public static Builder newBuilder(Site from, boolean forceCopy) {
263         return new Builder(from, forceCopy);
264     }
265 
266     /**
267      * Builder class used to create Site instances.
268      * @see #with()
269      * @see #newBuilder()
270      */
271     @NotThreadSafe
272     public static class Builder
273     {
274         Site base;
275         String id;
276         String name;
277         String url;
278         String childSiteUrlInheritAppendPath;
279         Map<Object, InputLocation> locations;
280         InputLocation importedFrom;
281 
282         protected Builder(boolean withDefaults) {
283             if (withDefaults) {
284             }
285         }
286 
287         protected Builder(Site base, boolean forceCopy) {
288             if (forceCopy) {
289                 this.id = base.id;
290                 this.name = base.name;
291                 this.url = base.url;
292                 this.childSiteUrlInheritAppendPath = base.childSiteUrlInheritAppendPath;
293                 this.locations = base.locations;
294                 this.importedFrom = base.importedFrom;
295             } else {
296                 this.base = base;
297             }
298         }
299 
300         @Nonnull
301         public Builder id(String id) {
302             this.id = id;
303             return this;
304         }
305 
306         @Nonnull
307         public Builder name(String name) {
308             this.name = name;
309             return this;
310         }
311 
312         @Nonnull
313         public Builder url(String url) {
314             this.url = url;
315             return this;
316         }
317 
318         @Nonnull
319         public Builder childSiteUrlInheritAppendPath(String childSiteUrlInheritAppendPath) {
320             this.childSiteUrlInheritAppendPath = childSiteUrlInheritAppendPath;
321             return this;
322         }
323 
324 
325         @Nonnull
326         public Builder location(Object key, InputLocation location) {
327             if (location != null) {
328                 if (!(this.locations instanceof HashMap)) {
329                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
330                 }
331                 this.locations.put(key, location);
332             }
333             return this;
334         }
335 
336         @Nonnull
337         public Builder importedFrom(InputLocation importedFrom) {
338             this.importedFrom = importedFrom;
339             return this;
340         }
341 
342         @Nonnull
343         public Site build() {
344             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
345             if (base != null
346                     && (id == null || id == base.id)
347                     && (name == null || name == base.name)
348                     && (url == null || url == base.url)
349                     && (childSiteUrlInheritAppendPath == null || childSiteUrlInheritAppendPath == base.childSiteUrlInheritAppendPath)
350             ) {
351                 return base;
352             }
353             return new Site(this);
354         }
355 
356         Map<Object, InputLocation> computeLocations() {
357             Map<Object, InputLocation> newlocs = locations != null ? locations : Map.of();
358             Map<Object, InputLocation> oldlocs = base != null ? base.locations : Map.of();
359             if (newlocs.isEmpty()) {
360                 return Map.copyOf(oldlocs);
361             }
362             if (oldlocs.isEmpty()) {
363                 return Map.copyOf(newlocs);
364             }
365             return Stream.concat(newlocs.entrySet().stream(), oldlocs.entrySet().stream())
366                     // Keep value from newlocs in case of duplicates
367                     .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1));
368         }
369     }
370 
371 
372             
373 
374     public boolean isChildSiteUrlInheritAppendPath() {
375         return (getChildSiteUrlInheritAppendPath() != null) ? Boolean.parseBoolean(getChildSiteUrlInheritAppendPath()) : true;
376     }
377 
378             
379           
380 }