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