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