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.Properties;
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 Profile
23      extends IdentifiableBase
24      implements Serializable, Cloneable
25  {
26  
27      public Profile()
28      {
29          this( org.apache.maven.api.settings.Profile.newInstance() );
30      }
31  
32      public Profile( org.apache.maven.api.settings.Profile delegate )
33      {
34          this( delegate, null );
35      }
36  
37      public Profile( org.apache.maven.api.settings.Profile delegate, BaseObject parent )
38      {
39          super( delegate, parent );
40      }
41  
42      public Profile clone()
43      {
44          return new Profile( getDelegate() );
45      }
46  
47      @Override
48      public org.apache.maven.api.settings.Profile getDelegate()
49      {
50          return ( org.apache.maven.api.settings.Profile ) super.getDelegate();
51      }
52  
53      @Override
54      public boolean equals( Object o )
55      {
56          if ( this == o )
57          {
58              return true;
59          }
60          if ( o == null || !( o instanceof Profile ) )
61          {
62              return false;
63          }
64          Profile that = ( Profile ) o;
65          return Objects.equals( this.delegate, that.delegate );
66      }
67  
68      @Override
69      public int hashCode()
70      {
71          return getDelegate().hashCode();
72      }
73  
74      public Activation getActivation()
75      {
76          return getDelegate().getActivation() != null ? new Activation( getDelegate().getActivation(), this ) : null;
77      }
78  
79      public void setActivation( Activation activation )
80      {
81          if ( !Objects.equals( activation, getDelegate().getActivation() ) )
82          {
83              update( getDelegate().withActivation( activation.getDelegate() ) );
84              activation.childrenTracking = this::replace;
85          }
86      }
87  
88      @Nonnull
89      public Properties getProperties()
90      {
91          return new WrapperProperties( () -> getDelegate().getProperties(), this::setProperties );
92      }
93  
94      public void setProperties( Properties properties )
95      {
96          Map<String, String> map = properties.entrySet().stream()
97                  .collect( Collectors.toMap( e -> e.getKey().toString(), e -> e.getValue().toString() ) );
98          if ( !Objects.equals( map, getDelegate().getProperties() ) )
99          {
100             update( getDelegate().withProperties( map ) );
101         }
102     }
103 
104     public void addProperty( String key, String value )
105     {
106         getProperties().put( key, value );
107     }
108 
109     @Nonnull
110     public List<Repository> getRepositories()
111     {
112         return new WrapperList<Repository, org.apache.maven.api.settings.Repository>(
113                     () -> getDelegate().getRepositories(), l -> update( getDelegate().withRepositories( l ) ),
114                     d -> new Repository( d, this ), Repository::getDelegate );
115     }
116 
117     public void setRepositories( List<Repository> repositories )
118     {
119         if ( !Objects.equals( repositories, getDelegate().getRepositories() ) )
120         {
121             update( getDelegate().withRepositories(
122                     repositories.stream().map( c -> c.getDelegate() ).collect( Collectors.toList() ) ) );
123             repositories.forEach( e -> e.childrenTracking = this::replace );
124         }
125     }
126 
127     public void addRepository( Repository repository )
128     {
129         update( getDelegate().withRepositories(
130                 Stream.concat( getDelegate().getRepositories().stream(), Stream.of( repository.getDelegate() ) )
131                         .collect( Collectors.toList() ) ) );
132         repository.childrenTracking = this::replace;
133     }
134 
135     public void removeRepository( Repository repository )
136     {
137         update( getDelegate().withRepositories(
138                 getDelegate().getRepositories().stream()
139                         .filter( e -> !Objects.equals( e, repository ) )
140                         .collect( Collectors.toList() ) ) );
141         repository.childrenTracking = null;
142     }
143 
144     @Nonnull
145     public List<Repository> getPluginRepositories()
146     {
147         return new WrapperList<Repository, org.apache.maven.api.settings.Repository>(
148                     () -> getDelegate().getPluginRepositories(), l -> update( getDelegate().withPluginRepositories( l ) ),
149                     d -> new Repository( d, this ), Repository::getDelegate );
150     }
151 
152     public void setPluginRepositories( List<Repository> pluginRepositories )
153     {
154         if ( !Objects.equals( pluginRepositories, getDelegate().getPluginRepositories() ) )
155         {
156             update( getDelegate().withPluginRepositories(
157                     pluginRepositories.stream().map( c -> c.getDelegate() ).collect( Collectors.toList() ) ) );
158             pluginRepositories.forEach( e -> e.childrenTracking = this::replace );
159         }
160     }
161 
162     public void addPluginRepository( Repository pluginRepository )
163     {
164         update( getDelegate().withPluginRepositories(
165                 Stream.concat( getDelegate().getPluginRepositories().stream(), Stream.of( pluginRepository.getDelegate() ) )
166                         .collect( Collectors.toList() ) ) );
167         pluginRepository.childrenTracking = this::replace;
168     }
169 
170     public void removePluginRepository( Repository pluginRepository )
171     {
172         update( getDelegate().withPluginRepositories(
173                 getDelegate().getPluginRepositories().stream()
174                         .filter( e -> !Objects.equals( e, pluginRepository ) )
175                         .collect( Collectors.toList() ) ) );
176         pluginRepository.childrenTracking = null;
177     }
178 
179     protected boolean replace( Object oldDelegate, Object newDelegate )
180     {
181         if ( super.replace( oldDelegate, newDelegate ) )
182         {
183             return true;
184         }
185         if ( oldDelegate == getDelegate().getActivation() )
186         {
187             update( getDelegate().withActivation( ( org.apache.maven.api.settings.Activation ) newDelegate ) );
188             return true;
189         }
190         if ( getDelegate().getRepositories().contains( oldDelegate ) )
191         {
192             List<org.apache.maven.api.settings.Repository> list = new ArrayList<>( getDelegate().getRepositories() );
193             list.replaceAll( d -> d == oldDelegate ? ( org.apache.maven.api.settings.Repository ) newDelegate : d );
194             update( getDelegate().withRepositories( list ) );
195             return true;
196         }
197         if ( getDelegate().getPluginRepositories().contains( oldDelegate ) )
198         {
199             List<org.apache.maven.api.settings.Repository> list = new ArrayList<>( getDelegate().getPluginRepositories() );
200             list.replaceAll( d -> d == oldDelegate ? ( org.apache.maven.api.settings.Repository ) newDelegate : d );
201             update( getDelegate().withPluginRepositories( list ) );
202             return true;
203         }
204         return false;
205     }
206 
207     public static List<org.apache.maven.api.settings.Profile> profileToApiV4( List<Profile> list )
208     {
209         return list != null ? new WrapperList<>( list, Profile::getDelegate, Profile::new ) : null;
210     }
211 
212     public static List<Profile> profileToApiV3( List<org.apache.maven.api.settings.Profile> list )
213     {
214         return list != null ? new WrapperList<>( list, Profile::new, Profile::getDelegate ) : null;
215     }
216 
217 }