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.settings;
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.Set;
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   * Repository contains the information needed for establishing
21   * connections with 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      /** Locations (this potentially hides the same name field from the super class) */
38      final Map<Object, InputLocation> locations;
39  
40      /**
41        * Constructor for this class, to be called from its subclasses and {@link Builder}.
42        * @see Builder#build()
43        */
44      protected Repository(Builder builder) {
45          super(builder);
46          this.releases = builder.releases != null ? builder.releases : (builder.base != null ? builder.base.releases : null);
47          this.snapshots = builder.snapshots != null ? builder.snapshots : (builder.base != null ? builder.base.snapshots : null);
48          Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
49          Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
50          Map<Object, InputLocation> mutableLocations = new HashMap<>(super.locations);
51          mutableLocations.put("releases", newlocs.containsKey("releases") ? newlocs.get("releases") : oldlocs.get("releases"));
52          mutableLocations.put("snapshots", newlocs.containsKey("snapshots") ? newlocs.get("snapshots") : oldlocs.get("snapshots"));
53          this.locations = Collections.unmodifiableMap(mutableLocations);
54      }
55  
56      /**
57       * How to handle downloading of releases from this repository
58       *
59       * @return a {@code RepositoryPolicy}
60       */
61      public RepositoryPolicy getReleases() {
62          return this.releases;
63      }
64  
65      /**
66       * How to handle downloading of snapshots from this repository
67       *
68       * @return a {@code RepositoryPolicy}
69       */
70      public RepositoryPolicy getSnapshots() {
71          return this.snapshots;
72      }
73  
74      /**
75       * Gets the location of the specified field in the input source.
76       */
77      public InputLocation getLocation(Object key) {
78          return locations != null ? locations.get(key) : null;
79      }
80  
81      /**
82      * Gets the keys of the locations of the input source.
83      */
84      public Set<Object> getLocationKeys() {
85          return locations != null ? locations.keySet() : null;
86      }
87  
88      /**
89       * Creates a new builder with this object as the basis.
90       *
91       * @return a {@code Builder}
92       */
93      @Nonnull
94      public Builder with() {
95          return newBuilder(this);
96      }
97      /**
98       * Creates a new {@code Repository} instance using the specified id.
99       *
100      * @param id the new {@code String} to use
101      * @return a {@code Repository} with the specified id
102      */
103     @Nonnull
104     public Repository withId(String id) {
105         return newBuilder(this, true).id(id).build();
106     }
107     /**
108      * Creates a new {@code Repository} instance using the specified name.
109      *
110      * @param name the new {@code String} to use
111      * @return a {@code Repository} with the specified name
112      */
113     @Nonnull
114     public Repository withName(String name) {
115         return newBuilder(this, true).name(name).build();
116     }
117     /**
118      * Creates a new {@code Repository} instance using the specified url.
119      *
120      * @param url the new {@code String} to use
121      * @return a {@code Repository} with the specified url
122      */
123     @Nonnull
124     public Repository withUrl(String url) {
125         return newBuilder(this, true).url(url).build();
126     }
127     /**
128      * Creates a new {@code Repository} instance using the specified layout.
129      *
130      * @param layout the new {@code String} to use
131      * @return a {@code Repository} with the specified layout
132      */
133     @Nonnull
134     public Repository withLayout(String layout) {
135         return newBuilder(this, true).layout(layout).build();
136     }
137     /**
138      * Creates a new {@code Repository} instance using the specified releases.
139      *
140      * @param releases the new {@code RepositoryPolicy} to use
141      * @return a {@code Repository} with the specified releases
142      */
143     @Nonnull
144     public Repository withReleases(RepositoryPolicy releases) {
145         return newBuilder(this, true).releases(releases).build();
146     }
147     /**
148      * Creates a new {@code Repository} instance using the specified snapshots.
149      *
150      * @param snapshots the new {@code RepositoryPolicy} to use
151      * @return a {@code Repository} with the specified snapshots
152      */
153     @Nonnull
154     public Repository withSnapshots(RepositoryPolicy snapshots) {
155         return newBuilder(this, true).snapshots(snapshots).build();
156     }
157 
158     /**
159      * Creates a new {@code Repository} instance.
160      * Equivalent to {@code newInstance(true)}.
161      * @see #newInstance(boolean)
162      *
163      * @return a new {@code Repository}
164      */
165     @Nonnull
166     public static Repository newInstance() {
167         return newInstance(true);
168     }
169 
170     /**
171      * Creates a new {@code Repository} instance using default values or not.
172      * Equivalent to {@code newBuilder(withDefaults).build()}.
173      *
174      * @param withDefaults the boolean indicating whether default values should be used
175      * @return a new {@code Repository}
176      */
177     @Nonnull
178     public static Repository newInstance(boolean withDefaults) {
179         return newBuilder(withDefaults).build();
180     }
181 
182     /**
183      * Creates a new {@code Repository} builder instance.
184      * Equivalent to {@code newBuilder(true)}.
185      * @see #newBuilder(boolean)
186      *
187      * @return a new {@code Builder}
188      */
189     @Nonnull
190     public static Builder newBuilder() {
191         return newBuilder(true);
192     }
193 
194     /**
195      * Creates a new {@code Repository} builder instance using default values or not.
196      *
197      * @param withDefaults the boolean indicating whether default values should be used
198      * @return a new {@code Builder}
199      */
200     @Nonnull
201     public static Builder newBuilder(boolean withDefaults) {
202         return new Builder(withDefaults);
203     }
204 
205     /**
206      * Creates a new {@code Repository} builder instance using the specified object as a basis.
207      * Equivalent to {@code newBuilder(from, false)}.
208      *
209      * @param from the {@code Repository} instance to use as a basis
210      * @return a new {@code Builder}
211      */
212     @Nonnull
213     public static Builder newBuilder(Repository from) {
214         return newBuilder(from, false);
215     }
216 
217     /**
218      * Creates a new {@code Repository} builder instance using the specified object as a basis.
219      *
220      * @param from the {@code Repository} instance to use as a basis
221      * @param forceCopy the boolean indicating if a copy should be forced
222      * @return a new {@code Builder}
223      */
224     @Nonnull
225     public static Builder newBuilder(Repository from, boolean forceCopy) {
226         return new Builder(from, forceCopy);
227     }
228 
229     /**
230      * Builder class used to create Repository instances.
231      * @see #with()
232      * @see #newBuilder()
233      */
234     @NotThreadSafe
235     public static class Builder
236         extends RepositoryBase.Builder
237     {
238         Repository base;
239         RepositoryPolicy releases;
240         RepositoryPolicy snapshots;
241 
242         protected Builder(boolean withDefaults) {
243             super(withDefaults);
244             if (withDefaults) {
245             }
246         }
247 
248         protected Builder(Repository base, boolean forceCopy) {
249             super(base, forceCopy);
250             if (forceCopy) {
251                 this.releases = base.releases;
252                 this.snapshots = base.snapshots;
253                 this.locations = base.locations;
254                 this.importedFrom = base.importedFrom;
255             } else {
256                 this.base = base;
257             }
258         }
259 
260         @Nonnull
261         public Builder id(String id) {
262             this.id = id;
263             return this;
264         }
265 
266         @Nonnull
267         public Builder name(String name) {
268             this.name = name;
269             return this;
270         }
271 
272         @Nonnull
273         public Builder url(String url) {
274             this.url = url;
275             return this;
276         }
277 
278         @Nonnull
279         public Builder layout(String layout) {
280             this.layout = layout;
281             return this;
282         }
283 
284         @Nonnull
285         public Builder releases(RepositoryPolicy releases) {
286             this.releases = releases;
287             return this;
288         }
289 
290         @Nonnull
291         public Builder snapshots(RepositoryPolicy snapshots) {
292             this.snapshots = snapshots;
293             return this;
294         }
295 
296 
297         @Nonnull
298         public Builder location(Object key, InputLocation location) {
299             if (location != null) {
300                 if (!(this.locations instanceof HashMap)) {
301                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
302                 }
303                 this.locations.put(key, location);
304             }
305             return this;
306         }
307 
308         @Nonnull
309         public Builder importedFrom(InputLocation importedFrom) {
310             this.importedFrom = importedFrom;
311             return this;
312         }
313 
314         @Nonnull
315         public Repository build() {
316             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
317             if (base != null
318                     && (id == null || id == base.id)
319                     && (name == null || name == base.name)
320                     && (url == null || url == base.url)
321                     && (layout == null || layout == base.layout)
322                     && (releases == null || releases == base.releases)
323                     && (snapshots == null || snapshots == base.snapshots)
324             ) {
325                 return base;
326             }
327             return new Repository(this);
328         }
329     }
330 
331 }