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