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      /** Location of the xml element for this object. */
50      final InputLocation location;
51      /** Location of the xml element for the field id. */
52      final InputLocation idLocation;
53      /** Location of the xml element for the field name. */
54      final InputLocation nameLocation;
55      /** Location of the xml element for the field url. */
56      final InputLocation urlLocation;
57      /** Location of the xml element for the field childSiteUrlInheritAppendPath. */
58      final InputLocation childSiteUrlInheritAppendPathLocation;
59      /** Other locations */
60      final Map<Object, InputLocation> locations;
61  
62      /**
63        * Constructor for this class, package protected.
64        * @see Builder#build()
65        */
66      Site(
67          String id,
68          String name,
69          String url,
70          String childSiteUrlInheritAppendPath,
71          Map<Object, InputLocation> locations,
72          InputLocation location,
73          InputLocation idLocation,
74          InputLocation nameLocation,
75          InputLocation urlLocation,
76          InputLocation childSiteUrlInheritAppendPathLocation
77      )
78      {
79          this.id = id;
80          this.name = name;
81          this.url = url;
82          this.childSiteUrlInheritAppendPath = childSiteUrlInheritAppendPath;
83          this.locations = ImmutableCollections.copy( locations );
84          this.location = location;
85          this.idLocation = idLocation;
86          this.nameLocation = nameLocation;
87          this.urlLocation = urlLocation;
88          this.childSiteUrlInheritAppendPathLocation = childSiteUrlInheritAppendPathLocation;
89      }
90  
91      /**
92       * A unique identifier for a deployment location. This is used to match the
93       * site to configuration in the {@code settings.xml} file, for example.
94       *
95       * @return a {@code String}
96       */
97      public String getId()
98      {
99          return this.id;
100     }
101 
102     /**
103      * Human readable name of the deployment location.
104      *
105      * @return a {@code String}
106      */
107     public String getName()
108     {
109         return this.name;
110     }
111 
112     /**
113      * The url of the location where website is deployed, in the form {@code protocol://hostname/path}.
114      * <br><b>Default value is</b>: parent value [+ path adjustment] + (artifactId or project.directory property), or just parent value if
115      * site's {@code child.site.url.inherit.append.path="false"}
116      *
117      * @return a {@code String}
118      */
119     public String getUrl()
120     {
121         return this.url;
122     }
123 
124     /**
125      * When children inherit from distribution management site url, append path or not? Note: While the type
126      * of this field is {@code String} for technical reasons, the semantic type is actually
127      * {@code Boolean}
128      * <br><b>Default value is</b>: {@code true}
129      * <br><b>Since</b>: Maven 3.6.1
130      *
131      * @return a {@code String}
132      */
133     public String getChildSiteUrlInheritAppendPath()
134     {
135         return this.childSiteUrlInheritAppendPath;
136     }
137 
138     /**
139      * Gets the location of the specified field in the input source.
140      */
141     public InputLocation getLocation( Object key )
142     {
143         if ( key instanceof String )
144         {
145             switch ( ( String ) key )
146             {
147                 case "":
148                     return location;
149                 case "id":
150                     return idLocation;
151                 case "name":
152                     return nameLocation;
153                 case "url":
154                     return urlLocation;
155                 case "childSiteUrlInheritAppendPath":
156                     return childSiteUrlInheritAppendPathLocation;
157             }
158         }
159         return locations != null ? locations.get( key ) : null;
160     }
161 
162     /**
163      * Creates a new builder with this object as the basis.
164      *
165      * @return a {@code Builder}
166      */
167     @Nonnull
168     public Builder with()
169     {
170         return newBuilder( this );
171     }
172     /**
173      * Creates a new {@code Site} instance using the specified id.
174      *
175      * @param id the new {@code String} to use
176      * @return a {@code Site} with the specified id
177      */
178     @Nonnull
179     public Site withId( String id )
180     {
181         return with().id( id ).build();
182     }
183     /**
184      * Creates a new {@code Site} instance using the specified name.
185      *
186      * @param name the new {@code String} to use
187      * @return a {@code Site} with the specified name
188      */
189     @Nonnull
190     public Site withName( String name )
191     {
192         return with().name( name ).build();
193     }
194     /**
195      * Creates a new {@code Site} instance using the specified url.
196      *
197      * @param url the new {@code String} to use
198      * @return a {@code Site} with the specified url
199      */
200     @Nonnull
201     public Site withUrl( String url )
202     {
203         return with().url( url ).build();
204     }
205     /**
206      * Creates a new {@code Site} instance using the specified childSiteUrlInheritAppendPath.
207      *
208      * @param childSiteUrlInheritAppendPath the new {@code String} to use
209      * @return a {@code Site} with the specified childSiteUrlInheritAppendPath
210      */
211     @Nonnull
212     public Site withChildSiteUrlInheritAppendPath( String childSiteUrlInheritAppendPath )
213     {
214         return with().childSiteUrlInheritAppendPath( childSiteUrlInheritAppendPath ).build();
215     }
216 
217     /**
218      * Creates a new {@code Site} instance.
219      * Equivalent to {@code newInstance( true )}.
220      * @see #newInstance(boolean)
221      *
222      * @return a new {@code Site}
223      */
224     @Nonnull
225     public static Site newInstance()
226     {
227         return newInstance( true );
228     }
229 
230     /**
231      * Creates a new {@code Site} instance using default values or not.
232      * Equivalent to {@code newBuilder( withDefaults ).build()}.
233      *
234      * @param withDefaults the boolean indicating whether default values should be used
235      * @return a new {@code Site}
236      */
237     @Nonnull
238     public static Site newInstance( boolean withDefaults )
239     {
240         return newBuilder( withDefaults ).build();
241     }
242 
243     /**
244      * Creates a new {@code Site} builder instance.
245      * Equivalent to {@code newBuilder( true )}.
246      * @see #newBuilder(boolean)
247      *
248      * @return a new {@code Builder}
249      */
250     @Nonnull
251     public static Builder newBuilder()
252     {
253         return newBuilder( true );
254     }
255 
256     /**
257      * Creates a new {@code Site} builder instance using default values or not.
258      *
259      * @param withDefaults the boolean indicating whether default values should be used
260      * @return a new {@code Builder}
261      */
262     @Nonnull
263     public static Builder newBuilder( boolean withDefaults )
264     {
265         return new Builder( withDefaults );
266     }
267 
268     /**
269      * Creates a new {@code Site} builder instance using the specified object as a basis.
270      * Equivalent to {@code newBuilder( from, false )}.
271      *
272      * @param from the {@code Site} instance to use as a basis
273      * @return a new {@code Builder}
274      */
275     @Nonnull
276     public static Builder newBuilder( Site from )
277     {
278         return newBuilder( from, false );
279     }
280 
281     /**
282      * Creates a new {@code Site} builder instance using the specified object as a basis.
283      *
284      * @param from the {@code Site} instance to use as a basis
285      * @param forceCopy the boolean indicating if a copy should be forced
286      * @return a new {@code Builder}
287      */
288     @Nonnull
289     public static Builder newBuilder( Site from, boolean forceCopy )
290     {
291         return new Builder( from, forceCopy );
292     }
293 
294     /**
295      * Builder class used to create Site instances.
296      * @see #with()
297      * @see #newBuilder()
298      */
299     @NotThreadSafe
300     public static class Builder
301     {
302         Site base;
303         String id;
304         String name;
305         String url;
306         String childSiteUrlInheritAppendPath;
307         Map<Object, InputLocation> locations;
308 
309         Builder( boolean withDefaults )
310         {
311             if ( withDefaults )
312             {
313             }
314         }
315 
316         Builder( Site base, boolean forceCopy )
317         {
318             if ( forceCopy )
319             {
320                 this.id = base.id;
321                 this.name = base.name;
322                 this.url = base.url;
323                 this.childSiteUrlInheritAppendPath = base.childSiteUrlInheritAppendPath;
324             }
325             else
326             {
327                 this.base = base;
328             }
329         }
330 
331         @Nonnull
332         public Builder id( String id )
333         {
334             this.id = id;
335             return this;
336         }
337 
338         @Nonnull
339         public Builder name( String name )
340         {
341             this.name = name;
342             return this;
343         }
344 
345         @Nonnull
346         public Builder url( String url )
347         {
348             this.url = url;
349             return this;
350         }
351 
352         @Nonnull
353         public Builder childSiteUrlInheritAppendPath( String childSiteUrlInheritAppendPath )
354         {
355             this.childSiteUrlInheritAppendPath = childSiteUrlInheritAppendPath;
356             return this;
357         }
358 
359 
360         @Nonnull
361         public Builder location( Object key, InputLocation location )
362         {
363             if ( location != null )
364             {
365                 if ( this.locations == null )
366                 {
367                     this.locations = new HashMap<>();
368                 }
369                 this.locations.put( key, location );
370             }
371             return this;
372         }
373 
374         @Nonnull
375         public Site build()
376         {
377             if ( base != null
378                     && ( id == null || id == base.id )
379                     && ( name == null || name == base.name )
380                     && ( url == null || url == base.url )
381                     && ( childSiteUrlInheritAppendPath == null || childSiteUrlInheritAppendPath == base.childSiteUrlInheritAppendPath )
382             )
383             {
384                 return base;
385             }
386             Map<Object, InputLocation> locations = null;
387             InputLocation location = null;
388             InputLocation idLocation = null;
389             InputLocation nameLocation = null;
390             InputLocation urlLocation = null;
391             InputLocation childSiteUrlInheritAppendPathLocation = null;
392             if ( this.locations != null )
393             {
394                 locations = this.locations;
395                 location = locations.remove( "" );
396                 idLocation = locations.remove( "id" );
397                 nameLocation = locations.remove( "name" );
398                 urlLocation = locations.remove( "url" );
399                 childSiteUrlInheritAppendPathLocation = locations.remove( "childSiteUrlInheritAppendPath" );
400             }
401             return new Site(
402                 id != null ? id : ( base != null ? base.id : null ),
403                 name != null ? name : ( base != null ? base.name : null ),
404                 url != null ? url : ( base != null ? base.url : null ),
405                 childSiteUrlInheritAppendPath != null ? childSiteUrlInheritAppendPath : ( base != null ? base.childSiteUrlInheritAppendPath : null ),
406                 locations != null ? locations : ( base != null ? base.locations : null ),
407                 location != null ? location : ( base != null ? base.location : null ),
408                 idLocation != null ? idLocation : ( base != null ? base.idLocation : null ),
409                 nameLocation != null ? nameLocation : ( base != null ? base.nameLocation : null ),
410                 urlLocation != null ? urlLocation : ( base != null ? base.urlLocation : null ),
411                 childSiteUrlInheritAppendPathLocation != null ? childSiteUrlInheritAppendPathLocation : ( base != null ? base.childSiteUrlInheritAppendPathLocation : null )
412             );
413         }
414     }
415 
416 
417             
418 
419     public boolean isChildSiteUrlInheritAppendPath()
420     {
421         return ( getChildSiteUrlInheritAppendPath() != null ) ? Boolean.parseBoolean( getChildSiteUrlInheritAppendPath() ) : true;
422     }
423 
424             
425           
426 }