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