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