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 RepositoryBase
26      implements Serializable, InputLocationTracker
27  {
28      /**
29       * A unique identifier for a repository. This is used to match the repository
30       * to configuration in the {@code settings.xml} file, for example. Furthermore, the identifier is
31       * used during POM inheritance and profile injection to detect repositories that should be merged.
32       */
33      final String id;
34      /**
35       * Human readable name of the repository.
36       */
37      final String name;
38      /**
39       * The url of the repository, in the form {@code protocol://hostname/path}.
40       */
41      final String url;
42      /**
43       * The type of layout this repository uses for locating and storing artifacts -
44       * can be {@code legacy} or {@code default}.
45       */
46      final String layout;
47      /** Location of the xml element for this object. */
48      final InputLocation location;
49      /** Location of the xml element for the field id. */
50      final InputLocation idLocation;
51      /** Location of the xml element for the field name. */
52      final InputLocation nameLocation;
53      /** Location of the xml element for the field url. */
54      final InputLocation urlLocation;
55      /** Location of the xml element for the field layout. */
56      final InputLocation layoutLocation;
57      /** Other locations */
58      final Map<Object, InputLocation> locations;
59  
60      /**
61        * Constructor for this class, package protected.
62        * @see Builder#build()
63        */
64      RepositoryBase(
65          String id,
66          String name,
67          String url,
68          String layout,
69          Map<Object, InputLocation> locations,
70          InputLocation location,
71          InputLocation idLocation,
72          InputLocation nameLocation,
73          InputLocation urlLocation,
74          InputLocation layoutLocation
75      )
76      {
77          this.id = id;
78          this.name = name;
79          this.url = url;
80          this.layout = layout;
81          this.locations = ImmutableCollections.copy( locations );
82          this.location = location;
83          this.idLocation = idLocation;
84          this.nameLocation = nameLocation;
85          this.urlLocation = urlLocation;
86          this.layoutLocation = layoutLocation;
87      }
88  
89      @Override
90      public boolean equals( Object o )
91      {
92          if ( this == o )
93          {
94              return true;
95          }
96          if ( o == null || !( o instanceof RepositoryBase ) )
97          {
98              return false;
99          }
100         RepositoryBase that = ( RepositoryBase ) o;
101         return Objects.equals( this.id, that.id );
102     }
103 
104     @Override
105     public int hashCode()
106     {
107         return Objects.hash( id );
108     }
109 
110     /**
111      * A unique identifier for a repository. This is used to match the repository
112      * to configuration in the {@code settings.xml} file, for example. Furthermore, the identifier is
113      * used during POM inheritance and profile injection to detect repositories that should be merged.
114      *
115      * @return a {@code String}
116      */
117     public String getId()
118     {
119         return this.id;
120     }
121 
122     /**
123      * Human readable name of the repository.
124      *
125      * @return a {@code String}
126      */
127     public String getName()
128     {
129         return this.name;
130     }
131 
132     /**
133      * The url of the repository, in the form {@code protocol://hostname/path}.
134      *
135      * @return a {@code String}
136      */
137     public String getUrl()
138     {
139         return this.url;
140     }
141 
142     /**
143      * The type of layout this repository uses for locating and storing artifacts -
144      * can be {@code legacy} or {@code default}.
145      *
146      * @return a {@code String}
147      */
148     public String getLayout()
149     {
150         return this.layout;
151     }
152 
153     /**
154      * Gets the location of the specified field in the input source.
155      */
156     public InputLocation getLocation( Object key )
157     {
158         if ( key instanceof String )
159         {
160             switch ( ( String ) key )
161             {
162                 case "":
163                     return location;
164                 case "id":
165                     return idLocation;
166                 case "name":
167                     return nameLocation;
168                 case "url":
169                     return urlLocation;
170                 case "layout":
171                     return layoutLocation;
172             }
173         }
174         return locations != null ? locations.get( key ) : null;
175     }
176 
177     /**
178      * Creates a new builder with this object as the basis.
179      *
180      * @return a {@code Builder}
181      */
182     @Nonnull
183     public Builder with()
184     {
185         return newBuilder( this );
186     }
187     /**
188      * Creates a new {@code RepositoryBase} instance using the specified id.
189      *
190      * @param id the new {@code String} to use
191      * @return a {@code RepositoryBase} with the specified id
192      */
193     @Nonnull
194     public RepositoryBase withId( String id )
195     {
196         return with().id( id ).build();
197     }
198     /**
199      * Creates a new {@code RepositoryBase} instance using the specified name.
200      *
201      * @param name the new {@code String} to use
202      * @return a {@code RepositoryBase} with the specified name
203      */
204     @Nonnull
205     public RepositoryBase withName( String name )
206     {
207         return with().name( name ).build();
208     }
209     /**
210      * Creates a new {@code RepositoryBase} instance using the specified url.
211      *
212      * @param url the new {@code String} to use
213      * @return a {@code RepositoryBase} with the specified url
214      */
215     @Nonnull
216     public RepositoryBase withUrl( String url )
217     {
218         return with().url( url ).build();
219     }
220     /**
221      * Creates a new {@code RepositoryBase} instance using the specified layout.
222      *
223      * @param layout the new {@code String} to use
224      * @return a {@code RepositoryBase} with the specified layout
225      */
226     @Nonnull
227     public RepositoryBase withLayout( String layout )
228     {
229         return with().layout( layout ).build();
230     }
231 
232     /**
233      * Creates a new {@code RepositoryBase} instance.
234      * Equivalent to {@code newInstance( true )}.
235      * @see #newInstance(boolean)
236      *
237      * @return a new {@code RepositoryBase}
238      */
239     @Nonnull
240     public static RepositoryBase newInstance()
241     {
242         return newInstance( true );
243     }
244 
245     /**
246      * Creates a new {@code RepositoryBase} instance using default values or not.
247      * Equivalent to {@code newBuilder( withDefaults ).build()}.
248      *
249      * @param withDefaults the boolean indicating whether default values should be used
250      * @return a new {@code RepositoryBase}
251      */
252     @Nonnull
253     public static RepositoryBase newInstance( boolean withDefaults )
254     {
255         return newBuilder( withDefaults ).build();
256     }
257 
258     /**
259      * Creates a new {@code RepositoryBase} builder instance.
260      * Equivalent to {@code newBuilder( true )}.
261      * @see #newBuilder(boolean)
262      *
263      * @return a new {@code Builder}
264      */
265     @Nonnull
266     public static Builder newBuilder()
267     {
268         return newBuilder( true );
269     }
270 
271     /**
272      * Creates a new {@code RepositoryBase} builder instance using default values or not.
273      *
274      * @param withDefaults the boolean indicating whether default values should be used
275      * @return a new {@code Builder}
276      */
277     @Nonnull
278     public static Builder newBuilder( boolean withDefaults )
279     {
280         return new Builder( withDefaults );
281     }
282 
283     /**
284      * Creates a new {@code RepositoryBase} builder instance using the specified object as a basis.
285      * Equivalent to {@code newBuilder( from, false )}.
286      *
287      * @param from the {@code RepositoryBase} instance to use as a basis
288      * @return a new {@code Builder}
289      */
290     @Nonnull
291     public static Builder newBuilder( RepositoryBase from )
292     {
293         return newBuilder( from, false );
294     }
295 
296     /**
297      * Creates a new {@code RepositoryBase} builder instance using the specified object as a basis.
298      *
299      * @param from the {@code RepositoryBase} instance to use as a basis
300      * @param forceCopy the boolean indicating if a copy should be forced
301      * @return a new {@code Builder}
302      */
303     @Nonnull
304     public static Builder newBuilder( RepositoryBase from, boolean forceCopy )
305     {
306         return new Builder( from, forceCopy );
307     }
308 
309     /**
310      * Builder class used to create RepositoryBase instances.
311      * @see #with()
312      * @see #newBuilder()
313      */
314     @NotThreadSafe
315     public static class Builder
316     {
317         RepositoryBase base;
318         String id;
319         String name;
320         String url;
321         String layout;
322         Map<Object, InputLocation> locations;
323 
324         Builder( boolean withDefaults )
325         {
326             if ( withDefaults )
327             {
328                 this.layout = "default";
329             }
330         }
331 
332         Builder( RepositoryBase base, boolean forceCopy )
333         {
334             if ( forceCopy )
335             {
336                 this.id = base.id;
337                 this.name = base.name;
338                 this.url = base.url;
339                 this.layout = base.layout;
340             }
341             else
342             {
343                 this.base = base;
344             }
345         }
346 
347         @Nonnull
348         public Builder id( String id )
349         {
350             this.id = id;
351             return this;
352         }
353 
354         @Nonnull
355         public Builder name( String name )
356         {
357             this.name = name;
358             return this;
359         }
360 
361         @Nonnull
362         public Builder url( String url )
363         {
364             this.url = url;
365             return this;
366         }
367 
368         @Nonnull
369         public Builder layout( String layout )
370         {
371             this.layout = layout;
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 RepositoryBase 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             )
399             {
400                 return base;
401             }
402             Map<Object, InputLocation> locations = null;
403             InputLocation location = null;
404             InputLocation idLocation = null;
405             InputLocation nameLocation = null;
406             InputLocation urlLocation = null;
407             InputLocation layoutLocation = 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             }
417             return new RepositoryBase(
418                 id != null ? id : ( base != null ? base.id : null ),
419                 name != null ? name : ( base != null ? base.name : null ),
420                 url != null ? url : ( base != null ? base.url : null ),
421                 layout != null ? layout : ( base != null ? base.layout : null ),
422                 locations != null ? locations : ( base != null ? base.locations : null ),
423                 location != null ? location : ( base != null ? base.location : null ),
424                 idLocation != null ? idLocation : ( base != null ? base.idLocation : null ),
425                 nameLocation != null ? nameLocation : ( base != null ? base.nameLocation : null ),
426                 urlLocation != null ? urlLocation : ( base != null ? base.urlLocation : null ),
427                 layoutLocation != null ? layoutLocation : ( base != null ? base.layoutLocation : null )
428             );
429         }
430     }
431 
432 }