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