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 (!Objects.equals(proxies, getProxies())) {
117             update(getDelegate().withProxies(
118                    proxies.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
119             proxies.forEach(e -> e.childrenTracking = this::replace);
120         }
121     }
122 
123     public void addProxy(Proxy proxy) {
124         update(getDelegate().withProxies(
125                Stream.concat(getDelegate().getProxies().stream(), Stream.of(proxy.getDelegate()))
126                         .collect(Collectors.toList())));
127         proxy.childrenTracking = this::replace;
128     }
129 
130     public void removeProxy(Proxy proxy) {
131         update(getDelegate().withProxies(
132                getDelegate().getProxies().stream()
133                         .filter(e -> !Objects.equals(e, proxy))
134                         .collect(Collectors.toList())));
135         proxy.childrenTracking = null;
136     }
137 
138     @Nonnull
139     public List<Server> getServers() {
140         return new WrapperList<Server, org.apache.maven.api.settings.Server>(
141                     () -> getDelegate().getServers(), l -> update(getDelegate().withServers(l)),
142                     d -> new Server(d, this), Server::getDelegate);
143     }
144 
145     public void setServers(List<Server> servers) {
146         if (!Objects.equals(servers, getServers())) {
147             update(getDelegate().withServers(
148                    servers.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
149             servers.forEach(e -> e.childrenTracking = this::replace);
150         }
151     }
152 
153     public void addServer(Server server) {
154         update(getDelegate().withServers(
155                Stream.concat(getDelegate().getServers().stream(), Stream.of(server.getDelegate()))
156                         .collect(Collectors.toList())));
157         server.childrenTracking = this::replace;
158     }
159 
160     public void removeServer(Server server) {
161         update(getDelegate().withServers(
162                getDelegate().getServers().stream()
163                         .filter(e -> !Objects.equals(e, server))
164                         .collect(Collectors.toList())));
165         server.childrenTracking = null;
166     }
167 
168     @Nonnull
169     public List<Mirror> getMirrors() {
170         return new WrapperList<Mirror, org.apache.maven.api.settings.Mirror>(
171                     () -> getDelegate().getMirrors(), l -> update(getDelegate().withMirrors(l)),
172                     d -> new Mirror(d, this), Mirror::getDelegate);
173     }
174 
175     public void setMirrors(List<Mirror> mirrors) {
176         if (!Objects.equals(mirrors, getMirrors())) {
177             update(getDelegate().withMirrors(
178                    mirrors.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
179             mirrors.forEach(e -> e.childrenTracking = this::replace);
180         }
181     }
182 
183     public void addMirror(Mirror mirror) {
184         update(getDelegate().withMirrors(
185                Stream.concat(getDelegate().getMirrors().stream(), Stream.of(mirror.getDelegate()))
186                         .collect(Collectors.toList())));
187         mirror.childrenTracking = this::replace;
188     }
189 
190     public void removeMirror(Mirror mirror) {
191         update(getDelegate().withMirrors(
192                getDelegate().getMirrors().stream()
193                         .filter(e -> !Objects.equals(e, mirror))
194                         .collect(Collectors.toList())));
195         mirror.childrenTracking = null;
196     }
197 
198     @Nonnull
199     public List<Repository> getRepositories() {
200         return new WrapperList<Repository, org.apache.maven.api.settings.Repository>(
201                     () -> getDelegate().getRepositories(), l -> update(getDelegate().withRepositories(l)),
202                     d -> new Repository(d, this), Repository::getDelegate);
203     }
204 
205     public void setRepositories(List<Repository> repositories) {
206         if (!Objects.equals(repositories, getRepositories())) {
207             update(getDelegate().withRepositories(
208                    repositories.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
209             repositories.forEach(e -> e.childrenTracking = this::replace);
210         }
211     }
212 
213     public void addRepository(Repository repository) {
214         update(getDelegate().withRepositories(
215                Stream.concat(getDelegate().getRepositories().stream(), Stream.of(repository.getDelegate()))
216                         .collect(Collectors.toList())));
217         repository.childrenTracking = this::replace;
218     }
219 
220     public void removeRepository(Repository repository) {
221         update(getDelegate().withRepositories(
222                getDelegate().getRepositories().stream()
223                         .filter(e -> !Objects.equals(e, repository))
224                         .collect(Collectors.toList())));
225         repository.childrenTracking = null;
226     }
227 
228     @Nonnull
229     public List<Repository> getPluginRepositories() {
230         return new WrapperList<Repository, org.apache.maven.api.settings.Repository>(
231                     () -> getDelegate().getPluginRepositories(), l -> update(getDelegate().withPluginRepositories(l)),
232                     d -> new Repository(d, this), Repository::getDelegate);
233     }
234 
235     public void setPluginRepositories(List<Repository> pluginRepositories) {
236         if (!Objects.equals(pluginRepositories, getPluginRepositories())) {
237             update(getDelegate().withPluginRepositories(
238                    pluginRepositories.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
239             pluginRepositories.forEach(e -> e.childrenTracking = this::replace);
240         }
241     }
242 
243     public void addPluginRepository(Repository pluginRepository) {
244         update(getDelegate().withPluginRepositories(
245                Stream.concat(getDelegate().getPluginRepositories().stream(), Stream.of(pluginRepository.getDelegate()))
246                         .collect(Collectors.toList())));
247         pluginRepository.childrenTracking = this::replace;
248     }
249 
250     public void removePluginRepository(Repository pluginRepository) {
251         update(getDelegate().withPluginRepositories(
252                getDelegate().getPluginRepositories().stream()
253                         .filter(e -> !Objects.equals(e, pluginRepository))
254                         .collect(Collectors.toList())));
255         pluginRepository.childrenTracking = null;
256     }
257 
258     @Nonnull
259     public List<Profile> getProfiles() {
260         return new WrapperList<Profile, org.apache.maven.api.settings.Profile>(
261                     () -> getDelegate().getProfiles(), l -> update(getDelegate().withProfiles(l)),
262                     d -> new Profile(d, this), Profile::getDelegate);
263     }
264 
265     public void setProfiles(List<Profile> profiles) {
266         if (!Objects.equals(profiles, getProfiles())) {
267             update(getDelegate().withProfiles(
268                    profiles.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
269             profiles.forEach(e -> e.childrenTracking = this::replace);
270         }
271     }
272 
273     public void addProfile(Profile profile) {
274         update(getDelegate().withProfiles(
275                Stream.concat(getDelegate().getProfiles().stream(), Stream.of(profile.getDelegate()))
276                         .collect(Collectors.toList())));
277         profile.childrenTracking = this::replace;
278     }
279 
280     public void removeProfile(Profile profile) {
281         update(getDelegate().withProfiles(
282                getDelegate().getProfiles().stream()
283                         .filter(e -> !Objects.equals(e, profile))
284                         .collect(Collectors.toList())));
285         profile.childrenTracking = null;
286     }
287 
288     @Nonnull
289     public List<String> getActiveProfiles() {
290         return new WrapperList<String, String>(() -> getDelegate().getActiveProfiles(), this::setActiveProfiles, s -> s, s -> s);
291     }
292 
293     public void setActiveProfiles(List<String> activeProfiles) {
294         if (!Objects.equals(activeProfiles, getActiveProfiles())) {
295             update(getDelegate().withActiveProfiles(activeProfiles));
296         }
297     }
298 
299     public void addActiveProfile(String activeProfile) {
300         update(getDelegate().withActiveProfiles(
301                Stream.concat(getDelegate().getActiveProfiles().stream(), Stream.of(activeProfile))
302                         .collect(Collectors.toList())));
303     }
304 
305     public void removeActiveProfile(String activeProfile) {
306         update(getDelegate().withActiveProfiles(
307                getDelegate().getActiveProfiles().stream()
308                         .filter(e -> !Objects.equals(e, activeProfile))
309                         .collect(Collectors.toList())));
310     }
311 
312     @Nonnull
313     public List<String> getPluginGroups() {
314         return new WrapperList<String, String>(() -> getDelegate().getPluginGroups(), this::setPluginGroups, s -> s, s -> s);
315     }
316 
317     public void setPluginGroups(List<String> pluginGroups) {
318         if (!Objects.equals(pluginGroups, getPluginGroups())) {
319             update(getDelegate().withPluginGroups(pluginGroups));
320         }
321     }
322 
323     public void addPluginGroup(String pluginGroup) {
324         update(getDelegate().withPluginGroups(
325                Stream.concat(getDelegate().getPluginGroups().stream(), Stream.of(pluginGroup))
326                         .collect(Collectors.toList())));
327     }
328 
329     public void removePluginGroup(String pluginGroup) {
330         update(getDelegate().withPluginGroups(
331                getDelegate().getPluginGroups().stream()
332                         .filter(e -> !Objects.equals(e, pluginGroup))
333                         .collect(Collectors.toList())));
334     }
335 
336     protected boolean replace(Object oldDelegate, Object newDelegate) {
337         if (super.replace(oldDelegate, newDelegate)) {
338             return true;
339         }
340         if (getDelegate().getProxies().contains(oldDelegate)) {
341             List<org.apache.maven.api.settings.Proxy> list = new ArrayList<>(getDelegate().getProxies());
342             list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.settings.Proxy) newDelegate : d);
343             update(getDelegate().withProxies(list));
344             return true;
345         }
346         if (getDelegate().getServers().contains(oldDelegate)) {
347             List<org.apache.maven.api.settings.Server> list = new ArrayList<>(getDelegate().getServers());
348             list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.settings.Server) newDelegate : d);
349             update(getDelegate().withServers(list));
350             return true;
351         }
352         if (getDelegate().getMirrors().contains(oldDelegate)) {
353             List<org.apache.maven.api.settings.Mirror> list = new ArrayList<>(getDelegate().getMirrors());
354             list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.settings.Mirror) newDelegate : d);
355             update(getDelegate().withMirrors(list));
356             return true;
357         }
358         if (getDelegate().getRepositories().contains(oldDelegate)) {
359             List<org.apache.maven.api.settings.Repository> list = new ArrayList<>(getDelegate().getRepositories());
360             list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.settings.Repository) newDelegate : d);
361             update(getDelegate().withRepositories(list));
362             return true;
363         }
364         if (getDelegate().getPluginRepositories().contains(oldDelegate)) {
365             List<org.apache.maven.api.settings.Repository> list = new ArrayList<>(getDelegate().getPluginRepositories());
366             list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.settings.Repository) newDelegate : d);
367             update(getDelegate().withPluginRepositories(list));
368             return true;
369         }
370         if (getDelegate().getProfiles().contains(oldDelegate)) {
371             List<org.apache.maven.api.settings.Profile> list = new ArrayList<>(getDelegate().getProfiles());
372             list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.settings.Profile) newDelegate : d);
373             update(getDelegate().withProfiles(list));
374             return true;
375         }
376         return false;
377     }
378 
379     public static List<org.apache.maven.api.settings.Settings> settingsToApiV4(List<Settings> list) {
380         return list != null ? new WrapperList<>(list, Settings::getDelegate, Settings::new) : null;
381     }
382 
383     public static List<Settings> settingsToApiV3(List<org.apache.maven.api.settings.Settings> list) {
384         return list != null ? new WrapperList<>(list, Settings::new, Settings::getDelegate) : null;
385     }
386 
387 
388             
389     public Boolean getInteractiveMode()
390     {
391         return Boolean.valueOf( isInteractiveMode() );
392     }
393 
394     private Proxy activeProxy;
395 
396     /**
397      * Reset the <code>activeProxy</code> field to <code>null</code>
398      */
399     public void flushActiveProxy()
400     {
401         this.activeProxy = null;
402     }
403 
404     /**
405      * @return the first active proxy
406      */
407     public synchronized Proxy getActiveProxy()
408     {
409         if ( activeProxy == null )
410         {
411             java.util.List<Proxy> proxies = getProxies();
412             if ( proxies != null && !proxies.isEmpty() )
413             {
414                 for ( Proxy proxy : proxies )
415                 {
416                     if ( proxy.isActive() )
417                     {
418                         activeProxy = proxy;
419                         break;
420                     }
421                 }
422             }
423         }
424 
425         return activeProxy;
426     }
427 
428     public Server getServer( String serverId )
429     {
430         Server match = null;
431 
432         java.util.List<Server> servers = getServers();
433         if ( servers != null && serverId != null )
434         {
435             for ( Server server : servers )
436             {
437                 if ( serverId.equals( server.getId() ) )
438                 {
439                     match = server;
440                     break;
441                 }
442             }
443         }
444 
445         return match;
446     }
447 
448     @Deprecated
449     public Mirror getMirrorOf( String repositoryId )
450     {
451         Mirror match = null;
452 
453         java.util.List<Mirror> mirrors = getMirrors();
454         if ( mirrors != null && repositoryId != null )
455         {
456             for ( Mirror mirror : mirrors )
457             {
458                 if ( repositoryId.equals( mirror.getMirrorOf() ) )
459                 {
460                     match = mirror;
461                     break;
462                 }
463             }
464         }
465 
466         return match;
467     }
468 
469     private java.util.Map<String, Profile> profileMap;
470 
471     /**
472      * Reset the <code>profileMap</code> field to <code>null</code>
473      */
474     public void flushProfileMap()
475     {
476         this.profileMap = null;
477     }
478 
479     /**
480      * @return a Map of profiles field with <code>Profile#getId()</code> as key
481      * @see Profile#getId()
482      */
483     public java.util.Map<String, Profile> getProfilesAsMap()
484     {
485         if ( profileMap == null )
486         {
487             profileMap = new java.util.LinkedHashMap<String, Profile>();
488 
489             if ( getProfiles() != null )
490             {
491                 for ( Profile profile : getProfiles() )
492                 {
493                     profileMap.put( profile.getId(), profile );
494                 }
495             }
496         }
497 
498         return profileMap;
499     }
500             
501           
502 }