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   * Root element of the {@code lifecycle.xml} file.
24   */
25  @Experimental
26  @Generated @ThreadSafe @Immutable
27  public class LifecycleConfiguration
28      implements Serializable
29  {
30      final String namespaceUri;
31      final String modelEncoding;
32      /**
33       */
34      final List<Lifecycle> lifecycles;
35  
36      /**
37        * Constructor for this class, to be called from its subclasses and {@link Builder}.
38        * @see Builder#build()
39        */
40      protected LifecycleConfiguration(Builder builder) {
41          this.namespaceUri = builder.namespaceUri != null ? builder.namespaceUri : (builder.base != null ? builder.base.namespaceUri : null);
42          this.modelEncoding = builder.modelEncoding != null ? builder.modelEncoding : (builder.base != null ? builder.base.modelEncoding :  "UTF-8");
43          this.lifecycles = ImmutableCollections.copy(builder.lifecycles != null ? builder.lifecycles : (builder.base != null ? builder.base.lifecycles : null));
44      }
45  
46      public String getNamespaceUri() {
47          return namespaceUri;
48      }
49  
50      public String getModelEncoding() {
51          return modelEncoding;
52      }
53  
54      /**
55       *
56       * @return a {@code List<Lifecycle>}
57       */
58      @Nonnull
59      public List<Lifecycle> getLifecycles() {
60          return this.lifecycles;
61      }
62  
63      /**
64       * Creates a new builder with this object as the basis.
65       *
66       * @return a {@code Builder}
67       */
68      @Nonnull
69      public Builder with() {
70          return newBuilder(this);
71      }
72      /**
73       * Creates a new {@code LifecycleConfiguration} instance using the specified lifecycles.
74       *
75       * @param lifecycles the new {@code Collection<Lifecycle>} to use
76       * @return a {@code LifecycleConfiguration} with the specified lifecycles
77       */
78      @Nonnull
79      public LifecycleConfiguration withLifecycles(Collection<Lifecycle> lifecycles) {
80          return newBuilder(this, true).lifecycles(lifecycles).build();
81      }
82  
83      /**
84       * Creates a new {@code LifecycleConfiguration} instance.
85       * Equivalent to {@code newInstance(true)}.
86       * @see #newInstance(boolean)
87       *
88       * @return a new {@code LifecycleConfiguration}
89       */
90      @Nonnull
91      public static LifecycleConfiguration newInstance() {
92          return newInstance(true);
93      }
94  
95      /**
96       * Creates a new {@code LifecycleConfiguration} instance using default values or not.
97       * Equivalent to {@code newBuilder(withDefaults).build()}.
98       *
99       * @param withDefaults the boolean indicating whether default values should be used
100      * @return a new {@code LifecycleConfiguration}
101      */
102     @Nonnull
103     public static LifecycleConfiguration newInstance(boolean withDefaults) {
104         return newBuilder(withDefaults).build();
105     }
106 
107     /**
108      * Creates a new {@code LifecycleConfiguration} builder instance.
109      * Equivalent to {@code newBuilder(true)}.
110      * @see #newBuilder(boolean)
111      *
112      * @return a new {@code Builder}
113      */
114     @Nonnull
115     public static Builder newBuilder() {
116         return newBuilder(true);
117     }
118 
119     /**
120      * Creates a new {@code LifecycleConfiguration} builder instance using default values or not.
121      *
122      * @param withDefaults the boolean indicating whether default values should be used
123      * @return a new {@code Builder}
124      */
125     @Nonnull
126     public static Builder newBuilder(boolean withDefaults) {
127         return new Builder(withDefaults);
128     }
129 
130     /**
131      * Creates a new {@code LifecycleConfiguration} builder instance using the specified object as a basis.
132      * Equivalent to {@code newBuilder(from, false)}.
133      *
134      * @param from the {@code LifecycleConfiguration} instance to use as a basis
135      * @return a new {@code Builder}
136      */
137     @Nonnull
138     public static Builder newBuilder(LifecycleConfiguration from) {
139         return newBuilder(from, false);
140     }
141 
142     /**
143      * Creates a new {@code LifecycleConfiguration} builder instance using the specified object as a basis.
144      *
145      * @param from the {@code LifecycleConfiguration} instance to use as a basis
146      * @param forceCopy the boolean indicating if a copy should be forced
147      * @return a new {@code Builder}
148      */
149     @Nonnull
150     public static Builder newBuilder(LifecycleConfiguration from, boolean forceCopy) {
151         return new Builder(from, forceCopy);
152     }
153 
154     /**
155      * Builder class used to create LifecycleConfiguration instances.
156      * @see #with()
157      * @see #newBuilder()
158      */
159     @NotThreadSafe
160     public static class Builder
161     {
162         LifecycleConfiguration base;
163         String namespaceUri;
164         String modelEncoding;
165         Collection<Lifecycle> lifecycles;
166 
167         protected Builder(boolean withDefaults) {
168             if (withDefaults) {
169             }
170         }
171 
172         protected Builder(LifecycleConfiguration base, boolean forceCopy) {
173             this.namespaceUri = base.namespaceUri;
174             this.modelEncoding = base.modelEncoding;
175             if (forceCopy) {
176                 this.lifecycles = base.lifecycles;
177             } else {
178                 this.base = base;
179             }
180         }
181 
182         @Nonnull
183         public Builder namespaceUri(String namespaceUri) {
184             this.namespaceUri = namespaceUri;
185             return this;
186         }
187 
188         @Nonnull
189         public Builder modelEncoding(String modelEncoding) {
190             this.modelEncoding = modelEncoding;
191             return this;
192         }
193 
194         @Nonnull
195         public Builder lifecycles(Collection<Lifecycle> lifecycles) {
196             this.lifecycles = lifecycles;
197             return this;
198         }
199 
200 
201         @Nonnull
202         public LifecycleConfiguration build() {
203             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
204             if (base != null
205                     && (lifecycles == null || lifecycles == base.lifecycles)
206             ) {
207                 return base;
208             }
209             return new LifecycleConfiguration(this);
210         }
211     }
212 
213 }