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.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 if (distributionManagement != null) {
95 update(getDelegate().withDistributionManagement(distributionManagement.getDelegate()));
96 distributionManagement.childrenTracking = this::replace;
97 } else {
98 update(getDelegate().withDistributionManagement(null));
99 }
100 }
101 }
102
103 @Nonnull
104 public Properties getProperties() {
105 return new WrapperProperties(() -> getDelegate().getProperties(), this::setProperties);
106 }
107
108 public void setProperties(Properties properties) {
109 Map<String, String> map = properties.entrySet().stream()
110 .collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue().toString()));
111 if (!Objects.equals(map, getDelegate().getProperties())) {
112 update(getDelegate().withProperties(map));
113 }
114 }
115
116 public void addProperty(String key, String value) {
117 getProperties().put(key, value);
118 }
119
120 public DependencyManagement getDependencyManagement() {
121 return getDelegate().getDependencyManagement() != null ? new DependencyManagement(getDelegate().getDependencyManagement(), this) : null;
122 }
123
124 public void setDependencyManagement(DependencyManagement dependencyManagement) {
125 if (!Objects.equals(dependencyManagement, getDependencyManagement())){
126 if (dependencyManagement != null) {
127 update(getDelegate().withDependencyManagement(dependencyManagement.getDelegate()));
128 dependencyManagement.childrenTracking = this::replace;
129 } else {
130 update(getDelegate().withDependencyManagement(null));
131 }
132 }
133 }
134
135 @Nonnull
136 public List<Dependency> getDependencies() {
137 return new WrapperList<Dependency, org.apache.maven.api.model.Dependency>(
138 () -> getDelegate().getDependencies(), l -> update(getDelegate().withDependencies(l)),
139 d -> new Dependency(d, this), Dependency::getDelegate);
140 }
141
142 public void setDependencies(List<Dependency> dependencies) {
143 if (dependencies == null) {
144 dependencies = Collections.emptyList();
145 }
146 if (!Objects.equals(dependencies, getDependencies())) {
147 update(getDelegate().withDependencies(
148 dependencies.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
149 dependencies.forEach(e -> e.childrenTracking = this::replace);
150 }
151 }
152
153 public void addDependency(Dependency dependency) {
154 update(getDelegate().withDependencies(
155 Stream.concat(getDelegate().getDependencies().stream(), Stream.of(dependency.getDelegate()))
156 .collect(Collectors.toList())));
157 dependency.childrenTracking = this::replace;
158 }
159
160 public void removeDependency(Dependency dependency) {
161 update(getDelegate().withDependencies(
162 getDelegate().getDependencies().stream()
163 .filter(e -> !Objects.equals(e, dependency))
164 .collect(Collectors.toList())));
165 dependency.childrenTracking = null;
166 }
167
168 @Nonnull
169 public List<Repository> getRepositories() {
170 return new WrapperList<Repository, org.apache.maven.api.model.Repository>(
171 () -> getDelegate().getRepositories(), l -> update(getDelegate().withRepositories(l)),
172 d -> new Repository(d, this), Repository::getDelegate);
173 }
174
175 public void setRepositories(List<Repository> repositories) {
176 if (repositories == null) {
177 repositories = Collections.emptyList();
178 }
179 if (!Objects.equals(repositories, getRepositories())) {
180 update(getDelegate().withRepositories(
181 repositories.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
182 repositories.forEach(e -> e.childrenTracking = this::replace);
183 }
184 }
185
186 public void addRepository(Repository repository) {
187 update(getDelegate().withRepositories(
188 Stream.concat(getDelegate().getRepositories().stream(), Stream.of(repository.getDelegate()))
189 .collect(Collectors.toList())));
190 repository.childrenTracking = this::replace;
191 }
192
193 public void removeRepository(Repository repository) {
194 update(getDelegate().withRepositories(
195 getDelegate().getRepositories().stream()
196 .filter(e -> !Objects.equals(e, repository))
197 .collect(Collectors.toList())));
198 repository.childrenTracking = null;
199 }
200
201 @Nonnull
202 public List<Repository> getPluginRepositories() {
203 return new WrapperList<Repository, org.apache.maven.api.model.Repository>(
204 () -> getDelegate().getPluginRepositories(), l -> update(getDelegate().withPluginRepositories(l)),
205 d -> new Repository(d, this), Repository::getDelegate);
206 }
207
208 public void setPluginRepositories(List<Repository> pluginRepositories) {
209 if (pluginRepositories == null) {
210 pluginRepositories = Collections.emptyList();
211 }
212 if (!Objects.equals(pluginRepositories, getPluginRepositories())) {
213 update(getDelegate().withPluginRepositories(
214 pluginRepositories.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
215 pluginRepositories.forEach(e -> e.childrenTracking = this::replace);
216 }
217 }
218
219 public void addPluginRepository(Repository pluginRepository) {
220 update(getDelegate().withPluginRepositories(
221 Stream.concat(getDelegate().getPluginRepositories().stream(), Stream.of(pluginRepository.getDelegate()))
222 .collect(Collectors.toList())));
223 pluginRepository.childrenTracking = this::replace;
224 }
225
226 public void removePluginRepository(Repository pluginRepository) {
227 update(getDelegate().withPluginRepositories(
228 getDelegate().getPluginRepositories().stream()
229 .filter(e -> !Objects.equals(e, pluginRepository))
230 .collect(Collectors.toList())));
231 pluginRepository.childrenTracking = null;
232 }
233
234 public Reporting getReporting() {
235 return getDelegate().getReporting() != null ? new Reporting(getDelegate().getReporting(), this) : null;
236 }
237
238 public void setReporting(Reporting reporting) {
239 if (!Objects.equals(reporting, getReporting())){
240 if (reporting != null) {
241 update(getDelegate().withReporting(reporting.getDelegate()));
242 reporting.childrenTracking = this::replace;
243 } else {
244 update(getDelegate().withReporting(null));
245 }
246 }
247 }
248
249 public InputLocation getLocation(Object key) {
250 org.apache.maven.api.model.InputLocation loc = getDelegate().getLocation(key);
251 return loc != null ? new InputLocation(loc) : null;
252 }
253
254 public void setLocation(Object key, InputLocation location) {
255 update(org.apache.maven.api.model.ModelBase.newBuilder(getDelegate(), true)
256 .location(key, location.toApiLocation()).build());
257 }
258
259 protected boolean replace(Object oldDelegate, Object newDelegate) {
260 if (super.replace(oldDelegate, newDelegate)) {
261 return true;
262 }
263 if (oldDelegate == getDelegate().getDistributionManagement()) {
264 update(getDelegate().withDistributionManagement((org.apache.maven.api.model.DistributionManagement) newDelegate));
265 return true;
266 }
267 if (oldDelegate == getDelegate().getDependencyManagement()) {
268 update(getDelegate().withDependencyManagement((org.apache.maven.api.model.DependencyManagement) newDelegate));
269 return true;
270 }
271 if (getDelegate().getDependencies().contains(oldDelegate)) {
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 List<org.apache.maven.api.model.Repository> list = new ArrayList<>(getDelegate().getRepositories());
279 list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.model.Repository) newDelegate : d);
280 update(getDelegate().withRepositories(list));
281 return true;
282 }
283 if (getDelegate().getPluginRepositories().contains(oldDelegate)) {
284 List<org.apache.maven.api.model.Repository> list = new ArrayList<>(getDelegate().getPluginRepositories());
285 list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.model.Repository) newDelegate : d);
286 update(getDelegate().withPluginRepositories(list));
287 return true;
288 }
289 if (oldDelegate == getDelegate().getReporting()) {
290 update(getDelegate().withReporting((org.apache.maven.api.model.Reporting) newDelegate));
291 return true;
292 }
293 return false;
294 }
295
296 public static List<org.apache.maven.api.model.ModelBase> modelBaseToApiV4(List<ModelBase> list) {
297 return list != null ? new WrapperList<>(list, ModelBase::getDelegate, ModelBase::new) : null;
298 }
299
300 public static List<ModelBase> modelBaseToApiV3(List<org.apache.maven.api.model.ModelBase> list) {
301 return list != null ? new WrapperList<>(list, ModelBase::new, ModelBase::getDelegate) : null;
302 }
303
304 }