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