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