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 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   * Deployment repository contains the information needed for deploying to the remote
21   * repository, which adds uniqueVersion property to usual repositories for download.
22   */
23  @Experimental
24  @Generated @ThreadSafe @Immutable
25  public class DeploymentRepository
26      extends Repository
27      implements Serializable, InputLocationTracker
28  {
29      /**
30       * Whether to assign snapshots a unique version comprised of the timestamp and
31       * build number, or to use the same version each time
32       */
33      final boolean uniqueVersion;
34      /** Location of the xml element for the field uniqueVersion. */
35      final InputLocation uniqueVersionLocation;
36  
37      /**
38        * Constructor for this class, package protected.
39        * @see Builder#build()
40        */
41      DeploymentRepository(
42          String id,
43          String name,
44          String url,
45          String layout,
46          RepositoryPolicy releases,
47          RepositoryPolicy snapshots,
48          boolean uniqueVersion,
49          Map<Object, InputLocation> locations,
50          InputLocation location,
51          InputLocation idLocation,
52          InputLocation nameLocation,
53          InputLocation urlLocation,
54          InputLocation layoutLocation,
55          InputLocation releasesLocation,
56          InputLocation snapshotsLocation,
57          InputLocation uniqueVersionLocation
58      )
59      {
60          super(
61              id,
62              name,
63              url,
64              layout,
65              releases,
66              snapshots,
67              locations,
68              location,
69              idLocation,
70              nameLocation,
71              urlLocation,
72              layoutLocation,
73              releasesLocation,
74              snapshotsLocation
75          );
76          this.uniqueVersion = uniqueVersion;
77          this.uniqueVersionLocation = uniqueVersionLocation;
78      }
79  
80      @Override
81      public boolean equals( Object o )
82      {
83          if ( this == o )
84          {
85              return true;
86          }
87          if ( o == null || !( o instanceof DeploymentRepository ) )
88          {
89              return false;
90          }
91          DeploymentRepository that = ( DeploymentRepository ) o;
92          return Objects.equals( this.id, that.id );
93      }
94  
95      @Override
96      public int hashCode()
97      {
98          return Objects.hash( id );
99      }
100 
101     /**
102      * Whether to assign snapshots a unique version comprised of the timestamp and
103      * build number, or to use the same version each time
104      *
105      * @return a {@code boolean}
106      */
107     public boolean isUniqueVersion()
108     {
109         return this.uniqueVersion;
110     }
111 
112     /**
113      * Gets the location of the specified field in the input source.
114      */
115     public InputLocation getLocation( Object key )
116     {
117         if ( key instanceof String )
118         {
119             switch ( ( String ) key )
120             {
121                 case "uniqueVersion":
122                     return uniqueVersionLocation;
123             }
124         }
125         return super.getLocation( key );
126     }
127 
128     /**
129      * Creates a new builder with this object as the basis.
130      *
131      * @return a {@code Builder}
132      */
133     @Nonnull
134     public Builder with()
135     {
136         return newBuilder( this );
137     }
138     /**
139      * Creates a new {@code DeploymentRepository} instance using the specified id.
140      *
141      * @param id the new {@code String} to use
142      * @return a {@code DeploymentRepository} with the specified id
143      */
144     @Nonnull
145     public DeploymentRepository withId( String id )
146     {
147         return with().id( id ).build();
148     }
149     /**
150      * Creates a new {@code DeploymentRepository} instance using the specified name.
151      *
152      * @param name the new {@code String} to use
153      * @return a {@code DeploymentRepository} with the specified name
154      */
155     @Nonnull
156     public DeploymentRepository withName( String name )
157     {
158         return with().name( name ).build();
159     }
160     /**
161      * Creates a new {@code DeploymentRepository} instance using the specified url.
162      *
163      * @param url the new {@code String} to use
164      * @return a {@code DeploymentRepository} with the specified url
165      */
166     @Nonnull
167     public DeploymentRepository withUrl( String url )
168     {
169         return with().url( url ).build();
170     }
171     /**
172      * Creates a new {@code DeploymentRepository} instance using the specified layout.
173      *
174      * @param layout the new {@code String} to use
175      * @return a {@code DeploymentRepository} with the specified layout
176      */
177     @Nonnull
178     public DeploymentRepository withLayout( String layout )
179     {
180         return with().layout( layout ).build();
181     }
182     /**
183      * Creates a new {@code DeploymentRepository} instance using the specified releases.
184      *
185      * @param releases the new {@code RepositoryPolicy} to use
186      * @return a {@code DeploymentRepository} with the specified releases
187      */
188     @Nonnull
189     public DeploymentRepository withReleases( RepositoryPolicy releases )
190     {
191         return with().releases( releases ).build();
192     }
193     /**
194      * Creates a new {@code DeploymentRepository} instance using the specified snapshots.
195      *
196      * @param snapshots the new {@code RepositoryPolicy} to use
197      * @return a {@code DeploymentRepository} with the specified snapshots
198      */
199     @Nonnull
200     public DeploymentRepository withSnapshots( RepositoryPolicy snapshots )
201     {
202         return with().snapshots( snapshots ).build();
203     }
204     /**
205      * Creates a new {@code DeploymentRepository} instance using the specified uniqueVersion.
206      *
207      * @param uniqueVersion the new {@code boolean} to use
208      * @return a {@code DeploymentRepository} with the specified uniqueVersion
209      */
210     @Nonnull
211     public DeploymentRepository withUniqueVersion( boolean uniqueVersion )
212     {
213         return with().uniqueVersion( uniqueVersion ).build();
214     }
215 
216     /**
217      * Creates a new {@code DeploymentRepository} instance.
218      * Equivalent to {@code newInstance( true )}.
219      * @see #newInstance(boolean)
220      *
221      * @return a new {@code DeploymentRepository}
222      */
223     @Nonnull
224     public static DeploymentRepository newInstance()
225     {
226         return newInstance( true );
227     }
228 
229     /**
230      * Creates a new {@code DeploymentRepository} instance using default values or not.
231      * Equivalent to {@code newBuilder( withDefaults ).build()}.
232      *
233      * @param withDefaults the boolean indicating whether default values should be used
234      * @return a new {@code DeploymentRepository}
235      */
236     @Nonnull
237     public static DeploymentRepository newInstance( boolean withDefaults )
238     {
239         return newBuilder( withDefaults ).build();
240     }
241 
242     /**
243      * Creates a new {@code DeploymentRepository} builder instance.
244      * Equivalent to {@code newBuilder( true )}.
245      * @see #newBuilder(boolean)
246      *
247      * @return a new {@code Builder}
248      */
249     @Nonnull
250     public static Builder newBuilder()
251     {
252         return newBuilder( true );
253     }
254 
255     /**
256      * Creates a new {@code DeploymentRepository} builder instance using default values or not.
257      *
258      * @param withDefaults the boolean indicating whether default values should be used
259      * @return a new {@code Builder}
260      */
261     @Nonnull
262     public static Builder newBuilder( boolean withDefaults )
263     {
264         return new Builder( withDefaults );
265     }
266 
267     /**
268      * Creates a new {@code DeploymentRepository} builder instance using the specified object as a basis.
269      * Equivalent to {@code newBuilder( from, false )}.
270      *
271      * @param from the {@code DeploymentRepository} instance to use as a basis
272      * @return a new {@code Builder}
273      */
274     @Nonnull
275     public static Builder newBuilder( DeploymentRepository from )
276     {
277         return newBuilder( from, false );
278     }
279 
280     /**
281      * Creates a new {@code DeploymentRepository} builder instance using the specified object as a basis.
282      *
283      * @param from the {@code DeploymentRepository} instance to use as a basis
284      * @param forceCopy the boolean indicating if a copy should be forced
285      * @return a new {@code Builder}
286      */
287     @Nonnull
288     public static Builder newBuilder( DeploymentRepository from, boolean forceCopy )
289     {
290         return new Builder( from, forceCopy );
291     }
292 
293     /**
294      * Builder class used to create DeploymentRepository instances.
295      * @see #with()
296      * @see #newBuilder()
297      */
298     @NotThreadSafe
299     public static class Builder
300         extends Repository.Builder
301     {
302         DeploymentRepository base;
303         Boolean uniqueVersion;
304 
305         Builder( boolean withDefaults )
306         {
307             super( withDefaults );
308             if ( withDefaults )
309             {
310                 this.uniqueVersion = true;
311             }
312         }
313 
314         Builder( DeploymentRepository base, boolean forceCopy )
315         {
316             super( base, forceCopy );
317             if ( forceCopy )
318             {
319                 this.uniqueVersion = base.uniqueVersion;
320             }
321             else
322             {
323                 this.base = base;
324             }
325         }
326 
327         @Nonnull
328         public Builder id( String id )
329         {
330             this.id = id;
331             return this;
332         }
333 
334         @Nonnull
335         public Builder name( String name )
336         {
337             this.name = name;
338             return this;
339         }
340 
341         @Nonnull
342         public Builder url( String url )
343         {
344             this.url = url;
345             return this;
346         }
347 
348         @Nonnull
349         public Builder layout( String layout )
350         {
351             this.layout = layout;
352             return this;
353         }
354 
355         @Nonnull
356         public Builder releases( RepositoryPolicy releases )
357         {
358             this.releases = releases;
359             return this;
360         }
361 
362         @Nonnull
363         public Builder snapshots( RepositoryPolicy snapshots )
364         {
365             this.snapshots = snapshots;
366             return this;
367         }
368 
369         @Nonnull
370         public Builder uniqueVersion( boolean uniqueVersion )
371         {
372             this.uniqueVersion = uniqueVersion;
373             return this;
374         }
375 
376 
377         @Nonnull
378         public Builder location( Object key, InputLocation location )
379         {
380             if ( location != null )
381             {
382                 if ( this.locations == null )
383                 {
384                     this.locations = new HashMap<>();
385                 }
386                 this.locations.put( key, location );
387             }
388             return this;
389         }
390 
391         @Nonnull
392         public DeploymentRepository build()
393         {
394             if ( base != null
395                     && ( id == null || id == base.id )
396                     && ( name == null || name == base.name )
397                     && ( url == null || url == base.url )
398                     && ( layout == null || layout == base.layout )
399                     && ( releases == null || releases == base.releases )
400                     && ( snapshots == null || snapshots == base.snapshots )
401                     && ( uniqueVersion == null || uniqueVersion == base.uniqueVersion )
402             )
403             {
404                 return base;
405             }
406             Map<Object, InputLocation> locations = null;
407             InputLocation location = null;
408             InputLocation idLocation = null;
409             InputLocation nameLocation = null;
410             InputLocation urlLocation = null;
411             InputLocation layoutLocation = null;
412             InputLocation releasesLocation = null;
413             InputLocation snapshotsLocation = null;
414             InputLocation uniqueVersionLocation = null;
415             if ( this.locations != null )
416             {
417                 locations = this.locations;
418                 location = locations.remove( "" );
419                 idLocation = locations.remove( "id" );
420                 nameLocation = locations.remove( "name" );
421                 urlLocation = locations.remove( "url" );
422                 layoutLocation = locations.remove( "layout" );
423                 releasesLocation = locations.remove( "releases" );
424                 snapshotsLocation = locations.remove( "snapshots" );
425                 uniqueVersionLocation = locations.remove( "uniqueVersion" );
426             }
427             return new DeploymentRepository(
428                 id != null ? id : ( base != null ? base.id : null ),
429                 name != null ? name : ( base != null ? base.name : null ),
430                 url != null ? url : ( base != null ? base.url : null ),
431                 layout != null ? layout : ( base != null ? base.layout : null ),
432                 releases != null ? releases : ( base != null ? base.releases : null ),
433                 snapshots != null ? snapshots : ( base != null ? base.snapshots : null ),
434                 uniqueVersion != null ? uniqueVersion : ( base != null ? base.uniqueVersion : true ),
435                 locations != null ? locations : ( base != null ? base.locations : null ),
436                 location != null ? location : ( base != null ? base.location : null ),
437                 idLocation != null ? idLocation : ( base != null ? base.idLocation : null ),
438                 nameLocation != null ? nameLocation : ( base != null ? base.nameLocation : null ),
439                 urlLocation != null ? urlLocation : ( base != null ? base.urlLocation : null ),
440                 layoutLocation != null ? layoutLocation : ( base != null ? base.layoutLocation : null ),
441                 releasesLocation != null ? releasesLocation : ( base != null ? base.releasesLocation : null ),
442                 snapshotsLocation != null ? snapshotsLocation : ( base != null ? base.snapshotsLocation : null ),
443                 uniqueVersionLocation != null ? uniqueVersionLocation : ( base != null ? base.uniqueVersionLocation : null )
444             );
445         }
446     }
447 
448 }