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.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   * Root element of the user configuration file.
28   */
29  @Experimental
30  @Generated @ThreadSafe @Immutable
31  public class Settings
32      extends TrackableBase
33      implements Serializable, InputLocationTracker
34  {
35      final String namespaceUri;
36      final String modelEncoding;
37      /**
38       * The local repository.<br><b>Default value is:</b> {@code ${user.home}/.m2/repository}
39       */
40      final String localRepository;
41      /**
42       * Whether Maven should attempt to interact with the user for input.
43       */
44      final boolean interactiveMode;
45      /**
46       * Whether Maven should use the {@code plugin-registry.xml} file to manage plugin versions.
47       */
48      final boolean usePluginRegistry;
49      /**
50       * Indicate whether maven should operate in offline mode full-time.
51       */
52      final boolean offline;
53      /**
54       * Configuration for different proxy profiles. Multiple proxy profiles
55       * might come in handy for anyone working from a notebook or other
56       * mobile platform, to enable easy switching of entire proxy
57       * configurations by simply specifying the profile id, again either from
58       * the command line or from the defaults section below.
59       */
60      final List<Proxy> proxies;
61      /**
62       * Configuration of server-specific settings, mainly authentication
63       * method. This allows configuration of authentication on a per-server
64       * basis.
65       */
66      final List<Server> servers;
67      /**
68       * Configuration of download mirrors for repositories.
69       */
70      final List<Mirror> mirrors;
71      /**
72       * The lists of the remote repositories.
73       */
74      final List<Repository> repositories;
75      /**
76       * The lists of the remote repositories for discovering plugins.
77       */
78      final List<Repository> pluginRepositories;
79      /**
80       * Configuration of build profiles for adjusting the build
81       * according to environmental parameters.
82       */
83      final List<Profile> profiles;
84      /**
85       * List of manually-activated build profiles, specified in the order in which
86       * they should be applied.
87       */
88      final List<String> activeProfiles;
89      /**
90       * List of groupIds to search for a plugin when that plugin
91       * groupId is not explicitly provided.
92       */
93      final List<String> pluginGroups;
94  
95      /**
96        * Constructor for this class, to be called from its subclasses and {@link Builder}.
97        * @see Builder#build()
98        */
99      protected Settings(Builder builder) {
100         super(builder);
101         this.namespaceUri = builder.namespaceUri != null ? builder.namespaceUri : (builder.base != null ? builder.base.namespaceUri : null);
102         this.modelEncoding = builder.modelEncoding != null ? builder.modelEncoding : (builder.base != null ? builder.base.modelEncoding :  "UTF-8");
103         this.localRepository = builder.localRepository != null ? builder.localRepository : (builder.base != null ? builder.base.localRepository : null);
104         this.interactiveMode = builder.interactiveMode != null ? builder.interactiveMode : (builder.base != null ? builder.base.interactiveMode : true);
105         this.usePluginRegistry = builder.usePluginRegistry != null ? builder.usePluginRegistry : (builder.base != null ? builder.base.usePluginRegistry : false);
106         this.offline = builder.offline != null ? builder.offline : (builder.base != null ? builder.base.offline : false);
107         this.proxies = ImmutableCollections.copy(builder.proxies != null ? builder.proxies : (builder.base != null ? builder.base.proxies : null));
108         this.servers = ImmutableCollections.copy(builder.servers != null ? builder.servers : (builder.base != null ? builder.base.servers : null));
109         this.mirrors = ImmutableCollections.copy(builder.mirrors != null ? builder.mirrors : (builder.base != null ? builder.base.mirrors : null));
110         this.repositories = ImmutableCollections.copy(builder.repositories != null ? builder.repositories : (builder.base != null ? builder.base.repositories : null));
111         this.pluginRepositories = ImmutableCollections.copy(builder.pluginRepositories != null ? builder.pluginRepositories : (builder.base != null ? builder.base.pluginRepositories : null));
112         this.profiles = ImmutableCollections.copy(builder.profiles != null ? builder.profiles : (builder.base != null ? builder.base.profiles : null));
113         this.activeProfiles = ImmutableCollections.copy(builder.activeProfiles != null ? builder.activeProfiles : (builder.base != null ? builder.base.activeProfiles : null));
114         this.pluginGroups = ImmutableCollections.copy(builder.pluginGroups != null ? builder.pluginGroups : (builder.base != null ? builder.base.pluginGroups : null));
115     }
116 
117     public String getNamespaceUri() {
118         return namespaceUri;
119     }
120 
121     public String getModelEncoding() {
122         return modelEncoding;
123     }
124 
125     /**
126      * The local repository.<br><b>Default value is:</b> {@code ${user.home}/.m2/repository}
127      *
128      * @return a {@code String}
129      */
130     public String getLocalRepository() {
131         return this.localRepository;
132     }
133 
134     /**
135      * Whether Maven should attempt to interact with the user for input.
136      *
137      * @return a {@code boolean}
138      */
139     public boolean isInteractiveMode() {
140         return this.interactiveMode;
141     }
142 
143     /**
144      * Whether Maven should use the {@code plugin-registry.xml} file to manage plugin versions.
145      *
146      * @return a {@code boolean}
147      */
148     public boolean isUsePluginRegistry() {
149         return this.usePluginRegistry;
150     }
151 
152     /**
153      * Indicate whether maven should operate in offline mode full-time.
154      *
155      * @return a {@code boolean}
156      */
157     public boolean isOffline() {
158         return this.offline;
159     }
160 
161     /**
162      * Configuration for different proxy profiles. Multiple proxy profiles
163      * might come in handy for anyone working from a notebook or other
164      * mobile platform, to enable easy switching of entire proxy
165      * configurations by simply specifying the profile id, again either from
166      * the command line or from the defaults section below.
167      *
168      * @return a {@code List<Proxy>}
169      */
170     @Nonnull
171     public List<Proxy> getProxies() {
172         return this.proxies;
173     }
174 
175     /**
176      * Configuration of server-specific settings, mainly authentication
177      * method. This allows configuration of authentication on a per-server
178      * basis.
179      *
180      * @return a {@code List<Server>}
181      */
182     @Nonnull
183     public List<Server> getServers() {
184         return this.servers;
185     }
186 
187     /**
188      * Configuration of download mirrors for repositories.
189      *
190      * @return a {@code List<Mirror>}
191      */
192     @Nonnull
193     public List<Mirror> getMirrors() {
194         return this.mirrors;
195     }
196 
197     /**
198      * The lists of the remote repositories.
199      *
200      * @return a {@code List<Repository>}
201      */
202     @Nonnull
203     public List<Repository> getRepositories() {
204         return this.repositories;
205     }
206 
207     /**
208      * The lists of the remote repositories for discovering plugins.
209      *
210      * @return a {@code List<Repository>}
211      */
212     @Nonnull
213     public List<Repository> getPluginRepositories() {
214         return this.pluginRepositories;
215     }
216 
217     /**
218      * Configuration of build profiles for adjusting the build
219      * according to environmental parameters.
220      *
221      * @return a {@code List<Profile>}
222      */
223     @Nonnull
224     public List<Profile> getProfiles() {
225         return this.profiles;
226     }
227 
228     /**
229      * List of manually-activated build profiles, specified in the order in which
230      * they should be applied.
231      *
232      * @return a {@code List<String>}
233      */
234     @Nonnull
235     public List<String> getActiveProfiles() {
236         return this.activeProfiles;
237     }
238 
239     /**
240      * List of groupIds to search for a plugin when that plugin
241      * groupId is not explicitly provided.
242      *
243      * @return a {@code List<String>}
244      */
245     @Nonnull
246     public List<String> getPluginGroups() {
247         return this.pluginGroups;
248     }
249 
250     /**
251      * Creates a new builder with this object as the basis.
252      *
253      * @return a {@code Builder}
254      */
255     @Nonnull
256     public Builder with() {
257         return newBuilder(this);
258     }
259     /**
260      * Creates a new {@code Settings} instance using the specified localRepository.
261      *
262      * @param localRepository the new {@code String} to use
263      * @return a {@code Settings} with the specified localRepository
264      */
265     @Nonnull
266     public Settings withLocalRepository(String localRepository) {
267         return newBuilder(this, true).localRepository(localRepository).build();
268     }
269     /**
270      * Creates a new {@code Settings} instance using the specified interactiveMode.
271      *
272      * @param interactiveMode the new {@code boolean} to use
273      * @return a {@code Settings} with the specified interactiveMode
274      */
275     @Nonnull
276     public Settings withInteractiveMode(boolean interactiveMode) {
277         return newBuilder(this, true).interactiveMode(interactiveMode).build();
278     }
279     /**
280      * Creates a new {@code Settings} instance using the specified usePluginRegistry.
281      *
282      * @param usePluginRegistry the new {@code boolean} to use
283      * @return a {@code Settings} with the specified usePluginRegistry
284      */
285     @Nonnull
286     public Settings withUsePluginRegistry(boolean usePluginRegistry) {
287         return newBuilder(this, true).usePluginRegistry(usePluginRegistry).build();
288     }
289     /**
290      * Creates a new {@code Settings} instance using the specified offline.
291      *
292      * @param offline the new {@code boolean} to use
293      * @return a {@code Settings} with the specified offline
294      */
295     @Nonnull
296     public Settings withOffline(boolean offline) {
297         return newBuilder(this, true).offline(offline).build();
298     }
299     /**
300      * Creates a new {@code Settings} instance using the specified proxies.
301      *
302      * @param proxies the new {@code Collection<Proxy>} to use
303      * @return a {@code Settings} with the specified proxies
304      */
305     @Nonnull
306     public Settings withProxies(Collection<Proxy> proxies) {
307         return newBuilder(this, true).proxies(proxies).build();
308     }
309     /**
310      * Creates a new {@code Settings} instance using the specified servers.
311      *
312      * @param servers the new {@code Collection<Server>} to use
313      * @return a {@code Settings} with the specified servers
314      */
315     @Nonnull
316     public Settings withServers(Collection<Server> servers) {
317         return newBuilder(this, true).servers(servers).build();
318     }
319     /**
320      * Creates a new {@code Settings} instance using the specified mirrors.
321      *
322      * @param mirrors the new {@code Collection<Mirror>} to use
323      * @return a {@code Settings} with the specified mirrors
324      */
325     @Nonnull
326     public Settings withMirrors(Collection<Mirror> mirrors) {
327         return newBuilder(this, true).mirrors(mirrors).build();
328     }
329     /**
330      * Creates a new {@code Settings} instance using the specified repositories.
331      *
332      * @param repositories the new {@code Collection<Repository>} to use
333      * @return a {@code Settings} with the specified repositories
334      */
335     @Nonnull
336     public Settings withRepositories(Collection<Repository> repositories) {
337         return newBuilder(this, true).repositories(repositories).build();
338     }
339     /**
340      * Creates a new {@code Settings} instance using the specified pluginRepositories.
341      *
342      * @param pluginRepositories the new {@code Collection<Repository>} to use
343      * @return a {@code Settings} with the specified pluginRepositories
344      */
345     @Nonnull
346     public Settings withPluginRepositories(Collection<Repository> pluginRepositories) {
347         return newBuilder(this, true).pluginRepositories(pluginRepositories).build();
348     }
349     /**
350      * Creates a new {@code Settings} instance using the specified profiles.
351      *
352      * @param profiles the new {@code Collection<Profile>} to use
353      * @return a {@code Settings} with the specified profiles
354      */
355     @Nonnull
356     public Settings withProfiles(Collection<Profile> profiles) {
357         return newBuilder(this, true).profiles(profiles).build();
358     }
359     /**
360      * Creates a new {@code Settings} instance using the specified activeProfiles.
361      *
362      * @param activeProfiles the new {@code Collection<String>} to use
363      * @return a {@code Settings} with the specified activeProfiles
364      */
365     @Nonnull
366     public Settings withActiveProfiles(Collection<String> activeProfiles) {
367         return newBuilder(this, true).activeProfiles(activeProfiles).build();
368     }
369     /**
370      * Creates a new {@code Settings} instance using the specified pluginGroups.
371      *
372      * @param pluginGroups the new {@code Collection<String>} to use
373      * @return a {@code Settings} with the specified pluginGroups
374      */
375     @Nonnull
376     public Settings withPluginGroups(Collection<String> pluginGroups) {
377         return newBuilder(this, true).pluginGroups(pluginGroups).build();
378     }
379 
380     /**
381      * Creates a new {@code Settings} instance.
382      * Equivalent to {@code newInstance(true)}.
383      * @see #newInstance(boolean)
384      *
385      * @return a new {@code Settings}
386      */
387     @Nonnull
388     public static Settings newInstance() {
389         return newInstance(true);
390     }
391 
392     /**
393      * Creates a new {@code Settings} instance using default values or not.
394      * Equivalent to {@code newBuilder(withDefaults).build()}.
395      *
396      * @param withDefaults the boolean indicating whether default values should be used
397      * @return a new {@code Settings}
398      */
399     @Nonnull
400     public static Settings newInstance(boolean withDefaults) {
401         return newBuilder(withDefaults).build();
402     }
403 
404     /**
405      * Creates a new {@code Settings} builder instance.
406      * Equivalent to {@code newBuilder(true)}.
407      * @see #newBuilder(boolean)
408      *
409      * @return a new {@code Builder}
410      */
411     @Nonnull
412     public static Builder newBuilder() {
413         return newBuilder(true);
414     }
415 
416     /**
417      * Creates a new {@code Settings} builder instance using default values or not.
418      *
419      * @param withDefaults the boolean indicating whether default values should be used
420      * @return a new {@code Builder}
421      */
422     @Nonnull
423     public static Builder newBuilder(boolean withDefaults) {
424         return new Builder(withDefaults);
425     }
426 
427     /**
428      * Creates a new {@code Settings} builder instance using the specified object as a basis.
429      * Equivalent to {@code newBuilder(from, false)}.
430      *
431      * @param from the {@code Settings} instance to use as a basis
432      * @return a new {@code Builder}
433      */
434     @Nonnull
435     public static Builder newBuilder(Settings from) {
436         return newBuilder(from, false);
437     }
438 
439     /**
440      * Creates a new {@code Settings} builder instance using the specified object as a basis.
441      *
442      * @param from the {@code Settings} instance to use as a basis
443      * @param forceCopy the boolean indicating if a copy should be forced
444      * @return a new {@code Builder}
445      */
446     @Nonnull
447     public static Builder newBuilder(Settings from, boolean forceCopy) {
448         return new Builder(from, forceCopy);
449     }
450 
451     /**
452      * Builder class used to create Settings instances.
453      * @see #with()
454      * @see #newBuilder()
455      */
456     @NotThreadSafe
457     public static class Builder
458         extends TrackableBase.Builder
459     {
460         Settings base;
461         String namespaceUri;
462         String modelEncoding;
463         String localRepository;
464         Boolean interactiveMode;
465         Boolean usePluginRegistry;
466         Boolean offline;
467         Collection<Proxy> proxies;
468         Collection<Server> servers;
469         Collection<Mirror> mirrors;
470         Collection<Repository> repositories;
471         Collection<Repository> pluginRepositories;
472         Collection<Profile> profiles;
473         Collection<String> activeProfiles;
474         Collection<String> pluginGroups;
475 
476         protected Builder(boolean withDefaults) {
477             super(withDefaults);
478             if (withDefaults) {
479                 this.interactiveMode = true;
480                 this.usePluginRegistry = false;
481                 this.offline = false;
482             }
483         }
484 
485         protected Builder(Settings base, boolean forceCopy) {
486             super(base, forceCopy);
487             this.namespaceUri = base.namespaceUri;
488             this.modelEncoding = base.modelEncoding;
489             if (forceCopy) {
490                 this.localRepository = base.localRepository;
491                 this.interactiveMode = base.interactiveMode;
492                 this.usePluginRegistry = base.usePluginRegistry;
493                 this.offline = base.offline;
494                 this.proxies = base.proxies;
495                 this.servers = base.servers;
496                 this.mirrors = base.mirrors;
497                 this.repositories = base.repositories;
498                 this.pluginRepositories = base.pluginRepositories;
499                 this.profiles = base.profiles;
500                 this.activeProfiles = base.activeProfiles;
501                 this.pluginGroups = base.pluginGroups;
502                 this.locations = base.locations;
503                 this.importedFrom = base.importedFrom;
504             } else {
505                 this.base = base;
506             }
507         }
508 
509         @Nonnull
510         public Builder namespaceUri(String namespaceUri) {
511             this.namespaceUri = namespaceUri;
512             return this;
513         }
514 
515         @Nonnull
516         public Builder modelEncoding(String modelEncoding) {
517             this.modelEncoding = modelEncoding;
518             return this;
519         }
520 
521         @Nonnull
522         public Builder localRepository(String localRepository) {
523             this.localRepository = localRepository;
524             return this;
525         }
526 
527         @Nonnull
528         public Builder interactiveMode(boolean interactiveMode) {
529             this.interactiveMode = interactiveMode;
530             return this;
531         }
532 
533         @Nonnull
534         public Builder usePluginRegistry(boolean usePluginRegistry) {
535             this.usePluginRegistry = usePluginRegistry;
536             return this;
537         }
538 
539         @Nonnull
540         public Builder offline(boolean offline) {
541             this.offline = offline;
542             return this;
543         }
544 
545         @Nonnull
546         public Builder proxies(Collection<Proxy> proxies) {
547             this.proxies = proxies;
548             return this;
549         }
550 
551         @Nonnull
552         public Builder servers(Collection<Server> servers) {
553             this.servers = servers;
554             return this;
555         }
556 
557         @Nonnull
558         public Builder mirrors(Collection<Mirror> mirrors) {
559             this.mirrors = mirrors;
560             return this;
561         }
562 
563         @Nonnull
564         public Builder repositories(Collection<Repository> repositories) {
565             this.repositories = repositories;
566             return this;
567         }
568 
569         @Nonnull
570         public Builder pluginRepositories(Collection<Repository> pluginRepositories) {
571             this.pluginRepositories = pluginRepositories;
572             return this;
573         }
574 
575         @Nonnull
576         public Builder profiles(Collection<Profile> profiles) {
577             this.profiles = profiles;
578             return this;
579         }
580 
581         @Nonnull
582         public Builder activeProfiles(Collection<String> activeProfiles) {
583             this.activeProfiles = activeProfiles;
584             return this;
585         }
586 
587         @Nonnull
588         public Builder pluginGroups(Collection<String> pluginGroups) {
589             this.pluginGroups = pluginGroups;
590             return this;
591         }
592 
593 
594         @Nonnull
595         public Builder location(Object key, InputLocation location) {
596             if (location != null) {
597                 if (!(this.locations instanceof HashMap)) {
598                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
599                 }
600                 this.locations.put(key, location);
601             }
602             return this;
603         }
604 
605         @Nonnull
606         public Builder importedFrom(InputLocation importedFrom) {
607             this.importedFrom = importedFrom;
608             return this;
609         }
610 
611         @Nonnull
612         public Settings build() {
613             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
614             if (base != null
615                     && (localRepository == null || localRepository == base.localRepository)
616                     && (interactiveMode == null || interactiveMode == base.interactiveMode)
617                     && (usePluginRegistry == null || usePluginRegistry == base.usePluginRegistry)
618                     && (offline == null || offline == base.offline)
619                     && (proxies == null || proxies == base.proxies)
620                     && (servers == null || servers == base.servers)
621                     && (mirrors == null || mirrors == base.mirrors)
622                     && (repositories == null || repositories == base.repositories)
623                     && (pluginRepositories == null || pluginRepositories == base.pluginRepositories)
624                     && (profiles == null || profiles == base.profiles)
625                     && (activeProfiles == null || activeProfiles == base.activeProfiles)
626                     && (pluginGroups == null || pluginGroups == base.pluginGroups)
627             ) {
628                 return base;
629             }
630             return new Settings(this);
631         }
632 
633     }
634 
635 }