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