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