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.plugin.descriptor.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 java.util.Objects;
15 import java.util.Optional;
16 import java.util.Set;
17 import java.util.stream.Collectors;
18 import java.util.stream.Stream;
19 import org.apache.maven.api.annotations.Experimental;
20 import org.apache.maven.api.annotations.Generated;
21 import org.apache.maven.api.annotations.Immutable;
22 import org.apache.maven.api.annotations.Nonnull;
23 import org.apache.maven.api.annotations.NotThreadSafe;
24 import org.apache.maven.api.annotations.ThreadSafe;
25
26 /**
27 * A custom lifecycle mapping definition.
28 */
29 @Experimental
30 @Generated @ThreadSafe @Immutable
31 public class Lifecycle
32 implements Serializable
33 {
34 /**
35 * The ID of this lifecycle, for identification in the mojo descriptor.
36 */
37 final String id;
38 /**
39 * The phase mappings for this lifecycle.
40 */
41 final List<Phase> phases;
42
43 /**
44 * Constructor for this class, to be called from its subclasses and {@link Builder}.
45 * @see Builder#build()
46 */
47 protected Lifecycle(Builder builder) {
48 this.id = builder.id != null ? builder.id : (builder.base != null ? builder.base.id : null);
49 this.phases = ImmutableCollections.copy(builder.phases != null ? builder.phases : (builder.base != null ? builder.base.phases : null));
50 }
51
52 /**
53 * The ID of this lifecycle, for identification in the mojo descriptor.
54 *
55 * @return a {@code String}
56 */
57 public String getId() {
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 return this.phases;
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 Lifecycle} instance using the specified id.
82 *
83 * @param id the new {@code String} to use
84 * @return a {@code Lifecycle} with the specified id
85 */
86 @Nonnull
87 public Lifecycle withId(String id) {
88 return newBuilder(this, true).id(id).build();
89 }
90 /**
91 * Creates a new {@code Lifecycle} instance using the specified phases.
92 *
93 * @param phases the new {@code Collection<Phase>} to use
94 * @return a {@code Lifecycle} with the specified phases
95 */
96 @Nonnull
97 public Lifecycle withPhases(Collection<Phase> phases) {
98 return newBuilder(this, true).phases(phases).build();
99 }
100
101 /**
102 * Creates a new {@code Lifecycle} instance.
103 * Equivalent to {@code newInstance(true)}.
104 * @see #newInstance(boolean)
105 *
106 * @return a new {@code Lifecycle}
107 */
108 @Nonnull
109 public static Lifecycle newInstance() {
110 return newInstance(true);
111 }
112
113 /**
114 * Creates a new {@code Lifecycle} instance using default values or not.
115 * Equivalent to {@code newBuilder(withDefaults).build()}.
116 *
117 * @param withDefaults the boolean indicating whether default values should be used
118 * @return a new {@code Lifecycle}
119 */
120 @Nonnull
121 public static Lifecycle newInstance(boolean withDefaults) {
122 return newBuilder(withDefaults).build();
123 }
124
125 /**
126 * Creates a new {@code Lifecycle} builder instance.
127 * Equivalent to {@code newBuilder(true)}.
128 * @see #newBuilder(boolean)
129 *
130 * @return a new {@code Builder}
131 */
132 @Nonnull
133 public static Builder newBuilder() {
134 return newBuilder(true);
135 }
136
137 /**
138 * Creates a new {@code Lifecycle} builder instance using default values or not.
139 *
140 * @param withDefaults the boolean indicating whether default values should be used
141 * @return a new {@code Builder}
142 */
143 @Nonnull
144 public static Builder newBuilder(boolean withDefaults) {
145 return new Builder(withDefaults);
146 }
147
148 /**
149 * Creates a new {@code Lifecycle} builder instance using the specified object as a basis.
150 * Equivalent to {@code newBuilder(from, false)}.
151 *
152 * @param from the {@code Lifecycle} instance to use as a basis
153 * @return a new {@code Builder}
154 */
155 @Nonnull
156 public static Builder newBuilder(Lifecycle from) {
157 return newBuilder(from, false);
158 }
159
160 /**
161 * Creates a new {@code Lifecycle} builder instance using the specified object as a basis.
162 *
163 * @param from the {@code Lifecycle} instance to use as a basis
164 * @param forceCopy the boolean indicating if a copy should be forced
165 * @return a new {@code Builder}
166 */
167 @Nonnull
168 public static Builder newBuilder(Lifecycle from, boolean forceCopy) {
169 return new Builder(from, forceCopy);
170 }
171
172 /**
173 * Builder class used to create Lifecycle instances.
174 * @see #with()
175 * @see #newBuilder()
176 */
177 @NotThreadSafe
178 public static class Builder
179 {
180 Lifecycle base;
181 String id;
182 Collection<Phase> phases;
183
184 protected Builder(boolean withDefaults) {
185 if (withDefaults) {
186 }
187 }
188
189 protected Builder(Lifecycle base, boolean forceCopy) {
190 if (forceCopy) {
191 this.id = base.id;
192 this.phases = base.phases;
193 } else {
194 this.base = base;
195 }
196 }
197
198 @Nonnull
199 public Builder id(String id) {
200 this.id = id;
201 return this;
202 }
203
204 @Nonnull
205 public Builder phases(Collection<Phase> phases) {
206 this.phases = phases;
207 return this;
208 }
209
210
211 @Nonnull
212 public Lifecycle build() {
213 // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
214 if (base != null
215 && (id == null || id == base.id)
216 && (phases == null || phases == base.phases)
217 ) {
218 return base;
219 }
220 return new Lifecycle(this);
221 }
222
223 }
224
225 }