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