1 // =================== DO NOT EDIT THIS FILE ====================
2 // Generated by Maven, any modifications will be overwritten.
3 // ==============================================================
4 package org.apache.maven.api.model;
5
6 import java.io.Serializable;
7 import java.util.Collections;
8 import java.util.HashMap;
9 import java.util.Map;
10 import org.apache.maven.api.annotations.Experimental;
11 import org.apache.maven.api.annotations.Generated;
12 import org.apache.maven.api.annotations.Immutable;
13 import org.apache.maven.api.annotations.Nonnull;
14 import org.apache.maven.api.annotations.NotThreadSafe;
15 import org.apache.maven.api.annotations.ThreadSafe;
16
17 /**
18 * Describes the prerequisites a project can have.
19 */
20 @Experimental
21 @Generated @ThreadSafe @Immutable
22 public class Prerequisites
23 implements Serializable, InputLocationTracker
24 {
25 /**
26 * For a plugin project (packaging is {@code maven-plugin}), the minimum version of
27 * Maven required to use the resulting plugin.<br>
28 * In Maven 2, this was also specifying the minimum version of Maven required to build a
29 * project, but this usage is <b>deprecated</b> in Maven 3 and not checked any more: use
30 * the <a href="https://maven.apache.org/enforcer/enforcer-rules/requireMavenVersion.html">Maven Enforcer Plugin's
31 * {@code requireMavenVersion} rule</a> instead.
32 */
33 final String maven;
34 /** Location of the xml element for this object. */
35 final InputLocation location;
36 /** Location of the xml element for the field maven. */
37 final InputLocation mavenLocation;
38 /** Other locations */
39 final Map<Object, InputLocation> locations;
40
41 /**
42 * Constructor for this class, package protected.
43 * @see Builder#build()
44 */
45 Prerequisites(
46 String maven,
47 Map<Object, InputLocation> locations,
48 InputLocation location,
49 InputLocation mavenLocation
50 )
51 {
52 this.maven = maven;
53 this.locations = ImmutableCollections.copy( locations );
54 this.location = location;
55 this.mavenLocation = mavenLocation;
56 }
57
58 /**
59 * For a plugin project (packaging is {@code maven-plugin}), the minimum version of
60 * Maven required to use the resulting plugin.<br>
61 * In Maven 2, this was also specifying the minimum version of Maven required to build a
62 * project, but this usage is <b>deprecated</b> in Maven 3 and not checked any more: use
63 * the <a href="https://maven.apache.org/enforcer/enforcer-rules/requireMavenVersion.html">Maven Enforcer Plugin's
64 * {@code requireMavenVersion} rule</a> instead.
65 *
66 * @return a {@code String}
67 */
68 public String getMaven()
69 {
70 return this.maven;
71 }
72
73 /**
74 * Gets the location of the specified field in the input source.
75 */
76 public InputLocation getLocation( Object key )
77 {
78 if ( key instanceof String )
79 {
80 switch ( ( String ) key )
81 {
82 case "":
83 return location;
84 case "maven":
85 return mavenLocation;
86 }
87 }
88 return locations != null ? locations.get( key ) : null;
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 {
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 {
110 return with().maven( maven ).build();
111 }
112
113 /**
114 * Creates a new {@code Prerequisites} instance.
115 * Equivalent to {@code newInstance( true )}.
116 * @see #newInstance(boolean)
117 *
118 * @return a new {@code Prerequisites}
119 */
120 @Nonnull
121 public static Prerequisites newInstance()
122 {
123 return newInstance( true );
124 }
125
126 /**
127 * Creates a new {@code Prerequisites} instance using default values or not.
128 * Equivalent to {@code newBuilder( withDefaults ).build()}.
129 *
130 * @param withDefaults the boolean indicating whether default values should be used
131 * @return a new {@code Prerequisites}
132 */
133 @Nonnull
134 public static Prerequisites newInstance( boolean withDefaults )
135 {
136 return newBuilder( withDefaults ).build();
137 }
138
139 /**
140 * Creates a new {@code Prerequisites} builder instance.
141 * Equivalent to {@code newBuilder( true )}.
142 * @see #newBuilder(boolean)
143 *
144 * @return a new {@code Builder}
145 */
146 @Nonnull
147 public static Builder newBuilder()
148 {
149 return newBuilder( true );
150 }
151
152 /**
153 * Creates a new {@code Prerequisites} builder instance using default values or not.
154 *
155 * @param withDefaults the boolean indicating whether default values should be used
156 * @return a new {@code Builder}
157 */
158 @Nonnull
159 public static Builder newBuilder( boolean withDefaults )
160 {
161 return new Builder( withDefaults );
162 }
163
164 /**
165 * Creates a new {@code Prerequisites} builder instance using the specified object as a basis.
166 * Equivalent to {@code newBuilder( from, false )}.
167 *
168 * @param from the {@code Prerequisites} instance to use as a basis
169 * @return a new {@code Builder}
170 */
171 @Nonnull
172 public static Builder newBuilder( Prerequisites from )
173 {
174 return newBuilder( from, false );
175 }
176
177 /**
178 * Creates a new {@code Prerequisites} builder instance using the specified object as a basis.
179 *
180 * @param from the {@code Prerequisites} instance to use as a basis
181 * @param forceCopy the boolean indicating if a copy should be forced
182 * @return a new {@code Builder}
183 */
184 @Nonnull
185 public static Builder newBuilder( Prerequisites from, boolean forceCopy )
186 {
187 return new Builder( from, forceCopy );
188 }
189
190 /**
191 * Builder class used to create Prerequisites instances.
192 * @see #with()
193 * @see #newBuilder()
194 */
195 @NotThreadSafe
196 public static class Builder
197 {
198 Prerequisites base;
199 String maven;
200 Map<Object, InputLocation> locations;
201
202 Builder( boolean withDefaults )
203 {
204 if ( withDefaults )
205 {
206 this.maven = "2.0";
207 }
208 }
209
210 Builder( Prerequisites base, boolean forceCopy )
211 {
212 if ( forceCopy )
213 {
214 this.maven = base.maven;
215 }
216 else
217 {
218 this.base = base;
219 }
220 }
221
222 @Nonnull
223 public Builder maven( String maven )
224 {
225 this.maven = maven;
226 return this;
227 }
228
229
230 @Nonnull
231 public Builder location( Object key, InputLocation location )
232 {
233 if ( location != null )
234 {
235 if ( this.locations == null )
236 {
237 this.locations = new HashMap<>();
238 }
239 this.locations.put( key, location );
240 }
241 return this;
242 }
243
244 @Nonnull
245 public Prerequisites build()
246 {
247 if ( base != null
248 && ( maven == null || maven == base.maven )
249 )
250 {
251 return base;
252 }
253 Map<Object, InputLocation> locations = null;
254 InputLocation location = null;
255 InputLocation mavenLocation = null;
256 if ( this.locations != null )
257 {
258 locations = this.locations;
259 location = locations.remove( "" );
260 mavenLocation = locations.remove( "maven" );
261 }
262 return new Prerequisites(
263 maven != null ? maven : ( base != null ? base.maven : null ),
264 locations != null ? locations : ( base != null ? base.locations : null ),
265 location != null ? location : ( base != null ? base.location : null ),
266 mavenLocation != null ? mavenLocation : ( base != null ? base.mavenLocation : null )
267 );
268 }
269 }
270
271 }