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