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 org.apache.maven.api.annotations.Experimental;
15  import org.apache.maven.api.annotations.Generated;
16  import org.apache.maven.api.annotations.Immutable;
17  import org.apache.maven.api.annotations.Nonnull;
18  import org.apache.maven.api.annotations.NotThreadSafe;
19  import org.apache.maven.api.annotations.ThreadSafe;
20  import org.apache.maven.api.xml.XmlNode;
21  
22  /**
23   * A set of goals to execute.
24   */
25  @Experimental
26  @Generated @ThreadSafe @Immutable
27  public class Execution
28      implements Serializable
29  {
30      /**
31       * Configuration to pass to the goals.
32       */
33      final XmlNode configuration;
34      /**
35       * The goals to execute.
36       */
37      final List<String> goals;
38  
39      /**
40        * Constructor for this class, package protected.
41        * @see Builder#build()
42        */
43      Execution(
44          XmlNode configuration,
45          Collection<String> goals
46      ) {
47          this.configuration = configuration;
48          this.goals = ImmutableCollections.copy(goals);
49      }
50  
51      /**
52       * Configuration to pass to the goals.
53       *
54       * @return a {@code XmlNode}
55       */
56      public XmlNode getConfiguration() {
57          return this.configuration;
58      }
59  
60      /**
61       * The goals to execute.
62       *
63       * @return a {@code List<String>}
64       */
65      @Nonnull
66      public List<String> getGoals() {
67          return this.goals;
68      }
69  
70      /**
71       * Creates a new builder with this object as the basis.
72       *
73       * @return a {@code Builder}
74       */
75      @Nonnull
76      public Builder with() {
77          return newBuilder(this);
78      }
79      /**
80       * Creates a new {@code Execution} instance using the specified configuration.
81       *
82       * @param configuration the new {@code XmlNode} to use
83       * @return a {@code Execution} with the specified configuration
84       */
85      @Nonnull
86      public Execution withConfiguration(XmlNode configuration) {
87          return newBuilder(this, true).configuration(configuration).build();
88      }
89      /**
90       * Creates a new {@code Execution} instance using the specified goals.
91       *
92       * @param goals the new {@code Collection<String>} to use
93       * @return a {@code Execution} with the specified goals
94       */
95      @Nonnull
96      public Execution withGoals(Collection<String> goals) {
97          return newBuilder(this, true).goals(goals).build();
98      }
99  
100     /**
101      * Creates a new {@code Execution} instance.
102      * Equivalent to {@code newInstance(true)}.
103      * @see #newInstance(boolean)
104      *
105      * @return a new {@code Execution}
106      */
107     @Nonnull
108     public static Execution newInstance() {
109         return newInstance(true);
110     }
111 
112     /**
113      * Creates a new {@code Execution} instance using default values or not.
114      * Equivalent to {@code newBuilder(withDefaults).build()}.
115      *
116      * @param withDefaults the boolean indicating whether default values should be used
117      * @return a new {@code Execution}
118      */
119     @Nonnull
120     public static Execution newInstance(boolean withDefaults) {
121         return newBuilder(withDefaults).build();
122     }
123 
124     /**
125      * Creates a new {@code Execution} builder instance.
126      * Equivalent to {@code newBuilder(true)}.
127      * @see #newBuilder(boolean)
128      *
129      * @return a new {@code Builder}
130      */
131     @Nonnull
132     public static Builder newBuilder() {
133         return newBuilder(true);
134     }
135 
136     /**
137      * Creates a new {@code Execution} builder instance using default values or not.
138      *
139      * @param withDefaults the boolean indicating whether default values should be used
140      * @return a new {@code Builder}
141      */
142     @Nonnull
143     public static Builder newBuilder(boolean withDefaults) {
144         return new Builder(withDefaults);
145     }
146 
147     /**
148      * Creates a new {@code Execution} builder instance using the specified object as a basis.
149      * Equivalent to {@code newBuilder(from, false)}.
150      *
151      * @param from the {@code Execution} instance to use as a basis
152      * @return a new {@code Builder}
153      */
154     @Nonnull
155     public static Builder newBuilder(Execution from) {
156         return newBuilder(from, false);
157     }
158 
159     /**
160      * Creates a new {@code Execution} builder instance using the specified object as a basis.
161      *
162      * @param from the {@code Execution} instance to use as a basis
163      * @param forceCopy the boolean indicating if a copy should be forced
164      * @return a new {@code Builder}
165      */
166     @Nonnull
167     public static Builder newBuilder(Execution from, boolean forceCopy) {
168         return new Builder(from, forceCopy);
169     }
170 
171     /**
172      * Builder class used to create Execution instances.
173      * @see #with()
174      * @see #newBuilder()
175      */
176     @NotThreadSafe
177     public static class Builder
178     {
179         Execution base;
180         XmlNode configuration;
181         Collection<String> goals;
182 
183         Builder(boolean withDefaults) {
184             if (withDefaults) {
185             }
186         }
187 
188         Builder(Execution base, boolean forceCopy) {
189             if (forceCopy) {
190                 this.configuration = base.configuration;
191                 this.goals = base.goals;
192             } else {
193                 this.base = base;
194             }
195         }
196 
197         @Nonnull
198         public Builder configuration(XmlNode configuration) {
199             this.configuration = configuration;
200             return this;
201         }
202 
203         @Nonnull
204         public Builder goals(Collection<String> goals) {
205             this.goals = goals;
206             return this;
207         }
208 
209 
210         @Nonnull
211         public Execution build() {
212             if (base != null
213                     && (configuration == null || configuration == base.configuration)
214                     && (goals == null || goals == base.goals)
215             ) {
216                 return base;
217             }
218             return new Execution(
219                 configuration != null ? configuration : (base != null ? base.configuration : null),
220                 goals != null ? goals : (base != null ? base.goals : null)
221             );
222         }
223     }
224 
225 }