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