View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //   Generated by Maven, any modifications will be overwritten.
3   // ==============================================================
4   package org.apache.maven.model;
5   
6   import java.io.Serializable;
7   import java.util.AbstractList;
8   import java.util.ArrayList;
9   import java.util.Collections;
10  import java.util.HashMap;
11  import java.util.List;
12  import java.util.Map;
13  import java.util.Objects;
14  import java.util.Properties;
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  import org.codehaus.plexus.util.xml.Xpp3Dom;
20  
21  @Generated
22  public class ModelBase
23      extends BaseObject
24  {
25  
26      public ModelBase()
27      {
28          this( org.apache.maven.api.model.ModelBase.newInstance() );
29      }
30  
31      public ModelBase( org.apache.maven.api.model.ModelBase delegate )
32      {
33          this( delegate, null );
34      }
35  
36      public ModelBase( org.apache.maven.api.model.ModelBase delegate, BaseObject parent )
37      {
38          super( delegate, parent );
39      }
40  
41      public ModelBase clone()
42      {
43          return new ModelBase( getDelegate() );
44      }
45  
46      public org.apache.maven.api.model.ModelBase getDelegate()
47      {
48          return ( org.apache.maven.api.model.ModelBase ) super.getDelegate();
49      }
50  
51      @Nonnull
52      public List<String> getModules()
53      {
54          return new WrapperList<String, String>( () -> getDelegate().getModules(), this::setModules, s -> s, s -> s );
55      }
56  
57      public void setModules( List<String> modules )
58      {
59          if ( !Objects.equals( modules, getDelegate().getModules() ) )
60          {
61              update( getDelegate().withModules( modules ) );
62          }
63      }
64  
65      public void addModule( String module )
66      {
67          update( getDelegate().withModules(
68                  Stream.concat( getDelegate().getModules().stream(), Stream.of( module ) )
69                          .collect( Collectors.toList() ) ) );
70      }
71  
72      public void removeModule( String module )
73      {
74          update( getDelegate().withModules(
75                  getDelegate().getModules().stream()
76                          .filter( e -> !Objects.equals( e, module ) )
77                          .collect( Collectors.toList() ) ) );
78      }
79  
80      public DistributionManagement getDistributionManagement()
81      {
82          return getDelegate().getDistributionManagement() != null ? new DistributionManagement( getDelegate().getDistributionManagement(), this ) : null;
83      }
84  
85      public void setDistributionManagement( DistributionManagement distributionManagement )
86      {
87          if ( !Objects.equals( distributionManagement, getDelegate().getDistributionManagement() ) )
88          {
89              update( getDelegate().withDistributionManagement( distributionManagement.getDelegate() ) );
90              distributionManagement.childrenTracking = this::replace;
91          }
92      }
93  
94      @Nonnull
95      public Properties getProperties()
96      {
97          return new WrapperProperties( () -> getDelegate().getProperties(), this::setProperties );
98      }
99  
100     public void setProperties( Properties properties )
101     {
102         Map<String, String> map = properties.entrySet().stream()
103                 .collect( Collectors.toMap( e -> e.getKey().toString(), e -> e.getValue().toString() ) );
104         if ( !Objects.equals( map, getDelegate().getProperties() ) )
105         {
106             update( getDelegate().withProperties( map ) );
107         }
108     }
109 
110     public DependencyManagement getDependencyManagement()
111     {
112         return getDelegate().getDependencyManagement() != null ? new DependencyManagement( getDelegate().getDependencyManagement(), this ) : null;
113     }
114 
115     public void setDependencyManagement( DependencyManagement dependencyManagement )
116     {
117         if ( !Objects.equals( dependencyManagement, getDelegate().getDependencyManagement() ) )
118         {
119             update( getDelegate().withDependencyManagement( dependencyManagement.getDelegate() ) );
120             dependencyManagement.childrenTracking = this::replace;
121         }
122     }
123 
124     @Nonnull
125     public List<Dependency> getDependencies()
126     {
127         return new WrapperList<Dependency, org.apache.maven.api.model.Dependency>(
128                     () -> getDelegate().getDependencies(), l -> update( getDelegate().withDependencies( l ) ),
129                     d -> new Dependency( d, this ), Dependency::getDelegate );
130     }
131 
132     public void setDependencies( List<Dependency> dependencies )
133     {
134         if ( !Objects.equals( dependencies, getDelegate().getDependencies() ) )
135         {
136             update( getDelegate().withDependencies(
137                     dependencies.stream().map( c -> c.getDelegate() ).collect( Collectors.toList() ) ) );
138             dependencies.forEach( e -> e.childrenTracking = this::replace );
139         }
140     }
141 
142     public void addDependency( Dependency dependency )
143     {
144         update( getDelegate().withDependencies(
145                 Stream.concat( getDelegate().getDependencies().stream(), Stream.of( dependency.getDelegate() ) )
146                         .collect( Collectors.toList() ) ) );
147         dependency.childrenTracking = this::replace;
148     }
149 
150     public void removeDependency( Dependency dependency )
151     {
152         update( getDelegate().withDependencies(
153                 getDelegate().getDependencies().stream()
154                         .filter( e -> !Objects.equals( e, dependency ) )
155                         .collect( Collectors.toList() ) ) );
156         dependency.childrenTracking = null;
157     }
158 
159     @Nonnull
160     public List<Repository> getRepositories()
161     {
162         return new WrapperList<Repository, org.apache.maven.api.model.Repository>(
163                     () -> getDelegate().getRepositories(), l -> update( getDelegate().withRepositories( l ) ),
164                     d -> new Repository( d, this ), Repository::getDelegate );
165     }
166 
167     public void setRepositories( List<Repository> repositories )
168     {
169         if ( !Objects.equals( repositories, getDelegate().getRepositories() ) )
170         {
171             update( getDelegate().withRepositories(
172                     repositories.stream().map( c -> c.getDelegate() ).collect( Collectors.toList() ) ) );
173             repositories.forEach( e -> e.childrenTracking = this::replace );
174         }
175     }
176 
177     public void addRepository( Repository repository )
178     {
179         update( getDelegate().withRepositories(
180                 Stream.concat( getDelegate().getRepositories().stream(), Stream.of( repository.getDelegate() ) )
181                         .collect( Collectors.toList() ) ) );
182         repository.childrenTracking = this::replace;
183     }
184 
185     public void removeRepository( Repository repository )
186     {
187         update( getDelegate().withRepositories(
188                 getDelegate().getRepositories().stream()
189                         .filter( e -> !Objects.equals( e, repository ) )
190                         .collect( Collectors.toList() ) ) );
191         repository.childrenTracking = null;
192     }
193 
194     @Nonnull
195     public List<Repository> getPluginRepositories()
196     {
197         return new WrapperList<Repository, org.apache.maven.api.model.Repository>(
198                     () -> getDelegate().getPluginRepositories(), l -> update( getDelegate().withPluginRepositories( l ) ),
199                     d -> new Repository( d, this ), Repository::getDelegate );
200     }
201 
202     public void setPluginRepositories( List<Repository> pluginRepositories )
203     {
204         if ( !Objects.equals( pluginRepositories, getDelegate().getPluginRepositories() ) )
205         {
206             update( getDelegate().withPluginRepositories(
207                     pluginRepositories.stream().map( c -> c.getDelegate() ).collect( Collectors.toList() ) ) );
208             pluginRepositories.forEach( e -> e.childrenTracking = this::replace );
209         }
210     }
211 
212     public void addPluginRepository( Repository pluginRepository )
213     {
214         update( getDelegate().withPluginRepositories(
215                 Stream.concat( getDelegate().getPluginRepositories().stream(), Stream.of( pluginRepository.getDelegate() ) )
216                         .collect( Collectors.toList() ) ) );
217         pluginRepository.childrenTracking = this::replace;
218     }
219 
220     public void removePluginRepository( Repository pluginRepository )
221     {
222         update( getDelegate().withPluginRepositories(
223                 getDelegate().getPluginRepositories().stream()
224                         .filter( e -> !Objects.equals( e, pluginRepository ) )
225                         .collect( Collectors.toList() ) ) );
226         pluginRepository.childrenTracking = null;
227     }
228 
229     public Reporting getReporting()
230     {
231         return getDelegate().getReporting() != null ? new Reporting( getDelegate().getReporting(), this ) : null;
232     }
233 
234     public void setReporting( Reporting reporting )
235     {
236         if ( !Objects.equals( reporting, getDelegate().getReporting() ) )
237         {
238             update( getDelegate().withReporting( reporting.getDelegate() ) );
239             reporting.childrenTracking = this::replace;
240         }
241     }
242 
243     public InputLocation getLocation( Object key )
244     {
245         org.apache.maven.api.model.InputLocation loc = getDelegate().getLocation( key );
246         return loc != null ? new InputLocation( loc ) : null;
247     }
248 
249     public void setLocation( Object key, InputLocation location )
250     {
251         update( org.apache.maven.api.model.ModelBase.newBuilder( getDelegate(), true )
252                         .location( key, location.toApiLocation() ).build() );
253     }
254 
255     protected boolean replace( Object oldDelegate, Object newDelegate )
256     {
257         if ( super.replace( oldDelegate, newDelegate ) )
258         {
259             return true;
260         }
261         if ( oldDelegate == getDelegate().getDistributionManagement() )
262         {
263             update( getDelegate().withDistributionManagement( ( org.apache.maven.api.model.DistributionManagement ) newDelegate ) );
264             return true;
265         }
266         if ( oldDelegate == getDelegate().getDependencyManagement() )
267         {
268             update( getDelegate().withDependencyManagement( ( org.apache.maven.api.model.DependencyManagement ) newDelegate ) );
269             return true;
270         }
271         if ( getDelegate().getDependencies().contains( oldDelegate ) )
272         {
273             List<org.apache.maven.api.model.Dependency> list = new ArrayList<>( getDelegate().getDependencies() );
274             list.replaceAll( d -> d == oldDelegate ? ( org.apache.maven.api.model.Dependency ) newDelegate : d );
275             update( getDelegate().withDependencies( list ) );
276             return true;
277         }
278         if ( getDelegate().getRepositories().contains( oldDelegate ) )
279         {
280             List<org.apache.maven.api.model.Repository> list = new ArrayList<>( getDelegate().getRepositories() );
281             list.replaceAll( d -> d == oldDelegate ? ( org.apache.maven.api.model.Repository ) newDelegate : d );
282             update( getDelegate().withRepositories( list ) );
283             return true;
284         }
285         if ( getDelegate().getPluginRepositories().contains( oldDelegate ) )
286         {
287             List<org.apache.maven.api.model.Repository> list = new ArrayList<>( getDelegate().getPluginRepositories() );
288             list.replaceAll( d -> d == oldDelegate ? ( org.apache.maven.api.model.Repository ) newDelegate : d );
289             update( getDelegate().withPluginRepositories( list ) );
290             return true;
291         }
292         if ( oldDelegate == getDelegate().getReporting() )
293         {
294             update( getDelegate().withReporting( ( org.apache.maven.api.model.Reporting ) newDelegate ) );
295             return true;
296         }
297         return false;
298     }
299 
300     public static List<org.apache.maven.api.model.ModelBase> modelBaseToApiV4( List<ModelBase> list )
301     {
302         return list != null ? new WrapperList<>( list, ModelBase::getDelegate, ModelBase::new ) : null;
303     }
304 
305     public static List<ModelBase> modelBaseToApiV3( List<org.apache.maven.api.model.ModelBase> list )
306     {
307         return list != null ? new WrapperList<>( list, ModelBase::new, ModelBase::getDelegate ) : null;
308     }
309 
310 }