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.Set;
12  import org.apache.maven.api.annotations.Experimental;
13  import org.apache.maven.api.annotations.Generated;
14  import org.apache.maven.api.annotations.Immutable;
15  import org.apache.maven.api.annotations.Nonnull;
16  import org.apache.maven.api.annotations.NotThreadSafe;
17  import org.apache.maven.api.annotations.ThreadSafe;
18  
19  /**
20   * Contains the information needed for deploying websites.
21   */
22  @Experimental
23  @Generated @ThreadSafe @Immutable
24  public class Site
25      implements Serializable, InputLocationTracker
26  {
27      /**
28       * A unique identifier for a deployment location. This is used to match the
29       * site to configuration in the {@code settings.xml} file, for example.
30       */
31      final String id;
32      /**
33       * Human readable name of the deployment location.
34       */
35      final String name;
36      /**
37       * The url of the location where website is deployed, in the form {@code protocol://hostname/path}.
38       * <p><b>Default value is</b>: parent value [+ path adjustment] + (artifactId or project.directory property), or just parent value if
39       * site's {@code child.site.url.inherit.append.path="false"}.</p>
40       */
41      final String url;
42      /**
43       * When children inherit from distribution management site url, append path or not? Note: While the type
44       * of this field is {@code String} for technical reasons, the semantic type is actually
45       * {@code Boolean}
46       * <p><b>Default value is</b>: {@code true}</p>
47       * @since Maven 3.6.1
48       */
49      final String childSiteUrlInheritAppendPath;
50      /** Locations (this potentially hides the same name field from the super class) */
51      final Map<Object, InputLocation> locations;
52      /** Location tracking */
53      final InputLocation importedFrom;
54  
55      /**
56        * Constructor for this class, to be called from its subclasses and {@link Builder}.
57        * @see Builder#build()
58        */
59      protected Site(Builder builder) {
60          this.id = builder.id != null ? builder.id : (builder.base != null ? builder.base.id : null);
61          this.name = builder.name != null ? builder.name : (builder.base != null ? builder.base.name : null);
62          this.url = builder.url != null ? builder.url : (builder.base != null ? builder.base.url : null);
63          this.childSiteUrlInheritAppendPath = builder.childSiteUrlInheritAppendPath != null ? builder.childSiteUrlInheritAppendPath : (builder.base != null ? builder.base.childSiteUrlInheritAppendPath : null);
64          Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
65          Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
66          Map<Object, InputLocation> mutableLocations = new HashMap<>();
67          this.importedFrom = builder.importedFrom;
68          mutableLocations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
69          mutableLocations.put("id", newlocs.containsKey("id") ? newlocs.get("id") : oldlocs.get("id"));
70          mutableLocations.put("name", newlocs.containsKey("name") ? newlocs.get("name") : oldlocs.get("name"));
71          mutableLocations.put("url", newlocs.containsKey("url") ? newlocs.get("url") : oldlocs.get("url"));
72          mutableLocations.put("childSiteUrlInheritAppendPath", newlocs.containsKey("childSiteUrlInheritAppendPath") ? newlocs.get("childSiteUrlInheritAppendPath") : oldlocs.get("childSiteUrlInheritAppendPath"));
73          this.locations = Collections.unmodifiableMap(mutableLocations);
74      }
75  
76      /**
77       * A unique identifier for a deployment location. This is used to match the
78       * site to configuration in the {@code settings.xml} file, for example.
79       *
80       * @return a {@code String}
81       */
82      public String getId() {
83          return this.id;
84      }
85  
86      /**
87       * Human readable name of the deployment location.
88       *
89       * @return a {@code String}
90       */
91      public String getName() {
92          return this.name;
93      }
94  
95      /**
96       * The url of the location where website is deployed, in the form {@code protocol://hostname/path}.
97       * <p><b>Default value is</b>: parent value [+ path adjustment] + (artifactId or project.directory property), or just parent value if
98       * site's {@code child.site.url.inherit.append.path="false"}.</p>
99       *
100      * @return a {@code String}
101      */
102     public String getUrl() {
103         return this.url;
104     }
105 
106     /**
107      * When children inherit from distribution management site url, append path or not? Note: While the type
108      * of this field is {@code String} for technical reasons, the semantic type is actually
109      * {@code Boolean}
110      * <p><b>Default value is</b>: {@code true}</p>
111      * @since Maven 3.6.1
112      *
113      * @return a {@code String}
114      */
115     public String getChildSiteUrlInheritAppendPath() {
116         return this.childSiteUrlInheritAppendPath;
117     }
118 
119     /**
120      * Gets the location of the specified field in the input source.
121      */
122     public InputLocation getLocation(Object key) {
123         return locations != null ? locations.get(key) : null;
124     }
125 
126     /**
127     * Gets the keys of the locations of the input source.
128     */
129     public Set<Object> getLocationKeys() {
130         return locations != null ? locations.keySet() : null;
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 
353 
354             
355 
356     public boolean isChildSiteUrlInheritAppendPath() {
357         return (getChildSiteUrlInheritAppendPath() != null) ? Boolean.parseBoolean(getChildSiteUrlInheritAppendPath()) : true;
358     }
359 
360             
361           
362 }