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.model;
6   
7   import java.io.Serializable;
8   import java.util.Collections;
9   import java.util.HashMap;
10  import java.util.Map;
11  import org.apache.maven.api.annotations.Experimental;
12  import org.apache.maven.api.annotations.Generated;
13  import org.apache.maven.api.annotations.Immutable;
14  import org.apache.maven.api.annotations.Nonnull;
15  import org.apache.maven.api.annotations.NotThreadSafe;
16  import org.apache.maven.api.annotations.ThreadSafe;
17  
18  /**
19   * Describes the prerequisites a project can have.
20   */
21  @Experimental
22  @Generated @ThreadSafe @Immutable
23  public class Prerequisites
24      implements Serializable, InputLocationTracker
25  {
26      /**
27       * For a plugin project (packaging is {@code maven-plugin}), the minimum version of
28       * Maven required to use the resulting plugin.<br>
29       * In Maven 2, this was also specifying the minimum version of Maven required to build a
30       * project, but this usage is <b>deprecated</b> in Maven 3 and not checked any more: use
31       * the <a href="https://maven.apache.org/enforcer/enforcer-rules/requireMavenVersion.html">Maven Enforcer Plugin's
32       * {@code requireMavenVersion} rule</a> instead.
33       */
34      final String maven;
35      /** Location of the xml element for this object. */
36      final InputLocation location;
37      /** Location of the xml element for the field maven. */
38      final InputLocation mavenLocation;
39      /** Other locations */
40      final Map<Object, InputLocation> locations;
41  
42      /**
43        * Constructor for this class, package protected.
44        * @see Builder#build()
45        */
46      Prerequisites(
47          String maven,
48          Map<Object, InputLocation> locations,
49          InputLocation location,
50          InputLocation mavenLocation
51      )
52      {
53          this.maven = maven;
54          this.locations = ImmutableCollections.copy( locations );
55          this.location = location;
56          this.mavenLocation = mavenLocation;
57      }
58  
59      /**
60       * For a plugin project (packaging is {@code maven-plugin}), the minimum version of
61       * Maven required to use the resulting plugin.<br>
62       * In Maven 2, this was also specifying the minimum version of Maven required to build a
63       * project, but this usage is <b>deprecated</b> in Maven 3 and not checked any more: use
64       * the <a href="https://maven.apache.org/enforcer/enforcer-rules/requireMavenVersion.html">Maven Enforcer Plugin's
65       * {@code requireMavenVersion} rule</a> instead.
66       *
67       * @return a {@code String}
68       */
69      public String getMaven()
70      {
71          return this.maven;
72      }
73  
74      /**
75       * Gets the location of the specified field in the input source.
76       */
77      public InputLocation getLocation( Object key )
78      {
79          if ( key instanceof String )
80          {
81              switch ( ( String ) key )
82              {
83                  case "":
84                      return location;
85                  case "maven":
86                      return mavenLocation;
87              }
88          }
89          return locations != null ? locations.get( key ) : null;
90      }
91  
92      /**
93       * Creates a new builder with this object as the basis.
94       *
95       * @return a {@code Builder}
96       */
97      @Nonnull
98      public Builder with()
99      {
100         return newBuilder( this );
101     }
102     /**
103      * Creates a new {@code Prerequisites} instance using the specified maven.
104      *
105      * @param maven the new {@code String} to use
106      * @return a {@code Prerequisites} with the specified maven
107      */
108     @Nonnull
109     public Prerequisites withMaven( String maven )
110     {
111         return with().maven( maven ).build();
112     }
113 
114     /**
115      * Creates a new {@code Prerequisites} instance.
116      * Equivalent to {@code newInstance( true )}.
117      * @see #newInstance(boolean)
118      *
119      * @return a new {@code Prerequisites}
120      */
121     @Nonnull
122     public static Prerequisites newInstance()
123     {
124         return newInstance( true );
125     }
126 
127     /**
128      * Creates a new {@code Prerequisites} instance using default values or not.
129      * Equivalent to {@code newBuilder( withDefaults ).build()}.
130      *
131      * @param withDefaults the boolean indicating whether default values should be used
132      * @return a new {@code Prerequisites}
133      */
134     @Nonnull
135     public static Prerequisites newInstance( boolean withDefaults )
136     {
137         return newBuilder( withDefaults ).build();
138     }
139 
140     /**
141      * Creates a new {@code Prerequisites} builder instance.
142      * Equivalent to {@code newBuilder( true )}.
143      * @see #newBuilder(boolean)
144      *
145      * @return a new {@code Builder}
146      */
147     @Nonnull
148     public static Builder newBuilder()
149     {
150         return newBuilder( true );
151     }
152 
153     /**
154      * Creates a new {@code Prerequisites} builder instance using default values or not.
155      *
156      * @param withDefaults the boolean indicating whether default values should be used
157      * @return a new {@code Builder}
158      */
159     @Nonnull
160     public static Builder newBuilder( boolean withDefaults )
161     {
162         return new Builder( withDefaults );
163     }
164 
165     /**
166      * Creates a new {@code Prerequisites} builder instance using the specified object as a basis.
167      * Equivalent to {@code newBuilder( from, false )}.
168      *
169      * @param from the {@code Prerequisites} instance to use as a basis
170      * @return a new {@code Builder}
171      */
172     @Nonnull
173     public static Builder newBuilder( Prerequisites from )
174     {
175         return newBuilder( from, false );
176     }
177 
178     /**
179      * Creates a new {@code Prerequisites} builder instance using the specified object as a basis.
180      *
181      * @param from the {@code Prerequisites} instance to use as a basis
182      * @param forceCopy the boolean indicating if a copy should be forced
183      * @return a new {@code Builder}
184      */
185     @Nonnull
186     public static Builder newBuilder( Prerequisites from, boolean forceCopy )
187     {
188         return new Builder( from, forceCopy );
189     }
190 
191     /**
192      * Builder class used to create Prerequisites instances.
193      * @see #with()
194      * @see #newBuilder()
195      */
196     @NotThreadSafe
197     public static class Builder
198     {
199         Prerequisites base;
200         String maven;
201         Map<Object, InputLocation> locations;
202 
203         Builder( boolean withDefaults )
204         {
205             if ( withDefaults )
206             {
207                 this.maven = "2.0";
208             }
209         }
210 
211         Builder( Prerequisites base, boolean forceCopy )
212         {
213             if ( forceCopy )
214             {
215                 this.maven = base.maven;
216             }
217             else
218             {
219                 this.base = base;
220             }
221         }
222 
223         @Nonnull
224         public Builder maven( String maven )
225         {
226             this.maven = maven;
227             return this;
228         }
229 
230 
231         @Nonnull
232         public Builder location( Object key, InputLocation location )
233         {
234             if ( location != null )
235             {
236                 if ( this.locations == null )
237                 {
238                     this.locations = new HashMap<>();
239                 }
240                 this.locations.put( key, location );
241             }
242             return this;
243         }
244 
245         @Nonnull
246         public Prerequisites build()
247         {
248             if ( base != null
249                     && ( maven == null || maven == base.maven )
250             )
251             {
252                 return base;
253             }
254             Map<Object, InputLocation> locations = null;
255             InputLocation location = null;
256             InputLocation mavenLocation = null;
257             if ( this.locations != null )
258             {
259                 locations = this.locations;
260                 location = locations.remove( "" );
261                 mavenLocation = locations.remove( "maven" );
262             }
263             return new Prerequisites(
264                 maven != null ? maven : ( base != null ? base.maven : null ),
265                 locations != null ? locations : ( base != null ? base.locations : null ),
266                 location != null ? location : ( base != null ? base.location : null ),
267                 mavenLocation != null ? mavenLocation : ( base != null ? base.mavenLocation : null )
268             );
269         }
270     }
271 
272 }