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.plugin.descriptor;
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.Set;
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   * Definition of a dependency, needed by the plugin at runtime.
21   */
22  @Experimental
23  @Generated @ThreadSafe @Immutable
24  public class Dependency
25      implements Serializable
26  {
27      /**
28       * The group id of the dependency.
29       */
30      final String groupId;
31      /**
32       * The artifact id of the dependency.
33       */
34      final String artifactId;
35      /**
36       * The version of the dependency.
37       */
38      final String version;
39      /**
40       * The type of dependency.
41       */
42      final String type;
43  
44      /**
45        * Constructor for this class, to be called from its subclasses and {@link Builder}.
46        * @see Builder#build()
47        */
48      protected Dependency(Builder builder) {
49          this.groupId = builder.groupId != null ? builder.groupId : (builder.base != null ? builder.base.groupId : null);
50          this.artifactId = builder.artifactId != null ? builder.artifactId : (builder.base != null ? builder.base.artifactId : null);
51          this.version = builder.version != null ? builder.version : (builder.base != null ? builder.base.version : null);
52          this.type = builder.type != null ? builder.type : (builder.base != null ? builder.base.type : null);
53      }
54  
55      /**
56       * The group id of the dependency.
57       *
58       * @return a {@code String}
59       */
60      public String getGroupId() {
61          return this.groupId;
62      }
63  
64      /**
65       * The artifact id of the dependency.
66       *
67       * @return a {@code String}
68       */
69      public String getArtifactId() {
70          return this.artifactId;
71      }
72  
73      /**
74       * The version of the dependency.
75       *
76       * @return a {@code String}
77       */
78      public String getVersion() {
79          return this.version;
80      }
81  
82      /**
83       * The type of dependency.
84       *
85       * @return a {@code String}
86       */
87      public String getType() {
88          return this.type;
89      }
90  
91      /**
92       * Creates a new builder with this object as the basis.
93       *
94       * @return a {@code Builder}
95       */
96      @Nonnull
97      public Builder with() {
98          return newBuilder(this);
99      }
100     /**
101      * Creates a new {@code Dependency} instance using the specified groupId.
102      *
103      * @param groupId the new {@code String} to use
104      * @return a {@code Dependency} with the specified groupId
105      */
106     @Nonnull
107     public Dependency withGroupId(String groupId) {
108         return newBuilder(this, true).groupId(groupId).build();
109     }
110     /**
111      * Creates a new {@code Dependency} instance using the specified artifactId.
112      *
113      * @param artifactId the new {@code String} to use
114      * @return a {@code Dependency} with the specified artifactId
115      */
116     @Nonnull
117     public Dependency withArtifactId(String artifactId) {
118         return newBuilder(this, true).artifactId(artifactId).build();
119     }
120     /**
121      * Creates a new {@code Dependency} instance using the specified version.
122      *
123      * @param version the new {@code String} to use
124      * @return a {@code Dependency} with the specified version
125      */
126     @Nonnull
127     public Dependency withVersion(String version) {
128         return newBuilder(this, true).version(version).build();
129     }
130     /**
131      * Creates a new {@code Dependency} instance using the specified type.
132      *
133      * @param type the new {@code String} to use
134      * @return a {@code Dependency} with the specified type
135      */
136     @Nonnull
137     public Dependency withType(String type) {
138         return newBuilder(this, true).type(type).build();
139     }
140 
141     /**
142      * Creates a new {@code Dependency} instance.
143      * Equivalent to {@code newInstance(true)}.
144      * @see #newInstance(boolean)
145      *
146      * @return a new {@code Dependency}
147      */
148     @Nonnull
149     public static Dependency newInstance() {
150         return newInstance(true);
151     }
152 
153     /**
154      * Creates a new {@code Dependency} instance using default values or not.
155      * Equivalent to {@code newBuilder(withDefaults).build()}.
156      *
157      * @param withDefaults the boolean indicating whether default values should be used
158      * @return a new {@code Dependency}
159      */
160     @Nonnull
161     public static Dependency newInstance(boolean withDefaults) {
162         return newBuilder(withDefaults).build();
163     }
164 
165     /**
166      * Creates a new {@code Dependency} builder instance.
167      * Equivalent to {@code newBuilder(true)}.
168      * @see #newBuilder(boolean)
169      *
170      * @return a new {@code Builder}
171      */
172     @Nonnull
173     public static Builder newBuilder() {
174         return newBuilder(true);
175     }
176 
177     /**
178      * Creates a new {@code Dependency} builder instance using default values or not.
179      *
180      * @param withDefaults the boolean indicating whether default values should be used
181      * @return a new {@code Builder}
182      */
183     @Nonnull
184     public static Builder newBuilder(boolean withDefaults) {
185         return new Builder(withDefaults);
186     }
187 
188     /**
189      * Creates a new {@code Dependency} builder instance using the specified object as a basis.
190      * Equivalent to {@code newBuilder(from, false)}.
191      *
192      * @param from the {@code Dependency} instance to use as a basis
193      * @return a new {@code Builder}
194      */
195     @Nonnull
196     public static Builder newBuilder(Dependency from) {
197         return newBuilder(from, false);
198     }
199 
200     /**
201      * Creates a new {@code Dependency} builder instance using the specified object as a basis.
202      *
203      * @param from the {@code Dependency} instance to use as a basis
204      * @param forceCopy the boolean indicating if a copy should be forced
205      * @return a new {@code Builder}
206      */
207     @Nonnull
208     public static Builder newBuilder(Dependency from, boolean forceCopy) {
209         return new Builder(from, forceCopy);
210     }
211 
212     /**
213      * Builder class used to create Dependency instances.
214      * @see #with()
215      * @see #newBuilder()
216      */
217     @NotThreadSafe
218     public static class Builder
219     {
220         Dependency base;
221         String groupId;
222         String artifactId;
223         String version;
224         String type;
225 
226         protected Builder(boolean withDefaults) {
227             if (withDefaults) {
228                 this.type = "jar";
229             }
230         }
231 
232         protected Builder(Dependency base, boolean forceCopy) {
233             if (forceCopy) {
234                 this.groupId = base.groupId;
235                 this.artifactId = base.artifactId;
236                 this.version = base.version;
237                 this.type = base.type;
238             } else {
239                 this.base = base;
240             }
241         }
242 
243         @Nonnull
244         public Builder groupId(String groupId) {
245             this.groupId = groupId;
246             return this;
247         }
248 
249         @Nonnull
250         public Builder artifactId(String artifactId) {
251             this.artifactId = artifactId;
252             return this;
253         }
254 
255         @Nonnull
256         public Builder version(String version) {
257             this.version = version;
258             return this;
259         }
260 
261         @Nonnull
262         public Builder type(String type) {
263             this.type = type;
264             return this;
265         }
266 
267 
268         @Nonnull
269         public Dependency build() {
270             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
271             if (base != null
272                     && (groupId == null || groupId == base.groupId)
273                     && (artifactId == null || artifactId == base.artifactId)
274                     && (version == null || version == base.version)
275                     && (type == null || type == base.type)
276             ) {
277                 return base;
278             }
279             return new Dependency(this);
280         }
281     }
282 
283 }