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