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.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 * Describes the prerequisites a project can have.
21 */
22 @Experimental
23 @Generated @ThreadSafe @Immutable
24 public class Prerequisites
25 implements Serializable, InputLocationTracker
26 {
27 /**
28 * For a plugin project (packaging is {@code maven-plugin}), the minimum version of
29 * Maven required to use the resulting plugin.<br>
30 * In Maven 2, this was also specifying the minimum version of Maven required to build a
31 * project, but this usage is <b>deprecated</b> in Maven 3 and not checked any more: use
32 * the <a href="https://maven.apache.org/enforcer/enforcer-rules/requireMavenVersion.html">Maven Enforcer Plugin's
33 * {@code requireMavenVersion} rule</a> instead.
34 */
35 final String maven;
36 /** Locations (this potentially hides the same name field from the super class) */
37 final Map<Object, InputLocation> locations;
38 /** Location tracking */
39 final InputLocation importedFrom;
40
41 /**
42 * Constructor for this class, to be called from its subclasses and {@link Builder}.
43 * @see Builder#build()
44 */
45 protected Prerequisites(Builder builder) {
46 this.maven = builder.maven != null ? builder.maven : (builder.base != null ? builder.base.maven : null);
47 Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
48 Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
49 Map<Object, InputLocation> mutableLocations = new HashMap<>();
50 this.importedFrom = builder.importedFrom;
51 mutableLocations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
52 mutableLocations.put("maven", newlocs.containsKey("maven") ? newlocs.get("maven") : oldlocs.get("maven"));
53 this.locations = Collections.unmodifiableMap(mutableLocations);
54 }
55
56 /**
57 * For a plugin project (packaging is {@code maven-plugin}), the minimum version of
58 * Maven required to use the resulting plugin.<br>
59 * In Maven 2, this was also specifying the minimum version of Maven required to build a
60 * project, but this usage is <b>deprecated</b> in Maven 3 and not checked any more: use
61 * the <a href="https://maven.apache.org/enforcer/enforcer-rules/requireMavenVersion.html">Maven Enforcer Plugin's
62 * {@code requireMavenVersion} rule</a> instead.
63 *
64 * @return a {@code String}
65 */
66 public String getMaven() {
67 return this.maven;
68 }
69
70 /**
71 * Gets the location of the specified field in the input source.
72 */
73 public InputLocation getLocation(Object key) {
74 return locations != null ? locations.get(key) : null;
75 }
76
77 /**
78 * Gets the keys of the locations of the input source.
79 */
80 public Set<Object> getLocationKeys() {
81 return locations != null ? locations.keySet() : null;
82 }
83
84 /**
85 * Gets the input location that caused this model to be read.
86 */
87 public InputLocation getImportedFrom()
88 {
89 return importedFrom;
90 }
91
92 /**
93 * Creates a new builder with this object as the basis.
94 *
95 * @return a {@code Builder}
96 */
97 @Nonnull
98 public Builder with() {
99 return newBuilder(this);
100 }
101 /**
102 * Creates a new {@code Prerequisites} instance using the specified maven.
103 *
104 * @param maven the new {@code String} to use
105 * @return a {@code Prerequisites} with the specified maven
106 */
107 @Nonnull
108 public Prerequisites withMaven(String maven) {
109 return newBuilder(this, true).maven(maven).build();
110 }
111
112 /**
113 * Creates a new {@code Prerequisites} instance.
114 * Equivalent to {@code newInstance(true)}.
115 * @see #newInstance(boolean)
116 *
117 * @return a new {@code Prerequisites}
118 */
119 @Nonnull
120 public static Prerequisites newInstance() {
121 return newInstance(true);
122 }
123
124 /**
125 * Creates a new {@code Prerequisites} instance using default values or not.
126 * Equivalent to {@code newBuilder(withDefaults).build()}.
127 *
128 * @param withDefaults the boolean indicating whether default values should be used
129 * @return a new {@code Prerequisites}
130 */
131 @Nonnull
132 public static Prerequisites newInstance(boolean withDefaults) {
133 return newBuilder(withDefaults).build();
134 }
135
136 /**
137 * Creates a new {@code Prerequisites} builder instance.
138 * Equivalent to {@code newBuilder(true)}.
139 * @see #newBuilder(boolean)
140 *
141 * @return a new {@code Builder}
142 */
143 @Nonnull
144 public static Builder newBuilder() {
145 return newBuilder(true);
146 }
147
148 /**
149 * Creates a new {@code Prerequisites} builder instance using default values or not.
150 *
151 * @param withDefaults the boolean indicating whether default values should be used
152 * @return a new {@code Builder}
153 */
154 @Nonnull
155 public static Builder newBuilder(boolean withDefaults) {
156 return new Builder(withDefaults);
157 }
158
159 /**
160 * Creates a new {@code Prerequisites} builder instance using the specified object as a basis.
161 * Equivalent to {@code newBuilder(from, false)}.
162 *
163 * @param from the {@code Prerequisites} instance to use as a basis
164 * @return a new {@code Builder}
165 */
166 @Nonnull
167 public static Builder newBuilder(Prerequisites from) {
168 return newBuilder(from, false);
169 }
170
171 /**
172 * Creates a new {@code Prerequisites} builder instance using the specified object as a basis.
173 *
174 * @param from the {@code Prerequisites} instance to use as a basis
175 * @param forceCopy the boolean indicating if a copy should be forced
176 * @return a new {@code Builder}
177 */
178 @Nonnull
179 public static Builder newBuilder(Prerequisites from, boolean forceCopy) {
180 return new Builder(from, forceCopy);
181 }
182
183 /**
184 * Builder class used to create Prerequisites instances.
185 * @see #with()
186 * @see #newBuilder()
187 */
188 @NotThreadSafe
189 public static class Builder
190 {
191 Prerequisites base;
192 String maven;
193 Map<Object, InputLocation> locations;
194 InputLocation importedFrom;
195
196 protected Builder(boolean withDefaults) {
197 if (withDefaults) {
198 this.maven = "2.0";
199 }
200 }
201
202 protected Builder(Prerequisites base, boolean forceCopy) {
203 if (forceCopy) {
204 this.maven = base.maven;
205 this.locations = base.locations;
206 this.importedFrom = base.importedFrom;
207 } else {
208 this.base = base;
209 }
210 }
211
212 @Nonnull
213 public Builder maven(String maven) {
214 this.maven = maven;
215 return this;
216 }
217
218
219 @Nonnull
220 public Builder location(Object key, InputLocation location) {
221 if (location != null) {
222 if (!(this.locations instanceof HashMap)) {
223 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
224 }
225 this.locations.put(key, location);
226 }
227 return this;
228 }
229
230 @Nonnull
231 public Builder importedFrom(InputLocation importedFrom) {
232 this.importedFrom = importedFrom;
233 return this;
234 }
235
236 @Nonnull
237 public Prerequisites build() {
238 // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
239 if (base != null
240 && (maven == null || maven == base.maven)
241 ) {
242 return base;
243 }
244 return new Prerequisites(this);
245 }
246 }
247
248 }