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.toolchain;
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 import org.apache.maven.api.xml.XmlNode;
19
20 /**
21 * Definition of a toolchain instance.
22 */
23 @Experimental
24 @Generated @ThreadSafe @Immutable
25 public class ToolchainModel
26 extends TrackableBase
27 implements Serializable, InputLocationTracker
28 {
29 /**
30 * Type of toolchain:<ul>
31 * <li>{@code jdk} for <a
32 * href="https://maven.apache.org/plugins/maven-toolchains-plugin/toolchains/jdk.html">JDK Standard Toolchain</a>,</li>
33 * <li>other value for <a
34 * href="https://maven.apache.org/plugins/maven-toolchains-plugin/toolchains/custom.html">Custom Toolchain</a></li>
35 * </ul>
36 */
37 final String type;
38 /**
39 * Toolchain identification information, which will be matched against project requirements.
40 * <p>For Maven 2.0.9 to 3.2.3, the actual content structure was completely open: each toolchain type would
41 * define its own format and semantics. This was generally a properties format.
42 * <p>Since Maven 3.2.4, the type for this field has been changed to Properties to match the de-facto
43 * format.
44 * <p>Each toolchain defines its own properties names and semantics.
45 */
46 final Map<String, String> provides;
47 /**
48 * Toolchain configuration information, like location or any information that is to be retrieved.
49 * <p>Actual content structure is completely open: each toolchain type will define its own format and
50 * semantics.
51 * <p>In general, this is a properties format: {@code <name>value</name>} with per-toolchain
52 * defined properties names.
53 */
54 final XmlNode configuration;
55 /** Locations (this potentially hides the same name field from the super class) */
56 final Map<Object, InputLocation> locations;
57
58 /**
59 * Constructor for this class, to be called from its subclasses and {@link Builder}.
60 * @see Builder#build()
61 */
62 protected ToolchainModel(Builder builder) {
63 super(builder);
64 this.type = builder.type != null ? builder.type : (builder.base != null ? builder.base.type : null);
65 this.provides = ImmutableCollections.copy(builder.provides != null ? builder.provides : (builder.base != null ? builder.base.provides : null));
66 this.configuration = builder.configuration != null ? builder.configuration : (builder.base != null ? builder.base.configuration : null);
67 Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
68 Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
69 Map<Object, InputLocation> mutableLocations = new HashMap<>(super.locations);
70 mutableLocations.put("type", newlocs.containsKey("type") ? newlocs.get("type") : oldlocs.get("type"));
71 mutableLocations.put("provides", newlocs.containsKey("provides") ? newlocs.get("provides") : oldlocs.get("provides"));
72 mutableLocations.put("configuration", newlocs.containsKey("configuration") ? newlocs.get("configuration") : oldlocs.get("configuration"));
73 this.locations = Collections.unmodifiableMap(mutableLocations);
74 }
75
76 /**
77 * Type of toolchain:<ul>
78 * <li>{@code jdk} for <a
79 * href="https://maven.apache.org/plugins/maven-toolchains-plugin/toolchains/jdk.html">JDK Standard Toolchain</a>,</li>
80 * <li>other value for <a
81 * href="https://maven.apache.org/plugins/maven-toolchains-plugin/toolchains/custom.html">Custom Toolchain</a></li>
82 * </ul>
83 *
84 * @return a {@code String}
85 */
86 public String getType() {
87 return this.type;
88 }
89
90 /**
91 * Toolchain identification information, which will be matched against project requirements.
92 * <p>For Maven 2.0.9 to 3.2.3, the actual content structure was completely open: each toolchain type would
93 * define its own format and semantics. This was generally a properties format.
94 * <p>Since Maven 3.2.4, the type for this field has been changed to Properties to match the de-facto
95 * format.
96 * <p>Each toolchain defines its own properties names and semantics.
97 *
98 * @return a {@code Map<String, String>}
99 */
100 @Nonnull
101 public Map<String, String> getProvides() {
102 return this.provides;
103 }
104
105 /**
106 * Toolchain configuration information, like location or any information that is to be retrieved.
107 * <p>Actual content structure is completely open: each toolchain type will define its own format and
108 * semantics.
109 * <p>In general, this is a properties format: {@code <name>value</name>} with per-toolchain
110 * defined properties names.
111 *
112 * @return a {@code XmlNode}
113 */
114 public XmlNode getConfiguration() {
115 return this.configuration;
116 }
117
118 /**
119 * Gets the location of the specified field in the input source.
120 */
121 public InputLocation getLocation(Object key) {
122 return locations != null ? locations.get(key) : null;
123 }
124
125 /**
126 * Gets the keys of the locations of the input source.
127 */
128 public Set<Object> getLocationKeys() {
129 return locations != null ? locations.keySet() : null;
130 }
131
132 /**
133 * Creates a new builder with this object as the basis.
134 *
135 * @return a {@code Builder}
136 */
137 @Nonnull
138 public Builder with() {
139 return newBuilder(this);
140 }
141 /**
142 * Creates a new {@code ToolchainModel} instance using the specified type.
143 *
144 * @param type the new {@code String} to use
145 * @return a {@code ToolchainModel} with the specified type
146 */
147 @Nonnull
148 public ToolchainModel withType(String type) {
149 return newBuilder(this, true).type(type).build();
150 }
151 /**
152 * Creates a new {@code ToolchainModel} instance using the specified provides.
153 *
154 * @param provides the new {@code Map<String, String>} to use
155 * @return a {@code ToolchainModel} with the specified provides
156 */
157 @Nonnull
158 public ToolchainModel withProvides(Map<String, String> provides) {
159 return newBuilder(this, true).provides(provides).build();
160 }
161 /**
162 * Creates a new {@code ToolchainModel} instance using the specified configuration.
163 *
164 * @param configuration the new {@code XmlNode} to use
165 * @return a {@code ToolchainModel} with the specified configuration
166 */
167 @Nonnull
168 public ToolchainModel withConfiguration(XmlNode configuration) {
169 return newBuilder(this, true).configuration(configuration).build();
170 }
171
172 /**
173 * Creates a new {@code ToolchainModel} instance.
174 * Equivalent to {@code newInstance(true)}.
175 * @see #newInstance(boolean)
176 *
177 * @return a new {@code ToolchainModel}
178 */
179 @Nonnull
180 public static ToolchainModel newInstance() {
181 return newInstance(true);
182 }
183
184 /**
185 * Creates a new {@code ToolchainModel} instance using default values or not.
186 * Equivalent to {@code newBuilder(withDefaults).build()}.
187 *
188 * @param withDefaults the boolean indicating whether default values should be used
189 * @return a new {@code ToolchainModel}
190 */
191 @Nonnull
192 public static ToolchainModel newInstance(boolean withDefaults) {
193 return newBuilder(withDefaults).build();
194 }
195
196 /**
197 * Creates a new {@code ToolchainModel} builder instance.
198 * Equivalent to {@code newBuilder(true)}.
199 * @see #newBuilder(boolean)
200 *
201 * @return a new {@code Builder}
202 */
203 @Nonnull
204 public static Builder newBuilder() {
205 return newBuilder(true);
206 }
207
208 /**
209 * Creates a new {@code ToolchainModel} builder instance using default values or not.
210 *
211 * @param withDefaults the boolean indicating whether default values should be used
212 * @return a new {@code Builder}
213 */
214 @Nonnull
215 public static Builder newBuilder(boolean withDefaults) {
216 return new Builder(withDefaults);
217 }
218
219 /**
220 * Creates a new {@code ToolchainModel} builder instance using the specified object as a basis.
221 * Equivalent to {@code newBuilder(from, false)}.
222 *
223 * @param from the {@code ToolchainModel} instance to use as a basis
224 * @return a new {@code Builder}
225 */
226 @Nonnull
227 public static Builder newBuilder(ToolchainModel from) {
228 return newBuilder(from, false);
229 }
230
231 /**
232 * Creates a new {@code ToolchainModel} builder instance using the specified object as a basis.
233 *
234 * @param from the {@code ToolchainModel} instance to use as a basis
235 * @param forceCopy the boolean indicating if a copy should be forced
236 * @return a new {@code Builder}
237 */
238 @Nonnull
239 public static Builder newBuilder(ToolchainModel from, boolean forceCopy) {
240 return new Builder(from, forceCopy);
241 }
242
243 /**
244 * Builder class used to create ToolchainModel instances.
245 * @see #with()
246 * @see #newBuilder()
247 */
248 @NotThreadSafe
249 public static class Builder
250 extends TrackableBase.Builder
251 {
252 ToolchainModel base;
253 String type;
254 Map<String, String> provides;
255 XmlNode configuration;
256
257 protected Builder(boolean withDefaults) {
258 super(withDefaults);
259 if (withDefaults) {
260 }
261 }
262
263 protected Builder(ToolchainModel base, boolean forceCopy) {
264 super(base, forceCopy);
265 if (forceCopy) {
266 this.type = base.type;
267 this.provides = base.provides;
268 this.configuration = base.configuration;
269 this.locations = base.locations;
270 this.importedFrom = base.importedFrom;
271 } else {
272 this.base = base;
273 }
274 }
275
276 @Nonnull
277 public Builder type(String type) {
278 this.type = type;
279 return this;
280 }
281
282 @Nonnull
283 public Builder provides(Map<String, String> provides) {
284 this.provides = provides;
285 return this;
286 }
287
288 @Nonnull
289 public Builder configuration(XmlNode configuration) {
290 this.configuration = configuration;
291 return this;
292 }
293
294
295 @Nonnull
296 public Builder location(Object key, InputLocation location) {
297 if (location != null) {
298 if (!(this.locations instanceof HashMap)) {
299 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
300 }
301 this.locations.put(key, location);
302 }
303 return this;
304 }
305
306 @Nonnull
307 public Builder importedFrom(InputLocation importedFrom) {
308 this.importedFrom = importedFrom;
309 return this;
310 }
311
312 @Nonnull
313 public ToolchainModel build() {
314 // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
315 if (base != null
316 && (type == null || type == base.type)
317 && (provides == null || provides == base.provides)
318 && (configuration == null || configuration == base.configuration)
319 ) {
320 return base;
321 }
322 return new ToolchainModel(this);
323 }
324 }
325
326
327
328 /**
329 * Computes a hash value based on {@link #getType()} and {@link #getProvides()} values.
330 */
331 public int hashCode() {
332 return java.util.Objects.hash(getType(), getProvides());
333 } //-- int hashCode()
334
335 /**
336 * Checks equality based on {@link #getType()} and {@link #getProvides()} values.
337 */
338 public boolean equals(Object other) {
339 if (this == other) {
340 return true;
341 } else if (!(other instanceof ToolchainModel)) {
342 return false;
343 } else {
344 ToolchainModel that = (ToolchainModel) other;
345 return java.util.Objects.equals(this.getType(), that.getType())
346 && java.util.Objects.equals(this.getProvides(), that.getProvides());
347 }
348 } //-- boolean equals(Object)
349
350
351 }