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