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.Set;
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
21 @Generated
22 public class DependencyManagement
23 extends BaseObject
24 {
25
26 public DependencyManagement() {
27 this(org.apache.maven.api.model.DependencyManagement.newInstance());
28 }
29
30 public DependencyManagement(org.apache.maven.api.model.DependencyManagement delegate) {
31 this(delegate, null);
32 }
33
34 public DependencyManagement(org.apache.maven.api.model.DependencyManagement delegate, BaseObject parent) {
35 super(delegate, parent);
36 }
37
38 public DependencyManagement clone(){
39 return new DependencyManagement(getDelegate());
40 }
41
42 public org.apache.maven.api.model.DependencyManagement getDelegate() {
43 return (org.apache.maven.api.model.DependencyManagement) super.getDelegate();
44 }
45
46 @Override
47 public boolean equals(Object o) {
48 if (this == o) {
49 return true;
50 }
51 if (o == null || !(o instanceof DependencyManagement)) {
52 return false;
53 }
54 DependencyManagement that = (DependencyManagement) o;
55 return Objects.equals(this.delegate, that.delegate);
56 }
57
58 @Override
59 public int hashCode() {
60 return getDelegate().hashCode();
61 }
62
63 @Nonnull
64 public List<Dependency> getDependencies() {
65 return new WrapperList<Dependency, org.apache.maven.api.model.Dependency>(
66 () -> getDelegate().getDependencies(), l -> update(getDelegate().withDependencies(l)),
67 d -> new Dependency(d, this), Dependency::getDelegate);
68 }
69
70 public void setDependencies(List<Dependency> dependencies) {
71 if (dependencies == null) {
72 dependencies = Collections.emptyList();
73 }
74 if (!Objects.equals(dependencies, getDependencies())) {
75 update(getDelegate().withDependencies(
76 dependencies.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
77 dependencies.forEach(e -> e.childrenTracking = this::replace);
78 }
79 }
80
81 public void addDependency(Dependency dependency) {
82 update(getDelegate().withDependencies(
83 Stream.concat(getDelegate().getDependencies().stream(), Stream.of(dependency.getDelegate()))
84 .collect(Collectors.toList())));
85 dependency.childrenTracking = this::replace;
86 }
87
88 public void removeDependency(Dependency dependency) {
89 update(getDelegate().withDependencies(
90 getDelegate().getDependencies().stream()
91 .filter(e -> !Objects.equals(e, dependency))
92 .collect(Collectors.toList())));
93 dependency.childrenTracking = null;
94 }
95
96 public InputLocation getLocation(Object key) {
97 org.apache.maven.api.model.InputLocation loc = getDelegate().getLocation(key);
98 return loc != null ? new InputLocation(loc) : null;
99 }
100
101 public void setLocation(Object key, InputLocation location) {
102 update(org.apache.maven.api.model.DependencyManagement.newBuilder(getDelegate(), true)
103 .location(key, location.toApiLocation()).build());
104 }
105
106 public InputLocation getImportedFrom() {
107 org.apache.maven.api.model.InputLocation loc = getDelegate().getImportedFrom();
108 return loc != null ? new InputLocation(loc) : null;
109 }
110
111 public void setImportedFrom(InputLocation location) {
112 update(org.apache.maven.api.model.DependencyManagement.newBuilder(getDelegate(), true)
113 .importedFrom(location.toApiLocation()).build());
114 }
115
116 public Set<Object> getLocationKeys() {
117 return getDelegate().getLocationKeys();
118 }
119
120 protected boolean replace(Object oldDelegate, Object newDelegate) {
121 if (super.replace(oldDelegate, newDelegate)) {
122 return true;
123 }
124 if (getDelegate().getDependencies().contains(oldDelegate)) {
125 List<org.apache.maven.api.model.Dependency> list = new ArrayList<>(getDelegate().getDependencies());
126 list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.model.Dependency) newDelegate : d);
127 update(getDelegate().withDependencies(list));
128 return true;
129 }
130 return false;
131 }
132
133 public static List<org.apache.maven.api.model.DependencyManagement> dependencyManagementToApiV4(List<DependencyManagement> list) {
134 return list != null ? new WrapperList<>(list, DependencyManagement::getDelegate, DependencyManagement::new) : null;
135 }
136
137 public static List<DependencyManagement> dependencyManagementToApiV3(List<org.apache.maven.api.model.DependencyManagement> list) {
138 return list != null ? new WrapperList<>(list, DependencyManagement::new, DependencyManagement::getDelegate) : null;
139 }
140
141 }