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