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.Set;
13  import org.apache.maven.api.annotations.Experimental;
14  import org.apache.maven.api.annotations.Generated;
15  import org.apache.maven.api.annotations.Immutable;
16  import org.apache.maven.api.annotations.Nonnull;
17  import org.apache.maven.api.annotations.NotThreadSafe;
18  import org.apache.maven.api.annotations.ThreadSafe;
19  
20  /**
21   * Deployment repository contains the information needed for deploying to the remote
22   * repository, which adds uniqueVersion property to usual repositories for download.
23   */
24  @Experimental
25  @Generated @ThreadSafe @Immutable
26  public class DeploymentRepository
27      extends Repository
28      implements Serializable, InputLocationTracker
29  {
30      /**
31       * Whether to assign snapshots a unique version comprised of the timestamp and
32       * build number, or to use the same version each time
33       */
34      final boolean uniqueVersion;
35      /** Locations (this potentially hides the same name field from the super class) */
36      final Map<Object, InputLocation> locations;
37  
38      /**
39        * Constructor for this class, to be called from its subclasses and {@link Builder}.
40        * @see Builder#build()
41        */
42      protected DeploymentRepository(Builder builder) {
43          super(builder);
44          this.uniqueVersion = builder.uniqueVersion != null ? builder.uniqueVersion : (builder.base != null ? builder.base.uniqueVersion : true);
45          Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
46          Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
47          Map<Object, InputLocation> mutableLocations = new HashMap<>(super.locations);
48          mutableLocations.put("uniqueVersion", newlocs.containsKey("uniqueVersion") ? newlocs.get("uniqueVersion") : oldlocs.get("uniqueVersion"));
49          this.locations = Collections.unmodifiableMap(mutableLocations);
50      }
51  
52      @Override
53      public boolean equals(Object o) {
54          if (this == o) {
55              return true;
56          }
57          if (o == null || !(o instanceof DeploymentRepository)) {
58              return false;
59          }
60          DeploymentRepository that = (DeploymentRepository) 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       * Whether to assign snapshots a unique version comprised of the timestamp and
71       * build number, or to use the same version each time
72       *
73       * @return a {@code boolean}
74       */
75      public boolean isUniqueVersion() {
76          return this.uniqueVersion;
77      }
78  
79      /**
80       * Gets the location of the specified field in the input source.
81       */
82      public InputLocation getLocation(Object key) {
83          return locations != null ? locations.get(key) : null;
84      }
85  
86      /**
87      * Gets the keys of the locations of the input source.
88      */
89      public Set<Object> getLocationKeys() {
90          return locations != null ? locations.keySet() : null;
91      }
92  
93      /**
94       * Creates a new builder with this object as the basis.
95       *
96       * @return a {@code Builder}
97       */
98      @Nonnull
99      public Builder with() {
100         return newBuilder(this);
101     }
102     /**
103      * Creates a new {@code DeploymentRepository} instance using the specified id.
104      *
105      * @param id the new {@code String} to use
106      * @return a {@code DeploymentRepository} with the specified id
107      */
108     @Nonnull
109     public DeploymentRepository withId(String id) {
110         return newBuilder(this, true).id(id).build();
111     }
112     /**
113      * Creates a new {@code DeploymentRepository} instance using the specified name.
114      *
115      * @param name the new {@code String} to use
116      * @return a {@code DeploymentRepository} with the specified name
117      */
118     @Nonnull
119     public DeploymentRepository withName(String name) {
120         return newBuilder(this, true).name(name).build();
121     }
122     /**
123      * Creates a new {@code DeploymentRepository} instance using the specified url.
124      *
125      * @param url the new {@code String} to use
126      * @return a {@code DeploymentRepository} with the specified url
127      */
128     @Nonnull
129     public DeploymentRepository withUrl(String url) {
130         return newBuilder(this, true).url(url).build();
131     }
132     /**
133      * Creates a new {@code DeploymentRepository} instance using the specified layout.
134      *
135      * @param layout the new {@code String} to use
136      * @return a {@code DeploymentRepository} with the specified layout
137      */
138     @Nonnull
139     public DeploymentRepository withLayout(String layout) {
140         return newBuilder(this, true).layout(layout).build();
141     }
142     /**
143      * Creates a new {@code DeploymentRepository} instance using the specified releases.
144      *
145      * @param releases the new {@code RepositoryPolicy} to use
146      * @return a {@code DeploymentRepository} with the specified releases
147      */
148     @Nonnull
149     public DeploymentRepository withReleases(RepositoryPolicy releases) {
150         return newBuilder(this, true).releases(releases).build();
151     }
152     /**
153      * Creates a new {@code DeploymentRepository} instance using the specified snapshots.
154      *
155      * @param snapshots the new {@code RepositoryPolicy} to use
156      * @return a {@code DeploymentRepository} with the specified snapshots
157      */
158     @Nonnull
159     public DeploymentRepository withSnapshots(RepositoryPolicy snapshots) {
160         return newBuilder(this, true).snapshots(snapshots).build();
161     }
162     /**
163      * Creates a new {@code DeploymentRepository} instance using the specified uniqueVersion.
164      *
165      * @param uniqueVersion the new {@code boolean} to use
166      * @return a {@code DeploymentRepository} with the specified uniqueVersion
167      */
168     @Nonnull
169     public DeploymentRepository withUniqueVersion(boolean uniqueVersion) {
170         return newBuilder(this, true).uniqueVersion(uniqueVersion).build();
171     }
172 
173     /**
174      * Creates a new {@code DeploymentRepository} instance.
175      * Equivalent to {@code newInstance(true)}.
176      * @see #newInstance(boolean)
177      *
178      * @return a new {@code DeploymentRepository}
179      */
180     @Nonnull
181     public static DeploymentRepository newInstance() {
182         return newInstance(true);
183     }
184 
185     /**
186      * Creates a new {@code DeploymentRepository} instance using default values or not.
187      * Equivalent to {@code newBuilder(withDefaults).build()}.
188      *
189      * @param withDefaults the boolean indicating whether default values should be used
190      * @return a new {@code DeploymentRepository}
191      */
192     @Nonnull
193     public static DeploymentRepository newInstance(boolean withDefaults) {
194         return newBuilder(withDefaults).build();
195     }
196 
197     /**
198      * Creates a new {@code DeploymentRepository} builder instance.
199      * Equivalent to {@code newBuilder(true)}.
200      * @see #newBuilder(boolean)
201      *
202      * @return a new {@code Builder}
203      */
204     @Nonnull
205     public static Builder newBuilder() {
206         return newBuilder(true);
207     }
208 
209     /**
210      * Creates a new {@code DeploymentRepository} builder instance using default values or not.
211      *
212      * @param withDefaults the boolean indicating whether default values should be used
213      * @return a new {@code Builder}
214      */
215     @Nonnull
216     public static Builder newBuilder(boolean withDefaults) {
217         return new Builder(withDefaults);
218     }
219 
220     /**
221      * Creates a new {@code DeploymentRepository} builder instance using the specified object as a basis.
222      * Equivalent to {@code newBuilder(from, false)}.
223      *
224      * @param from the {@code DeploymentRepository} instance to use as a basis
225      * @return a new {@code Builder}
226      */
227     @Nonnull
228     public static Builder newBuilder(DeploymentRepository from) {
229         return newBuilder(from, false);
230     }
231 
232     /**
233      * Creates a new {@code DeploymentRepository} builder instance using the specified object as a basis.
234      *
235      * @param from the {@code DeploymentRepository} instance to use as a basis
236      * @param forceCopy the boolean indicating if a copy should be forced
237      * @return a new {@code Builder}
238      */
239     @Nonnull
240     public static Builder newBuilder(DeploymentRepository from, boolean forceCopy) {
241         return new Builder(from, forceCopy);
242     }
243 
244     /**
245      * Builder class used to create DeploymentRepository instances.
246      * @see #with()
247      * @see #newBuilder()
248      */
249     @NotThreadSafe
250     public static class Builder
251         extends Repository.Builder
252     {
253         DeploymentRepository base;
254         Boolean uniqueVersion;
255 
256         protected Builder(boolean withDefaults) {
257             super(withDefaults);
258             if (withDefaults) {
259                 this.uniqueVersion = true;
260             }
261         }
262 
263         protected Builder(DeploymentRepository base, boolean forceCopy) {
264             super(base, forceCopy);
265             if (forceCopy) {
266                 this.uniqueVersion = base.uniqueVersion;
267                 this.locations = base.locations;
268                 this.importedFrom = base.importedFrom;
269             } else {
270                 this.base = base;
271             }
272         }
273 
274         @Nonnull
275         public Builder id(String id) {
276             this.id = id;
277             return this;
278         }
279 
280         @Nonnull
281         public Builder name(String name) {
282             this.name = name;
283             return this;
284         }
285 
286         @Nonnull
287         public Builder url(String url) {
288             this.url = url;
289             return this;
290         }
291 
292         @Nonnull
293         public Builder layout(String layout) {
294             this.layout = layout;
295             return this;
296         }
297 
298         @Nonnull
299         public Builder releases(RepositoryPolicy releases) {
300             this.releases = releases;
301             return this;
302         }
303 
304         @Nonnull
305         public Builder snapshots(RepositoryPolicy snapshots) {
306             this.snapshots = snapshots;
307             return this;
308         }
309 
310         @Nonnull
311         public Builder uniqueVersion(boolean uniqueVersion) {
312             this.uniqueVersion = uniqueVersion;
313             return this;
314         }
315 
316 
317         @Nonnull
318         public Builder location(Object key, InputLocation location) {
319             if (location != null) {
320                 if (!(this.locations instanceof HashMap)) {
321                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
322                 }
323                 this.locations.put(key, location);
324             }
325             return this;
326         }
327 
328         @Nonnull
329         public Builder importedFrom(InputLocation importedFrom) {
330             this.importedFrom = importedFrom;
331             return this;
332         }
333 
334         @Nonnull
335         public DeploymentRepository build() {
336             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
337             if (base != null
338                     && (id == null || id == base.id)
339                     && (name == null || name == base.name)
340                     && (url == null || url == base.url)
341                     && (layout == null || layout == base.layout)
342                     && (releases == null || releases == base.releases)
343                     && (snapshots == null || snapshots == base.snapshots)
344                     && (uniqueVersion == null || uniqueVersion == base.uniqueVersion)
345             ) {
346                 return base;
347             }
348             return new DeploymentRepository(this);
349         }
350     }
351 
352 }