1
2
3
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
23
24 @Experimental
25 @Generated @ThreadSafe @Immutable
26 public class Lifecycle
27 implements Serializable
28 {
29
30
31
32 final String id;
33
34
35
36 final List<Phase> phases;
37
38
39
40
41
42 Lifecycle(
43 String id,
44 Collection<Phase> phases
45 ) {
46 this.id = id;
47 this.phases = ImmutableCollections.copy(phases);
48 }
49
50
51
52
53
54
55 public String getId() {
56 return this.id;
57 }
58
59
60
61
62
63
64 @Nonnull
65 public List<Phase> getPhases() {
66 return this.phases;
67 }
68
69
70
71
72
73
74 @Nonnull
75 public Builder with() {
76 return newBuilder(this);
77 }
78
79
80
81
82
83
84 @Nonnull
85 public Lifecycle withId(String id) {
86 return newBuilder(this, true).id(id).build();
87 }
88
89
90
91
92
93
94 @Nonnull
95 public Lifecycle withPhases(Collection<Phase> phases) {
96 return newBuilder(this, true).phases(phases).build();
97 }
98
99
100
101
102
103
104
105
106 @Nonnull
107 public static Lifecycle newInstance() {
108 return newInstance(true);
109 }
110
111
112
113
114
115
116
117
118 @Nonnull
119 public static Lifecycle newInstance(boolean withDefaults) {
120 return newBuilder(withDefaults).build();
121 }
122
123
124
125
126
127
128
129
130 @Nonnull
131 public static Builder newBuilder() {
132 return newBuilder(true);
133 }
134
135
136
137
138
139
140
141 @Nonnull
142 public static Builder newBuilder(boolean withDefaults) {
143 return new Builder(withDefaults);
144 }
145
146
147
148
149
150
151
152
153 @Nonnull
154 public static Builder newBuilder(Lifecycle from) {
155 return newBuilder(from, false);
156 }
157
158
159
160
161
162
163
164
165 @Nonnull
166 public static Builder newBuilder(Lifecycle from, boolean forceCopy) {
167 return new Builder(from, forceCopy);
168 }
169
170
171
172
173
174
175 @NotThreadSafe
176 public static class Builder
177 {
178 Lifecycle base;
179 String id;
180 Collection<Phase> phases;
181
182 Builder(boolean withDefaults) {
183 if (withDefaults) {
184 }
185 }
186
187 Builder(Lifecycle base, boolean forceCopy) {
188 if (forceCopy) {
189 this.id = base.id;
190 this.phases = base.phases;
191 } else {
192 this.base = base;
193 }
194 }
195
196 @Nonnull
197 public Builder id(String id) {
198 this.id = id;
199 return this;
200 }
201
202 @Nonnull
203 public Builder phases(Collection<Phase> phases) {
204 this.phases = phases;
205 return this;
206 }
207
208
209 @Nonnull
210 public Lifecycle build() {
211 if (base != null
212 && (id == null || id == base.id)
213 && (phases == null || phases == base.phases)
214 ) {
215 return base;
216 }
217 return new Lifecycle(
218 id != null ? id : (base != null ? base.id : null),
219 phases != null ? phases : (base != null ? base.phases : null)
220 );
221 }
222 }
223
224 }