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