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   * Deployment repository contains the information needed for deploying to the remote
21   * repository, which adds uniqueVersion property to usual repositories for download.
22   */
23  @Experimental
24  @Generated @ThreadSafe @Immutable
25  public class DeploymentRepository
26      extends Repository
27      implements Serializable, InputLocationTracker
28  {
29      /**
30       * Whether to assign snapshots a unique version comprised of the timestamp and
31       * build number, or to use the same version each time
32       */
33      final boolean uniqueVersion;
34  
35      /**
36        * Constructor for this class, package protected.
37        * @see Builder#build()
38        */
39      DeploymentRepository(
40          String id,
41          String name,
42          String url,
43          String layout,
44          RepositoryPolicy releases,
45          RepositoryPolicy snapshots,
46          boolean uniqueVersion,
47          Map<Object, InputLocation> locations
48      ) {
49          super(
50              id,
51              name,
52              url,
53              layout,
54              releases,
55              snapshots,
56              locations
57          );
58          this.uniqueVersion = uniqueVersion;
59      }
60  
61      @Override
62      public boolean equals(Object o) {
63          if (this == o) {
64              return true;
65          }
66          if (o == null || !(o instanceof DeploymentRepository)) {
67              return false;
68          }
69          DeploymentRepository that = (DeploymentRepository) o;
70          return Objects.equals( this.id, that.id );
71      }
72  
73      @Override
74      public int hashCode() {
75          return Objects.hash(id);
76      }
77  
78      /**
79       * Whether to assign snapshots a unique version comprised of the timestamp and
80       * build number, or to use the same version each time
81       *
82       * @return a {@code boolean}
83       */
84      public boolean isUniqueVersion() {
85          return this.uniqueVersion;
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 DeploymentRepository} instance using the specified id.
99       *
100      * @param id the new {@code String} to use
101      * @return a {@code DeploymentRepository} with the specified id
102      */
103     @Nonnull
104     public DeploymentRepository withId(String id) {
105         return newBuilder(this, true).id(id).build();
106     }
107     /**
108      * Creates a new {@code DeploymentRepository} instance using the specified name.
109      *
110      * @param name the new {@code String} to use
111      * @return a {@code DeploymentRepository} with the specified name
112      */
113     @Nonnull
114     public DeploymentRepository withName(String name) {
115         return newBuilder(this, true).name(name).build();
116     }
117     /**
118      * Creates a new {@code DeploymentRepository} instance using the specified url.
119      *
120      * @param url the new {@code String} to use
121      * @return a {@code DeploymentRepository} with the specified url
122      */
123     @Nonnull
124     public DeploymentRepository withUrl(String url) {
125         return newBuilder(this, true).url(url).build();
126     }
127     /**
128      * Creates a new {@code DeploymentRepository} instance using the specified layout.
129      *
130      * @param layout the new {@code String} to use
131      * @return a {@code DeploymentRepository} with the specified layout
132      */
133     @Nonnull
134     public DeploymentRepository withLayout(String layout) {
135         return newBuilder(this, true).layout(layout).build();
136     }
137     /**
138      * Creates a new {@code DeploymentRepository} instance using the specified releases.
139      *
140      * @param releases the new {@code RepositoryPolicy} to use
141      * @return a {@code DeploymentRepository} with the specified releases
142      */
143     @Nonnull
144     public DeploymentRepository withReleases(RepositoryPolicy releases) {
145         return newBuilder(this, true).releases(releases).build();
146     }
147     /**
148      * Creates a new {@code DeploymentRepository} instance using the specified snapshots.
149      *
150      * @param snapshots the new {@code RepositoryPolicy} to use
151      * @return a {@code DeploymentRepository} with the specified snapshots
152      */
153     @Nonnull
154     public DeploymentRepository withSnapshots(RepositoryPolicy snapshots) {
155         return newBuilder(this, true).snapshots(snapshots).build();
156     }
157     /**
158      * Creates a new {@code DeploymentRepository} instance using the specified uniqueVersion.
159      *
160      * @param uniqueVersion the new {@code boolean} to use
161      * @return a {@code DeploymentRepository} with the specified uniqueVersion
162      */
163     @Nonnull
164     public DeploymentRepository withUniqueVersion(boolean uniqueVersion) {
165         return newBuilder(this, true).uniqueVersion(uniqueVersion).build();
166     }
167 
168     /**
169      * Creates a new {@code DeploymentRepository} instance.
170      * Equivalent to {@code newInstance(true)}.
171      * @see #newInstance(boolean)
172      *
173      * @return a new {@code DeploymentRepository}
174      */
175     @Nonnull
176     public static DeploymentRepository newInstance() {
177         return newInstance(true);
178     }
179 
180     /**
181      * Creates a new {@code DeploymentRepository} instance using default values or not.
182      * Equivalent to {@code newBuilder(withDefaults).build()}.
183      *
184      * @param withDefaults the boolean indicating whether default values should be used
185      * @return a new {@code DeploymentRepository}
186      */
187     @Nonnull
188     public static DeploymentRepository newInstance(boolean withDefaults) {
189         return newBuilder(withDefaults).build();
190     }
191 
192     /**
193      * Creates a new {@code DeploymentRepository} builder instance.
194      * Equivalent to {@code newBuilder(true)}.
195      * @see #newBuilder(boolean)
196      *
197      * @return a new {@code Builder}
198      */
199     @Nonnull
200     public static Builder newBuilder() {
201         return newBuilder(true);
202     }
203 
204     /**
205      * Creates a new {@code DeploymentRepository} builder instance using default values or not.
206      *
207      * @param withDefaults the boolean indicating whether default values should be used
208      * @return a new {@code Builder}
209      */
210     @Nonnull
211     public static Builder newBuilder(boolean withDefaults) {
212         return new Builder(withDefaults);
213     }
214 
215     /**
216      * Creates a new {@code DeploymentRepository} builder instance using the specified object as a basis.
217      * Equivalent to {@code newBuilder(from, false)}.
218      *
219      * @param from the {@code DeploymentRepository} instance to use as a basis
220      * @return a new {@code Builder}
221      */
222     @Nonnull
223     public static Builder newBuilder(DeploymentRepository from) {
224         return newBuilder(from, false);
225     }
226 
227     /**
228      * Creates a new {@code DeploymentRepository} builder instance using the specified object as a basis.
229      *
230      * @param from the {@code DeploymentRepository} instance to use as a basis
231      * @param forceCopy the boolean indicating if a copy should be forced
232      * @return a new {@code Builder}
233      */
234     @Nonnull
235     public static Builder newBuilder(DeploymentRepository from, boolean forceCopy) {
236         return new Builder(from, forceCopy);
237     }
238 
239     /**
240      * Builder class used to create DeploymentRepository instances.
241      * @see #with()
242      * @see #newBuilder()
243      */
244     @NotThreadSafe
245     public static class Builder
246         extends Repository.Builder
247     {
248         DeploymentRepository base;
249         Boolean uniqueVersion;
250 
251         Builder(boolean withDefaults) {
252             super(withDefaults);
253             if (withDefaults) {
254                 this.uniqueVersion = true;
255             }
256         }
257 
258         Builder(DeploymentRepository base, boolean forceCopy) {
259             super(base, forceCopy);
260             if (forceCopy) {
261                 this.uniqueVersion = base.uniqueVersion;
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         @Nonnull
305         public Builder uniqueVersion(boolean uniqueVersion) {
306             this.uniqueVersion = uniqueVersion;
307             return this;
308         }
309 
310 
311         @Nonnull
312         public Builder location(Object key, InputLocation location) {
313             if (location != null) {
314                 if (!(this.locations instanceof HashMap)) {
315                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
316                 }
317                 this.locations.put(key, location);
318             }
319             return this;
320         }
321 
322         @Nonnull
323         public DeploymentRepository build() {
324             if (base != null
325                     && (id == null || id == base.id)
326                     && (name == null || name == base.name)
327                     && (url == null || url == base.url)
328                     && (layout == null || layout == base.layout)
329                     && (releases == null || releases == base.releases)
330                     && (snapshots == null || snapshots == base.snapshots)
331                     && (uniqueVersion == null || uniqueVersion == base.uniqueVersion)
332             ) {
333                 return base;
334             }
335             Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
336             Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
337             Map<Object, InputLocation> locations = new HashMap<>();
338             locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
339             locations.put("id", newlocs.containsKey("id") ? newlocs.get("id") : oldlocs.get("id"));
340             locations.put("name", newlocs.containsKey("name") ? newlocs.get("name") : oldlocs.get("name"));
341             locations.put("url", newlocs.containsKey("url") ? newlocs.get("url") : oldlocs.get("url"));
342             locations.put("layout", newlocs.containsKey("layout") ? newlocs.get("layout") : oldlocs.get("layout"));
343             locations.put("releases", newlocs.containsKey("releases") ? newlocs.get("releases") : oldlocs.get("releases"));
344             locations.put("snapshots", newlocs.containsKey("snapshots") ? newlocs.get("snapshots") : oldlocs.get("snapshots"));
345             locations.put("uniqueVersion", newlocs.containsKey("uniqueVersion") ? newlocs.get("uniqueVersion") : oldlocs.get("uniqueVersion"));
346             return new DeploymentRepository(
347                 id != null ? id : (base != null ? base.id : null),
348                 name != null ? name : (base != null ? base.name : null),
349                 url != null ? url : (base != null ? base.url : null),
350                 layout != null ? layout : (base != null ? base.layout : null),
351                 releases != null ? releases : (base != null ? base.releases : null),
352                 snapshots != null ? snapshots : (base != null ? base.snapshots : null),
353                 uniqueVersion != null ? uniqueVersion : (base != null ? base.uniqueVersion : true),
354                 locations
355             );
356         }
357     }
358 
359 }