View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //  Generated by Modello Velocity from model-v3.vm
3   //  template, any modifications will be overwritten.
4   // ==============================================================
5   package org.apache.maven.settings;
6   
7   import java.io.Serializable;
8   import java.util.AbstractList;
9   import java.util.ArrayList;
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.stream.Collectors;
16  import java.util.stream.Stream;
17  import org.apache.maven.api.annotations.Generated;
18  import org.apache.maven.api.annotations.Nonnull;
19  
20  @Generated
21  public class Settings
22      extends TrackableBase
23      implements Serializable, Cloneable
24  {
25  
26      public Settings() {
27          this(org.apache.maven.api.settings.Settings.newInstance());
28      }
29  
30      public Settings(org.apache.maven.api.settings.Settings delegate) {
31          this(delegate, null);
32      }
33  
34      public Settings(org.apache.maven.api.settings.Settings delegate, BaseObject parent) {
35          super(delegate, parent);
36      }
37  
38      public Settings clone(){
39          return new Settings(getDelegate());
40      }
41  
42      @Override
43      public org.apache.maven.api.settings.Settings getDelegate() {
44          return (org.apache.maven.api.settings.Settings) super.getDelegate();
45      }
46  
47      @Override
48      public boolean equals(Object o) {
49          if (this == o) {
50              return true;
51          }
52          if (o == null || !(o instanceof Settings)) {
53              return false;
54          }
55          Settings that = (Settings) o;
56          return Objects.equals(this.delegate, that.delegate);
57      }
58  
59      @Override
60      public int hashCode() {
61          return getDelegate().hashCode();
62      }
63  
64      public String getModelEncoding() {
65          return getDelegate().getModelEncoding();
66      }
67  
68      public String getLocalRepository() {
69          return getDelegate().getLocalRepository();
70      }
71  
72      public void setLocalRepository(String localRepository) {
73          if (!Objects.equals(localRepository, getLocalRepository())) {
74              update(getDelegate().withLocalRepository(localRepository));
75          }
76      }
77  
78      public boolean isInteractiveMode() {
79          return getDelegate().isInteractiveMode();
80      }
81  
82      public void setInteractiveMode(boolean interactiveMode) {
83          if (!Objects.equals(interactiveMode, isInteractiveMode())) {
84              update(getDelegate().withInteractiveMode(interactiveMode));
85          }
86      }
87  
88      public boolean isUsePluginRegistry() {
89          return getDelegate().isUsePluginRegistry();
90      }
91  
92      public void setUsePluginRegistry(boolean usePluginRegistry) {
93          if (!Objects.equals(usePluginRegistry, isUsePluginRegistry())) {
94              update(getDelegate().withUsePluginRegistry(usePluginRegistry));
95          }
96      }
97  
98      public boolean isOffline() {
99          return getDelegate().isOffline();
100     }
101 
102     public void setOffline(boolean offline) {
103         if (!Objects.equals(offline, isOffline())) {
104             update(getDelegate().withOffline(offline));
105         }
106     }
107 
108     @Nonnull
109     public List<Proxy> getProxies() {
110         return new WrapperList<Proxy, org.apache.maven.api.settings.Proxy>(
111                     () -> getDelegate().getProxies(), l -> update(getDelegate().withProxies(l)),
112                     d -> new Proxy(d, this), Proxy::getDelegate);
113     }
114 
115     public void setProxies(List<Proxy> proxies) {
116         if (proxies == null) {
117             proxies = Collections.emptyList();
118         }
119         if (!Objects.equals(proxies, getProxies())) {
120             update(getDelegate().withProxies(
121                 proxies.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
122             proxies.forEach(e -> e.childrenTracking = this::replace);
123         }
124     }
125 
126     public void addProxy(Proxy proxy) {
127         update(getDelegate().withProxies(
128                Stream.concat(getDelegate().getProxies().stream(), Stream.of(proxy.getDelegate()))
129                         .collect(Collectors.toList())));
130         proxy.childrenTracking = this::replace;
131     }
132 
133     public void removeProxy(Proxy proxy) {
134         update(getDelegate().withProxies(
135                getDelegate().getProxies().stream()
136                         .filter(e -> !Objects.equals(e, proxy))
137                         .collect(Collectors.toList())));
138         proxy.childrenTracking = null;
139     }
140 
141     @Nonnull
142     public List<Server> getServers() {
143         return new WrapperList<Server, org.apache.maven.api.settings.Server>(
144                     () -> getDelegate().getServers(), l -> update(getDelegate().withServers(l)),
145                     d -> new Server(d, this), Server::getDelegate);
146     }
147 
148     public void setServers(List<Server> servers) {
149         if (servers == null) {
150             servers = Collections.emptyList();
151         }
152         if (!Objects.equals(servers, getServers())) {
153             update(getDelegate().withServers(
154                 servers.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
155             servers.forEach(e -> e.childrenTracking = this::replace);
156         }
157     }
158 
159     public void addServer(Server server) {
160         update(getDelegate().withServers(
161                Stream.concat(getDelegate().getServers().stream(), Stream.of(server.getDelegate()))
162                         .collect(Collectors.toList())));
163         server.childrenTracking = this::replace;
164     }
165 
166     public void removeServer(Server server) {
167         update(getDelegate().withServers(
168                getDelegate().getServers().stream()
169                         .filter(e -> !Objects.equals(e, server))
170                         .collect(Collectors.toList())));
171         server.childrenTracking = null;
172     }
173 
174     @Nonnull
175     public List<Mirror> getMirrors() {
176         return new WrapperList<Mirror, org.apache.maven.api.settings.Mirror>(
177                     () -> getDelegate().getMirrors(), l -> update(getDelegate().withMirrors(l)),
178                     d -> new Mirror(d, this), Mirror::getDelegate);
179     }
180 
181     public void setMirrors(List<Mirror> mirrors) {
182         if (mirrors == null) {
183             mirrors = Collections.emptyList();
184         }
185         if (!Objects.equals(mirrors, getMirrors())) {
186             update(getDelegate().withMirrors(
187                 mirrors.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
188             mirrors.forEach(e -> e.childrenTracking = this::replace);
189         }
190     }
191 
192     public void addMirror(Mirror mirror) {
193         update(getDelegate().withMirrors(
194                Stream.concat(getDelegate().getMirrors().stream(), Stream.of(mirror.getDelegate()))
195                         .collect(Collectors.toList())));
196         mirror.childrenTracking = this::replace;
197     }
198 
199     public void removeMirror(Mirror mirror) {
200         update(getDelegate().withMirrors(
201                getDelegate().getMirrors().stream()
202                         .filter(e -> !Objects.equals(e, mirror))
203                         .collect(Collectors.toList())));
204         mirror.childrenTracking = null;
205     }
206 
207     @Nonnull
208     public List<Repository> getRepositories() {
209         return new WrapperList<Repository, org.apache.maven.api.settings.Repository>(
210                     () -> getDelegate().getRepositories(), l -> update(getDelegate().withRepositories(l)),
211                     d -> new Repository(d, this), Repository::getDelegate);
212     }
213 
214     public void setRepositories(List<Repository> repositories) {
215         if (repositories == null) {
216             repositories = Collections.emptyList();
217         }
218         if (!Objects.equals(repositories, getRepositories())) {
219             update(getDelegate().withRepositories(
220                 repositories.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
221             repositories.forEach(e -> e.childrenTracking = this::replace);
222         }
223     }
224 
225     public void addRepository(Repository repository) {
226         update(getDelegate().withRepositories(
227                Stream.concat(getDelegate().getRepositories().stream(), Stream.of(repository.getDelegate()))
228                         .collect(Collectors.toList())));
229         repository.childrenTracking = this::replace;
230     }
231 
232     public void removeRepository(Repository repository) {
233         update(getDelegate().withRepositories(
234                getDelegate().getRepositories().stream()
235                         .filter(e -> !Objects.equals(e, repository))
236                         .collect(Collectors.toList())));
237         repository.childrenTracking = null;
238     }
239 
240     @Nonnull
241     public List<Repository> getPluginRepositories() {
242         return new WrapperList<Repository, org.apache.maven.api.settings.Repository>(
243                     () -> getDelegate().getPluginRepositories(), l -> update(getDelegate().withPluginRepositories(l)),
244                     d -> new Repository(d, this), Repository::getDelegate);
245     }
246 
247     public void setPluginRepositories(List<Repository> pluginRepositories) {
248         if (pluginRepositories == null) {
249             pluginRepositories = Collections.emptyList();
250         }
251         if (!Objects.equals(pluginRepositories, getPluginRepositories())) {
252             update(getDelegate().withPluginRepositories(
253                 pluginRepositories.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
254             pluginRepositories.forEach(e -> e.childrenTracking = this::replace);
255         }
256     }
257 
258     public void addPluginRepository(Repository pluginRepository) {
259         update(getDelegate().withPluginRepositories(
260                Stream.concat(getDelegate().getPluginRepositories().stream(), Stream.of(pluginRepository.getDelegate()))
261                         .collect(Collectors.toList())));
262         pluginRepository.childrenTracking = this::replace;
263     }
264 
265     public void removePluginRepository(Repository pluginRepository) {
266         update(getDelegate().withPluginRepositories(
267                getDelegate().getPluginRepositories().stream()
268                         .filter(e -> !Objects.equals(e, pluginRepository))
269                         .collect(Collectors.toList())));
270         pluginRepository.childrenTracking = null;
271     }
272 
273     @Nonnull
274     public List<Profile> getProfiles() {
275         return new WrapperList<Profile, org.apache.maven.api.settings.Profile>(
276                     () -> getDelegate().getProfiles(), l -> update(getDelegate().withProfiles(l)),
277                     d -> new Profile(d, this), Profile::getDelegate);
278     }
279 
280     public void setProfiles(List<Profile> profiles) {
281         if (profiles == null) {
282             profiles = Collections.emptyList();
283         }
284         if (!Objects.equals(profiles, getProfiles())) {
285             update(getDelegate().withProfiles(
286                 profiles.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
287             profiles.forEach(e -> e.childrenTracking = this::replace);
288         }
289     }
290 
291     public void addProfile(Profile profile) {
292         update(getDelegate().withProfiles(
293                Stream.concat(getDelegate().getProfiles().stream(), Stream.of(profile.getDelegate()))
294                         .collect(Collectors.toList())));
295         profile.childrenTracking = this::replace;
296     }
297 
298     public void removeProfile(Profile profile) {
299         update(getDelegate().withProfiles(
300                getDelegate().getProfiles().stream()
301                         .filter(e -> !Objects.equals(e, profile))
302                         .collect(Collectors.toList())));
303         profile.childrenTracking = null;
304     }
305 
306     @Nonnull
307     public List<String> getActiveProfiles() {
308         return new WrapperList<String, String>(() -> getDelegate().getActiveProfiles(), this::setActiveProfiles, s -> s, s -> s);
309     }
310 
311     public void setActiveProfiles(List<String> activeProfiles) {
312         if (!Objects.equals(activeProfiles, getActiveProfiles())) {
313             update(getDelegate().withActiveProfiles(activeProfiles));
314         }
315     }
316 
317     public void addActiveProfile(String activeProfile) {
318         update(getDelegate().withActiveProfiles(
319                Stream.concat(getDelegate().getActiveProfiles().stream(), Stream.of(activeProfile))
320                         .collect(Collectors.toList())));
321     }
322 
323     public void removeActiveProfile(String activeProfile) {
324         update(getDelegate().withActiveProfiles(
325                getDelegate().getActiveProfiles().stream()
326                         .filter(e -> !Objects.equals(e, activeProfile))
327                         .collect(Collectors.toList())));
328     }
329 
330     @Nonnull
331     public List<String> getPluginGroups() {
332         return new WrapperList<String, String>(() -> getDelegate().getPluginGroups(), this::setPluginGroups, s -> s, s -> s);
333     }
334 
335     public void setPluginGroups(List<String> pluginGroups) {
336         if (!Objects.equals(pluginGroups, getPluginGroups())) {
337             update(getDelegate().withPluginGroups(pluginGroups));
338         }
339     }
340 
341     public void addPluginGroup(String pluginGroup) {
342         update(getDelegate().withPluginGroups(
343                Stream.concat(getDelegate().getPluginGroups().stream(), Stream.of(pluginGroup))
344                         .collect(Collectors.toList())));
345     }
346 
347     public void removePluginGroup(String pluginGroup) {
348         update(getDelegate().withPluginGroups(
349                getDelegate().getPluginGroups().stream()
350                         .filter(e -> !Objects.equals(e, pluginGroup))
351                         .collect(Collectors.toList())));
352     }
353 
354     protected boolean replace(Object oldDelegate, Object newDelegate) {
355         if (super.replace(oldDelegate, newDelegate)) {
356             return true;
357         }
358         if (getDelegate().getProxies().contains(oldDelegate)) {
359             List<org.apache.maven.api.settings.Proxy> list = new ArrayList<>(getDelegate().getProxies());
360             list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.settings.Proxy) newDelegate : d);
361             update(getDelegate().withProxies(list));
362             return true;
363         }
364         if (getDelegate().getServers().contains(oldDelegate)) {
365             List<org.apache.maven.api.settings.Server> list = new ArrayList<>(getDelegate().getServers());
366             list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.settings.Server) newDelegate : d);
367             update(getDelegate().withServers(list));
368             return true;
369         }
370         if (getDelegate().getMirrors().contains(oldDelegate)) {
371             List<org.apache.maven.api.settings.Mirror> list = new ArrayList<>(getDelegate().getMirrors());
372             list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.settings.Mirror) newDelegate : d);
373             update(getDelegate().withMirrors(list));
374             return true;
375         }
376         if (getDelegate().getRepositories().contains(oldDelegate)) {
377             List<org.apache.maven.api.settings.Repository> list = new ArrayList<>(getDelegate().getRepositories());
378             list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.settings.Repository) newDelegate : d);
379             update(getDelegate().withRepositories(list));
380             return true;
381         }
382         if (getDelegate().getPluginRepositories().contains(oldDelegate)) {
383             List<org.apache.maven.api.settings.Repository> list = new ArrayList<>(getDelegate().getPluginRepositories());
384             list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.settings.Repository) newDelegate : d);
385             update(getDelegate().withPluginRepositories(list));
386             return true;
387         }
388         if (getDelegate().getProfiles().contains(oldDelegate)) {
389             List<org.apache.maven.api.settings.Profile> list = new ArrayList<>(getDelegate().getProfiles());
390             list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.settings.Profile) newDelegate : d);
391             update(getDelegate().withProfiles(list));
392             return true;
393         }
394         return false;
395     }
396 
397     public static List<org.apache.maven.api.settings.Settings> settingsToApiV4(List<Settings> list) {
398         return list != null ? new WrapperList<>(list, Settings::getDelegate, Settings::new) : null;
399     }
400 
401     public static List<Settings> settingsToApiV3(List<org.apache.maven.api.settings.Settings> list) {
402         return list != null ? new WrapperList<>(list, Settings::new, Settings::getDelegate) : null;
403     }
404 
405 
406             
407     public Boolean getInteractiveMode() {
408         return Boolean.valueOf(isInteractiveMode());
409     }
410 
411     private Proxy activeProxy;
412 
413     /**
414      * Reset the {@code activeProxy} field to {@code null}.
415      */
416     public void flushActiveProxy() {
417         this.activeProxy = null;
418     }
419 
420     /**
421      * @return the first active proxy
422      */
423     public synchronized Proxy getActiveProxy() {
424         if (activeProxy == null) {
425             java.util.List<Proxy> proxies = getProxies();
426             if (proxies != null && !proxies.isEmpty()) {
427                 for (Proxy proxy : proxies) {
428                     if (proxy.isActive()) {
429                         activeProxy = proxy;
430                         break;
431                     }
432                 }
433             }
434         }
435         return activeProxy;
436     }
437 
438     public Server getServer(String serverId) {
439         Server match = null;
440         java.util.List<Server> servers = getServers();
441         if (servers != null && serverId != null) {
442             for (Server server : servers) {
443                 if (serverId.equals(server.getId())) {
444                     match = server;
445                     break;
446                 }
447             }
448         }
449         return match;
450     }
451 
452     @Deprecated
453     public Mirror getMirrorOf(String repositoryId) {
454         Mirror match = null;
455         java.util.List<Mirror> mirrors = getMirrors();
456         if (mirrors != null && repositoryId != null) {
457             for (Mirror mirror : mirrors) {
458                 if (repositoryId.equals(mirror.getMirrorOf())) {
459                     match = mirror;
460                     break;
461                 }
462             }
463         }
464         return match;
465     }
466 
467     private java.util.Map<String, Profile> profileMap;
468 
469     /**
470      * Reset the {@code profileMap} field to {@code null}
471      */
472     public void flushProfileMap() {
473         this.profileMap = null;
474     }
475 
476     /**
477      * @return a Map of profiles field keyed by {@link Profile#getId()}
478      */
479     public java.util.Map<String, Profile> getProfilesAsMap() {
480         if (profileMap == null) {
481             profileMap = new java.util.LinkedHashMap<String, Profile>();
482             if (getProfiles() != null) {
483                 for (Profile profile : getProfiles()) {
484                     profileMap.put(profile.getId(), profile);
485                 }
486             }
487         }
488         return profileMap;
489     }
490             
491           
492 }