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.plugin.lifecycle;
6
7 import java.io.Serializable;
8 import java.util.ArrayList;
9 import java.util.Collection;
10 import java.util.Collections;
11 import java.util.HashMap;
12 import java.util.List;
13 import java.util.Map;
14 import org.apache.maven.api.annotations.Experimental;
15 import org.apache.maven.api.annotations.Generated;
16 import org.apache.maven.api.annotations.Immutable;
17 import org.apache.maven.api.annotations.Nonnull;
18 import org.apache.maven.api.annotations.NotThreadSafe;
19 import org.apache.maven.api.annotations.ThreadSafe;
20 import org.apache.maven.api.xml.XmlNode;
21
22 /**
23 * A phase mapping definition.
24 */
25 @Experimental
26 @Generated @ThreadSafe @Immutable
27 public class Phase
28 implements Serializable
29 {
30 /**
31 * The ID of this phase, e.g., <code>generate-sources</code>.
32 */
33 final String id;
34 /**
35 * The goals to execute within the phase.
36 */
37 final List<Execution> executions;
38 /**
39 * Configuration to pass to all goals run in this phase.
40 */
41 final XmlNode configuration;
42
43 /**
44 * Constructor for this class, package protected.
45 * @see Builder#build()
46 */
47 Phase(
48 String id,
49 Collection<Execution> executions,
50 XmlNode configuration
51 ) {
52 this.id = id;
53 this.executions = ImmutableCollections.copy(executions);
54 this.configuration = configuration;
55 }
56
57 /**
58 * The ID of this phase, e.g., <code>generate-sources</code>.
59 *
60 * @return a {@code String}
61 */
62 public String getId() {
63 return this.id;
64 }
65
66 /**
67 * The goals to execute within the phase.
68 *
69 * @return a {@code List<Execution>}
70 */
71 @Nonnull
72 public List<Execution> getExecutions() {
73 return this.executions;
74 }
75
76 /**
77 * Configuration to pass to all goals run in this phase.
78 *
79 * @return a {@code XmlNode}
80 */
81 public XmlNode getConfiguration() {
82 return this.configuration;
83 }
84
85 /**
86 * Creates a new builder with this object as the basis.
87 *
88 * @return a {@code Builder}
89 */
90 @Nonnull
91 public Builder with() {
92 return newBuilder(this);
93 }
94 /**
95 * Creates a new {@code Phase} instance using the specified id.
96 *
97 * @param id the new {@code String} to use
98 * @return a {@code Phase} with the specified id
99 */
100 @Nonnull
101 public Phase withId(String id) {
102 return newBuilder(this, true).id(id).build();
103 }
104 /**
105 * Creates a new {@code Phase} instance using the specified executions.
106 *
107 * @param executions the new {@code Collection<Execution>} to use
108 * @return a {@code Phase} with the specified executions
109 */
110 @Nonnull
111 public Phase withExecutions(Collection<Execution> executions) {
112 return newBuilder(this, true).executions(executions).build();
113 }
114 /**
115 * Creates a new {@code Phase} instance using the specified configuration.
116 *
117 * @param configuration the new {@code XmlNode} to use
118 * @return a {@code Phase} with the specified configuration
119 */
120 @Nonnull
121 public Phase withConfiguration(XmlNode configuration) {
122 return newBuilder(this, true).configuration(configuration).build();
123 }
124
125 /**
126 * Creates a new {@code Phase} instance.
127 * Equivalent to {@code newInstance(true)}.
128 * @see #newInstance(boolean)
129 *
130 * @return a new {@code Phase}
131 */
132 @Nonnull
133 public static Phase newInstance() {
134 return newInstance(true);
135 }
136
137 /**
138 * Creates a new {@code Phase} instance using default values or not.
139 * Equivalent to {@code newBuilder(withDefaults).build()}.
140 *
141 * @param withDefaults the boolean indicating whether default values should be used
142 * @return a new {@code Phase}
143 */
144 @Nonnull
145 public static Phase newInstance(boolean withDefaults) {
146 return newBuilder(withDefaults).build();
147 }
148
149 /**
150 * Creates a new {@code Phase} builder instance.
151 * Equivalent to {@code newBuilder(true)}.
152 * @see #newBuilder(boolean)
153 *
154 * @return a new {@code Builder}
155 */
156 @Nonnull
157 public static Builder newBuilder() {
158 return newBuilder(true);
159 }
160
161 /**
162 * Creates a new {@code Phase} builder instance using default values or not.
163 *
164 * @param withDefaults the boolean indicating whether default values should be used
165 * @return a new {@code Builder}
166 */
167 @Nonnull
168 public static Builder newBuilder(boolean withDefaults) {
169 return new Builder(withDefaults);
170 }
171
172 /**
173 * Creates a new {@code Phase} builder instance using the specified object as a basis.
174 * Equivalent to {@code newBuilder(from, false)}.
175 *
176 * @param from the {@code Phase} instance to use as a basis
177 * @return a new {@code Builder}
178 */
179 @Nonnull
180 public static Builder newBuilder(Phase from) {
181 return newBuilder(from, false);
182 }
183
184 /**
185 * Creates a new {@code Phase} builder instance using the specified object as a basis.
186 *
187 * @param from the {@code Phase} instance to use as a basis
188 * @param forceCopy the boolean indicating if a copy should be forced
189 * @return a new {@code Builder}
190 */
191 @Nonnull
192 public static Builder newBuilder(Phase from, boolean forceCopy) {
193 return new Builder(from, forceCopy);
194 }
195
196 /**
197 * Builder class used to create Phase instances.
198 * @see #with()
199 * @see #newBuilder()
200 */
201 @NotThreadSafe
202 public static class Builder
203 {
204 Phase base;
205 String id;
206 Collection<Execution> executions;
207 XmlNode configuration;
208
209 Builder(boolean withDefaults) {
210 if (withDefaults) {
211 }
212 }
213
214 Builder(Phase base, boolean forceCopy) {
215 if (forceCopy) {
216 this.id = base.id;
217 this.executions = base.executions;
218 this.configuration = base.configuration;
219 } else {
220 this.base = base;
221 }
222 }
223
224 @Nonnull
225 public Builder id(String id) {
226 this.id = id;
227 return this;
228 }
229
230 @Nonnull
231 public Builder executions(Collection<Execution> executions) {
232 this.executions = executions;
233 return this;
234 }
235
236 @Nonnull
237 public Builder configuration(XmlNode configuration) {
238 this.configuration = configuration;
239 return this;
240 }
241
242
243 @Nonnull
244 public Phase build() {
245 if (base != null
246 && (id == null || id == base.id)
247 && (executions == null || executions == base.executions)
248 && (configuration == null || configuration == base.configuration)
249 ) {
250 return base;
251 }
252 return new Phase(
253 id != null ? id : (base != null ? base.id : null),
254 executions != null ? executions : (base != null ? base.executions : null),
255 configuration != null ? configuration : (base != null ? base.configuration : null)
256 );
257 }
258 }
259
260 }