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