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 {
47 this.id = id;
48 this.phases = ImmutableCollections.copy( phases );
49 }
50
51
52
53
54
55
56 public String getId()
57 {
58 return this.id;
59 }
60
61
62
63
64
65
66 @Nonnull
67 public List<Phase> getPhases()
68 {
69 return this.phases;
70 }
71
72
73
74
75
76
77 @Nonnull
78 public Builder with()
79 {
80 return newBuilder( this );
81 }
82
83
84
85
86
87
88 @Nonnull
89 public Lifecycle withId( String id )
90 {
91 return with().id( id ).build();
92 }
93
94
95
96
97
98
99 @Nonnull
100 public Lifecycle withPhases( Collection<Phase> phases )
101 {
102 return with().phases( phases ).build();
103 }
104
105
106
107
108
109
110
111
112 @Nonnull
113 public static Lifecycle newInstance()
114 {
115 return newInstance( true );
116 }
117
118
119
120
121
122
123
124
125 @Nonnull
126 public static Lifecycle newInstance( boolean withDefaults )
127 {
128 return newBuilder( withDefaults ).build();
129 }
130
131
132
133
134
135
136
137
138 @Nonnull
139 public static Builder newBuilder()
140 {
141 return newBuilder( true );
142 }
143
144
145
146
147
148
149
150 @Nonnull
151 public static Builder newBuilder( boolean withDefaults )
152 {
153 return new Builder( withDefaults );
154 }
155
156
157
158
159
160
161
162
163 @Nonnull
164 public static Builder newBuilder( Lifecycle from )
165 {
166 return newBuilder( from, false );
167 }
168
169
170
171
172
173
174
175
176 @Nonnull
177 public static Builder newBuilder( Lifecycle from, boolean forceCopy )
178 {
179 return new Builder( from, forceCopy );
180 }
181
182
183
184
185
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 }