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