View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //   Generated by Maven, any modifications will be overwritten.
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   * A custom lifecycle mapping definition.
21   */
22  @Generated @ThreadSafe @Immutable
23  public class Lifecycle
24      implements Serializable
25  {
26      /**
27       * The ID of this lifecycle, for identification in the mojo descriptor.
28       */
29      final String id;
30      /**
31       * The phase mappings for this lifecycle.
32       */
33      final List<Phase> phases;
34  
35      /**
36        * Constructor for this class, package protected.
37        * @see Builder#build()
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       * The ID of this lifecycle, for identification in the mojo descriptor.
50       */
51      public String getId()
52      {
53          return this.id;
54      }
55  
56      /**
57       * The phase mappings for this lifecycle.
58       */
59      @Nonnull
60      public List<Phase> getPhases()
61      {
62          return this.phases;
63      }
64  
65      /**
66       * Creates a new builder with this object as the basis.
67       */
68      @Nonnull
69      public Builder with()
70      {
71          return newBuilder( this );
72      }
73      /** Creates a new Lifecycle instance using the specified id. */
74      @Nonnull
75      public Lifecycle withId( String id )
76      {
77          return with().id( id ).build();
78      }
79      /** Creates a new Lifecycle instance using the specified phases. */
80      @Nonnull
81      public Lifecycle withPhases( Collection<Phase> phases )
82      {
83          return with().phases( phases ).build();
84      }
85  
86      /**
87       * Creates a new Lifecycle instance.
88       * Equivalent to {@code newInstance( true )}.
89       * @see #newInstance(boolean)
90       */
91      @Nonnull
92      public static Lifecycle newInstance()
93      {
94          return newInstance( true );
95      }
96  
97      /**
98       * Creates a new Lifecycle instance using default values or not.
99       * Equivalent to {@code newBuilder( withDefaults ).build()}.
100      */
101     @Nonnull
102     public static Lifecycle newInstance( boolean withDefaults )
103     {
104         return newBuilder( withDefaults ).build();
105     }
106 
107     /**
108      * Creates a new Lifecycle builder instance.
109      * Equivalent to {@code newBuilder( true )}.
110      * @see #newBuilder(boolean)
111      */
112     @Nonnull
113     public static Builder newBuilder()
114     {
115         return newBuilder( true );
116     }
117 
118     /**
119      * Creates a new Lifecycle builder instance using default values or not.
120      */
121     @Nonnull
122     public static Builder newBuilder( boolean withDefaults )
123     {
124         return new Builder( withDefaults );
125     }
126 
127     /**
128      * Creates a new Lifecycle builder instance using the specified object as a basis.
129      * Equivalent to {@code newBuilder( from, false )}.
130      */
131     @Nonnull
132     public static Builder newBuilder( Lifecycle from )
133     {
134         return newBuilder( from, false );
135     }
136 
137     /**
138      * Creates a new Lifecycle builder instance using the specified object as a basis.
139      */
140     @Nonnull
141     public static Builder newBuilder( Lifecycle from, boolean forceCopy )
142     {
143         return new Builder( from, forceCopy );
144     }
145 
146     /**
147      * Builder class used to create Lifecycle instances.
148      * @see #with()
149      * @see #newBuilder()
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 }