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