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