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