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 org.apache.maven.api.annotations.Experimental;
12  import org.apache.maven.api.annotations.Generated;
13  import org.apache.maven.api.annotations.Immutable;
14  import org.apache.maven.api.annotations.Nonnull;
15  import org.apache.maven.api.annotations.NotThreadSafe;
16  import org.apache.maven.api.annotations.ThreadSafe;
17  
18  /**
19   * Contains the information needed for deploying websites.
20   */
21  @Experimental
22  @Generated @ThreadSafe @Immutable
23  public class Site
24      implements Serializable, InputLocationTracker
25  {
26      /**
27       * A unique identifier for a deployment location. This is used to match the
28       * site to configuration in the {@code settings.xml} file, for example.
29       */
30      final String id;
31      /**
32       * Human readable name of the deployment location.
33       */
34      final String name;
35      /**
36       * The url of the location where website is deployed, in the form {@code protocol://hostname/path}.
37       * <br><b>Default value is</b>: parent value [+ path adjustment] + (artifactId or project.directory property), or just parent value if
38       * site's {@code child.site.url.inherit.append.path="false"}
39       */
40      final String url;
41      /**
42       * When children inherit from distribution management site url, append path or not? Note: While the type
43       * of this field is {@code String} for technical reasons, the semantic type is actually
44       * {@code Boolean}
45       * <br><b>Default value is</b>: {@code true}
46       * <br><b>Since</b>: Maven 3.6.1
47       */
48      final String childSiteUrlInheritAppendPath;
49      /** Locations */
50      final Map<Object, InputLocation> locations;
51  
52      /**
53        * Constructor for this class, package protected.
54        * @see Builder#build()
55        */
56      Site(
57          String id,
58          String name,
59          String url,
60          String childSiteUrlInheritAppendPath,
61          Map<Object, InputLocation> locations
62      ) {
63          this.id = id;
64          this.name = name;
65          this.url = url;
66          this.childSiteUrlInheritAppendPath = childSiteUrlInheritAppendPath;
67          this.locations = ImmutableCollections.copy(locations);
68      }
69  
70      /**
71       * A unique identifier for a deployment location. This is used to match the
72       * site to configuration in the {@code settings.xml} file, for example.
73       *
74       * @return a {@code String}
75       */
76      public String getId() {
77          return this.id;
78      }
79  
80      /**
81       * Human readable name of the deployment location.
82       *
83       * @return a {@code String}
84       */
85      public String getName() {
86          return this.name;
87      }
88  
89      /**
90       * The url of the location where website is deployed, in the form {@code protocol://hostname/path}.
91       * <br><b>Default value is</b>: parent value [+ path adjustment] + (artifactId or project.directory property), or just parent value if
92       * site's {@code child.site.url.inherit.append.path="false"}
93       *
94       * @return a {@code String}
95       */
96      public String getUrl() {
97          return this.url;
98      }
99  
100     /**
101      * When children inherit from distribution management site url, append path or not? Note: While the type
102      * of this field is {@code String} for technical reasons, the semantic type is actually
103      * {@code Boolean}
104      * <br><b>Default value is</b>: {@code true}
105      * <br><b>Since</b>: Maven 3.6.1
106      *
107      * @return a {@code String}
108      */
109     public String getChildSiteUrlInheritAppendPath() {
110         return this.childSiteUrlInheritAppendPath;
111     }
112 
113     /**
114      * Gets the location of the specified field in the input source.
115      */
116     public InputLocation getLocation(Object key) {
117         return locations != null ? locations.get(key) : null;
118     }
119 
120     /**
121      * Creates a new builder with this object as the basis.
122      *
123      * @return a {@code Builder}
124      */
125     @Nonnull
126     public Builder with() {
127         return newBuilder(this);
128     }
129     /**
130      * Creates a new {@code Site} instance using the specified id.
131      *
132      * @param id the new {@code String} to use
133      * @return a {@code Site} with the specified id
134      */
135     @Nonnull
136     public Site withId(String id) {
137         return newBuilder(this, true).id(id).build();
138     }
139     /**
140      * Creates a new {@code Site} instance using the specified name.
141      *
142      * @param name the new {@code String} to use
143      * @return a {@code Site} with the specified name
144      */
145     @Nonnull
146     public Site withName(String name) {
147         return newBuilder(this, true).name(name).build();
148     }
149     /**
150      * Creates a new {@code Site} instance using the specified url.
151      *
152      * @param url the new {@code String} to use
153      * @return a {@code Site} with the specified url
154      */
155     @Nonnull
156     public Site withUrl(String url) {
157         return newBuilder(this, true).url(url).build();
158     }
159     /**
160      * Creates a new {@code Site} instance using the specified childSiteUrlInheritAppendPath.
161      *
162      * @param childSiteUrlInheritAppendPath the new {@code String} to use
163      * @return a {@code Site} with the specified childSiteUrlInheritAppendPath
164      */
165     @Nonnull
166     public Site withChildSiteUrlInheritAppendPath(String childSiteUrlInheritAppendPath) {
167         return newBuilder(this, true).childSiteUrlInheritAppendPath(childSiteUrlInheritAppendPath).build();
168     }
169 
170     /**
171      * Creates a new {@code Site} instance.
172      * Equivalent to {@code newInstance(true)}.
173      * @see #newInstance(boolean)
174      *
175      * @return a new {@code Site}
176      */
177     @Nonnull
178     public static Site newInstance() {
179         return newInstance(true);
180     }
181 
182     /**
183      * Creates a new {@code Site} instance using default values or not.
184      * Equivalent to {@code newBuilder(withDefaults).build()}.
185      *
186      * @param withDefaults the boolean indicating whether default values should be used
187      * @return a new {@code Site}
188      */
189     @Nonnull
190     public static Site newInstance(boolean withDefaults) {
191         return newBuilder(withDefaults).build();
192     }
193 
194     /**
195      * Creates a new {@code Site} builder instance.
196      * Equivalent to {@code newBuilder(true)}.
197      * @see #newBuilder(boolean)
198      *
199      * @return a new {@code Builder}
200      */
201     @Nonnull
202     public static Builder newBuilder() {
203         return newBuilder(true);
204     }
205 
206     /**
207      * Creates a new {@code Site} builder instance using default values or not.
208      *
209      * @param withDefaults the boolean indicating whether default values should be used
210      * @return a new {@code Builder}
211      */
212     @Nonnull
213     public static Builder newBuilder(boolean withDefaults) {
214         return new Builder(withDefaults);
215     }
216 
217     /**
218      * Creates a new {@code Site} builder instance using the specified object as a basis.
219      * Equivalent to {@code newBuilder(from, false)}.
220      *
221      * @param from the {@code Site} instance to use as a basis
222      * @return a new {@code Builder}
223      */
224     @Nonnull
225     public static Builder newBuilder(Site from) {
226         return newBuilder(from, false);
227     }
228 
229     /**
230      * Creates a new {@code Site} builder instance using the specified object as a basis.
231      *
232      * @param from the {@code Site} instance to use as a basis
233      * @param forceCopy the boolean indicating if a copy should be forced
234      * @return a new {@code Builder}
235      */
236     @Nonnull
237     public static Builder newBuilder(Site from, boolean forceCopy) {
238         return new Builder(from, forceCopy);
239     }
240 
241     /**
242      * Builder class used to create Site instances.
243      * @see #with()
244      * @see #newBuilder()
245      */
246     @NotThreadSafe
247     public static class Builder
248     {
249         Site base;
250         String id;
251         String name;
252         String url;
253         String childSiteUrlInheritAppendPath;
254         Map<Object, InputLocation> locations;
255 
256         Builder(boolean withDefaults) {
257             if (withDefaults) {
258             }
259         }
260 
261         Builder(Site base, boolean forceCopy) {
262             if (forceCopy) {
263                 this.id = base.id;
264                 this.name = base.name;
265                 this.url = base.url;
266                 this.childSiteUrlInheritAppendPath = base.childSiteUrlInheritAppendPath;
267                 this.locations = base.locations;
268             } else {
269                 this.base = base;
270             }
271         }
272 
273         @Nonnull
274         public Builder id(String id) {
275             this.id = id;
276             return this;
277         }
278 
279         @Nonnull
280         public Builder name(String name) {
281             this.name = name;
282             return this;
283         }
284 
285         @Nonnull
286         public Builder url(String url) {
287             this.url = url;
288             return this;
289         }
290 
291         @Nonnull
292         public Builder childSiteUrlInheritAppendPath(String childSiteUrlInheritAppendPath) {
293             this.childSiteUrlInheritAppendPath = childSiteUrlInheritAppendPath;
294             return this;
295         }
296 
297 
298         @Nonnull
299         public Builder location(Object key, InputLocation location) {
300             if (location != null) {
301                 if (!(this.locations instanceof HashMap)) {
302                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
303                 }
304                 this.locations.put(key, location);
305             }
306             return this;
307         }
308 
309         @Nonnull
310         public Site build() {
311             if (base != null
312                     && (id == null || id == base.id)
313                     && (name == null || name == base.name)
314                     && (url == null || url == base.url)
315                     && (childSiteUrlInheritAppendPath == null || childSiteUrlInheritAppendPath == base.childSiteUrlInheritAppendPath)
316             ) {
317                 return base;
318             }
319             Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
320             Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
321             Map<Object, InputLocation> locations = new HashMap<>();
322             locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
323             locations.put("id", newlocs.containsKey("id") ? newlocs.get("id") : oldlocs.get("id"));
324             locations.put("name", newlocs.containsKey("name") ? newlocs.get("name") : oldlocs.get("name"));
325             locations.put("url", newlocs.containsKey("url") ? newlocs.get("url") : oldlocs.get("url"));
326             locations.put("childSiteUrlInheritAppendPath", newlocs.containsKey("childSiteUrlInheritAppendPath") ? newlocs.get("childSiteUrlInheritAppendPath") : oldlocs.get("childSiteUrlInheritAppendPath"));
327             return new Site(
328                 id != null ? id : (base != null ? base.id : null),
329                 name != null ? name : (base != null ? base.name : null),
330                 url != null ? url : (base != null ? base.url : null),
331                 childSiteUrlInheritAppendPath != null ? childSiteUrlInheritAppendPath : (base != null ? base.childSiteUrlInheritAppendPath : null),
332                 locations
333             );
334         }
335     }
336 
337 
338             
339 
340     public boolean isChildSiteUrlInheritAppendPath()
341     {
342         return ( getChildSiteUrlInheritAppendPath() != null ) ? Boolean.parseBoolean( getChildSiteUrlInheritAppendPath() ) : true;
343     }
344 
345             
346           
347 }