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