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