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