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