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