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