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.settings;
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   * Download policy
20   */
21  @Experimental
22  @Generated @ThreadSafe @Immutable
23  public class RepositoryPolicy
24      implements Serializable
25  {
26      /**
27       * Whether to use this repository for downloading this type of
28       * artifact.
29       */
30      final boolean enabled;
31      /**
32       * The frequency for downloading updates - can be "always",
33       * "daily" (default), "interval:XXX" (in minutes) or "never"
34       * (only if it doesn't exist locally).
35       */
36      final String updatePolicy;
37      /**
38       * What to do when verification of an artifact checksum fails. Valid values are "fail" (default for Maven 4 and
39       * above), "warn" (default for Maven 2 and 3) or "ignore".
40       */
41      final String checksumPolicy;
42  
43      /**
44        * Constructor for this class, package protected.
45        * @see Builder#build()
46        */
47      RepositoryPolicy(
48          boolean enabled,
49          String updatePolicy,
50          String checksumPolicy
51      )
52      {
53          this.enabled = enabled;
54          this.updatePolicy = updatePolicy;
55          this.checksumPolicy = checksumPolicy;
56      }
57  
58      /**
59       * Whether to use this repository for downloading this type of
60       * artifact.
61       *
62       * @return a {@code boolean}
63       */
64      public boolean isEnabled()
65      {
66          return this.enabled;
67      }
68  
69      /**
70       * The frequency for downloading updates - can be "always",
71       * "daily" (default), "interval:XXX" (in minutes) or "never"
72       * (only if it doesn't exist locally).
73       *
74       * @return a {@code String}
75       */
76      public String getUpdatePolicy()
77      {
78          return this.updatePolicy;
79      }
80  
81      /**
82       * What to do when verification of an artifact checksum fails. Valid values are "fail" (default for Maven 4 and
83       * above), "warn" (default for Maven 2 and 3) or "ignore".
84       *
85       * @return a {@code String}
86       */
87      public String getChecksumPolicy()
88      {
89          return this.checksumPolicy;
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 RepositoryPolicy} instance using the specified enabled.
104      *
105      * @param enabled the new {@code boolean} to use
106      * @return a {@code RepositoryPolicy} with the specified enabled
107      */
108     @Nonnull
109     public RepositoryPolicy withEnabled( boolean enabled )
110     {
111         return with().enabled( enabled ).build();
112     }
113     /**
114      * Creates a new {@code RepositoryPolicy} instance using the specified updatePolicy.
115      *
116      * @param updatePolicy the new {@code String} to use
117      * @return a {@code RepositoryPolicy} with the specified updatePolicy
118      */
119     @Nonnull
120     public RepositoryPolicy withUpdatePolicy( String updatePolicy )
121     {
122         return with().updatePolicy( updatePolicy ).build();
123     }
124     /**
125      * Creates a new {@code RepositoryPolicy} instance using the specified checksumPolicy.
126      *
127      * @param checksumPolicy the new {@code String} to use
128      * @return a {@code RepositoryPolicy} with the specified checksumPolicy
129      */
130     @Nonnull
131     public RepositoryPolicy withChecksumPolicy( String checksumPolicy )
132     {
133         return with().checksumPolicy( checksumPolicy ).build();
134     }
135 
136     /**
137      * Creates a new {@code RepositoryPolicy} instance.
138      * Equivalent to {@code newInstance( true )}.
139      * @see #newInstance(boolean)
140      *
141      * @return a new {@code RepositoryPolicy}
142      */
143     @Nonnull
144     public static RepositoryPolicy newInstance()
145     {
146         return newInstance( true );
147     }
148 
149     /**
150      * Creates a new {@code RepositoryPolicy} instance using default values or not.
151      * Equivalent to {@code newBuilder( withDefaults ).build()}.
152      *
153      * @param withDefaults the boolean indicating whether default values should be used
154      * @return a new {@code RepositoryPolicy}
155      */
156     @Nonnull
157     public static RepositoryPolicy newInstance( boolean withDefaults )
158     {
159         return newBuilder( withDefaults ).build();
160     }
161 
162     /**
163      * Creates a new {@code RepositoryPolicy} builder instance.
164      * Equivalent to {@code newBuilder( true )}.
165      * @see #newBuilder(boolean)
166      *
167      * @return a new {@code Builder}
168      */
169     @Nonnull
170     public static Builder newBuilder()
171     {
172         return newBuilder( true );
173     }
174 
175     /**
176      * Creates a new {@code RepositoryPolicy} builder instance using default values or not.
177      *
178      * @param withDefaults the boolean indicating whether default values should be used
179      * @return a new {@code Builder}
180      */
181     @Nonnull
182     public static Builder newBuilder( boolean withDefaults )
183     {
184         return new Builder( withDefaults );
185     }
186 
187     /**
188      * Creates a new {@code RepositoryPolicy} builder instance using the specified object as a basis.
189      * Equivalent to {@code newBuilder( from, false )}.
190      *
191      * @param from the {@code RepositoryPolicy} instance to use as a basis
192      * @return a new {@code Builder}
193      */
194     @Nonnull
195     public static Builder newBuilder( RepositoryPolicy from )
196     {
197         return newBuilder( from, false );
198     }
199 
200     /**
201      * Creates a new {@code RepositoryPolicy} builder instance using the specified object as a basis.
202      *
203      * @param from the {@code RepositoryPolicy} instance to use as a basis
204      * @param forceCopy the boolean indicating if a copy should be forced
205      * @return a new {@code Builder}
206      */
207     @Nonnull
208     public static Builder newBuilder( RepositoryPolicy from, boolean forceCopy )
209     {
210         return new Builder( from, forceCopy );
211     }
212 
213     /**
214      * Builder class used to create RepositoryPolicy instances.
215      * @see #with()
216      * @see #newBuilder()
217      */
218     @NotThreadSafe
219     public static class Builder
220     {
221         RepositoryPolicy base;
222         Boolean enabled;
223         String updatePolicy;
224         String checksumPolicy;
225 
226         Builder( boolean withDefaults )
227         {
228             if ( withDefaults )
229             {
230                 this.enabled = true;
231             }
232         }
233 
234         Builder( RepositoryPolicy base, boolean forceCopy )
235         {
236             if ( forceCopy )
237             {
238                 this.enabled = base.enabled;
239                 this.updatePolicy = base.updatePolicy;
240                 this.checksumPolicy = base.checksumPolicy;
241             }
242             else
243             {
244                 this.base = base;
245             }
246         }
247 
248         @Nonnull
249         public Builder enabled( boolean enabled )
250         {
251             this.enabled = enabled;
252             return this;
253         }
254 
255         @Nonnull
256         public Builder updatePolicy( String updatePolicy )
257         {
258             this.updatePolicy = updatePolicy;
259             return this;
260         }
261 
262         @Nonnull
263         public Builder checksumPolicy( String checksumPolicy )
264         {
265             this.checksumPolicy = checksumPolicy;
266             return this;
267         }
268 
269 
270         @Nonnull
271         public RepositoryPolicy build()
272         {
273             if ( base != null
274                     && ( enabled == null || enabled == base.enabled )
275                     && ( updatePolicy == null || updatePolicy == base.updatePolicy )
276                     && ( checksumPolicy == null || checksumPolicy == base.checksumPolicy )
277             )
278             {
279                 return base;
280             }
281             return new RepositoryPolicy(
282                 enabled != null ? enabled : ( base != null ? base.enabled : true ),
283                 updatePolicy != null ? updatePolicy : ( base != null ? base.updatePolicy : null ),
284                 checksumPolicy != null ? checksumPolicy : ( base != null ? base.checksumPolicy : null )
285             );
286         }
287     }
288 
289 }