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