View Javadoc
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 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   * A custom lifecycle mapping definition.
23   */
24  @Experimental
25  @Generated @ThreadSafe @Immutable
26  public class Lifecycle
27      implements Serializable
28  {
29      /**
30       * The ID of this lifecycle, for identification in the mojo descriptor.
31       */
32      final String id;
33      /**
34       * The phase mappings for this lifecycle.
35       */
36      final List<Phase> phases;
37  
38      /**
39        * Constructor for this class, package protected.
40        * @see Builder#build()
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       * The ID of this lifecycle, for identification in the mojo descriptor.
52       *
53       * @return a {@code String}
54       */
55      public String getId() {
56          return this.id;
57      }
58  
59      /**
60       * The phase mappings for this lifecycle.
61       *
62       * @return a {@code List<Phase>}
63       */
64      @Nonnull
65      public List<Phase> getPhases() {
66          return this.phases;
67      }
68  
69      /**
70       * Creates a new builder with this object as the basis.
71       *
72       * @return a {@code Builder}
73       */
74      @Nonnull
75      public Builder with() {
76          return newBuilder(this);
77      }
78      /**
79       * Creates a new {@code Lifecycle} instance using the specified id.
80       *
81       * @param id the new {@code String} to use
82       * @return a {@code Lifecycle} with the specified id
83       */
84      @Nonnull
85      public Lifecycle withId(String id) {
86          return newBuilder(this, true).id(id).build();
87      }
88      /**
89       * Creates a new {@code Lifecycle} instance using the specified phases.
90       *
91       * @param phases the new {@code Collection<Phase>} to use
92       * @return a {@code Lifecycle} with the specified phases
93       */
94      @Nonnull
95      public Lifecycle withPhases(Collection<Phase> phases) {
96          return newBuilder(this, true).phases(phases).build();
97      }
98  
99      /**
100      * Creates a new {@code Lifecycle} instance.
101      * Equivalent to {@code newInstance(true)}.
102      * @see #newInstance(boolean)
103      *
104      * @return a new {@code Lifecycle}
105      */
106     @Nonnull
107     public static Lifecycle newInstance() {
108         return newInstance(true);
109     }
110 
111     /**
112      * Creates a new {@code Lifecycle} instance using default values or not.
113      * Equivalent to {@code newBuilder(withDefaults).build()}.
114      *
115      * @param withDefaults the boolean indicating whether default values should be used
116      * @return a new {@code Lifecycle}
117      */
118     @Nonnull
119     public static Lifecycle newInstance(boolean withDefaults) {
120         return newBuilder(withDefaults).build();
121     }
122 
123     /**
124      * Creates a new {@code Lifecycle} builder instance.
125      * Equivalent to {@code newBuilder(true)}.
126      * @see #newBuilder(boolean)
127      *
128      * @return a new {@code Builder}
129      */
130     @Nonnull
131     public static Builder newBuilder() {
132         return newBuilder(true);
133     }
134 
135     /**
136      * Creates a new {@code Lifecycle} builder instance using default values or not.
137      *
138      * @param withDefaults the boolean indicating whether default values should be used
139      * @return a new {@code Builder}
140      */
141     @Nonnull
142     public static Builder newBuilder(boolean withDefaults) {
143         return new Builder(withDefaults);
144     }
145 
146     /**
147      * Creates a new {@code Lifecycle} builder instance using the specified object as a basis.
148      * Equivalent to {@code newBuilder(from, false)}.
149      *
150      * @param from the {@code Lifecycle} instance to use as a basis
151      * @return a new {@code Builder}
152      */
153     @Nonnull
154     public static Builder newBuilder(Lifecycle from) {
155         return newBuilder(from, false);
156     }
157 
158     /**
159      * Creates a new {@code Lifecycle} builder instance using the specified object as a basis.
160      *
161      * @param from the {@code Lifecycle} instance to use as a basis
162      * @param forceCopy the boolean indicating if a copy should be forced
163      * @return a new {@code Builder}
164      */
165     @Nonnull
166     public static Builder newBuilder(Lifecycle from, boolean forceCopy) {
167         return new Builder(from, forceCopy);
168     }
169 
170     /**
171      * Builder class used to create Lifecycle instances.
172      * @see #with()
173      * @see #newBuilder()
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 }