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