1
2
3
4
5 package org.apache.maven.api.model;
6
7 import java.io.Serializable;
8 import java.util.ArrayList;
9 import java.util.Collection;
10 import java.util.Collections;
11 import java.util.HashMap;
12 import java.util.List;
13 import java.util.Map;
14 import org.apache.maven.api.annotations.Experimental;
15 import org.apache.maven.api.annotations.Generated;
16 import org.apache.maven.api.annotations.Immutable;
17 import org.apache.maven.api.annotations.Nonnull;
18 import org.apache.maven.api.annotations.NotThreadSafe;
19 import org.apache.maven.api.annotations.ThreadSafe;
20
21
22
23
24
25 @Experimental
26 @Generated @ThreadSafe @Immutable
27 public class DependencyManagement
28 implements Serializable, InputLocationTracker
29 {
30
31
32
33
34
35 final List<Dependency> dependencies;
36
37 final Map<Object, InputLocation> locations;
38
39
40
41
42
43 DependencyManagement(
44 Collection<Dependency> dependencies,
45 Map<Object, InputLocation> locations
46 ) {
47 this.dependencies = ImmutableCollections.copy(dependencies);
48 this.locations = ImmutableCollections.copy(locations);
49 }
50
51
52
53
54
55
56
57
58 @Nonnull
59 public List<Dependency> getDependencies() {
60 return this.dependencies;
61 }
62
63
64
65
66 public InputLocation getLocation(Object key) {
67 return locations != null ? locations.get(key) : null;
68 }
69
70
71
72
73
74
75 @Nonnull
76 public Builder with() {
77 return newBuilder(this);
78 }
79
80
81
82
83
84
85 @Nonnull
86 public DependencyManagement withDependencies(Collection<Dependency> dependencies) {
87 return newBuilder(this, true).dependencies(dependencies).build();
88 }
89
90
91
92
93
94
95
96
97 @Nonnull
98 public static DependencyManagement newInstance() {
99 return newInstance(true);
100 }
101
102
103
104
105
106
107
108
109 @Nonnull
110 public static DependencyManagement newInstance(boolean withDefaults) {
111 return newBuilder(withDefaults).build();
112 }
113
114
115
116
117
118
119
120
121 @Nonnull
122 public static Builder newBuilder() {
123 return newBuilder(true);
124 }
125
126
127
128
129
130
131
132 @Nonnull
133 public static Builder newBuilder(boolean withDefaults) {
134 return new Builder(withDefaults);
135 }
136
137
138
139
140
141
142
143
144 @Nonnull
145 public static Builder newBuilder(DependencyManagement from) {
146 return newBuilder(from, false);
147 }
148
149
150
151
152
153
154
155
156 @Nonnull
157 public static Builder newBuilder(DependencyManagement from, boolean forceCopy) {
158 return new Builder(from, forceCopy);
159 }
160
161
162
163
164
165
166 @NotThreadSafe
167 public static class Builder
168 {
169 DependencyManagement base;
170 Collection<Dependency> dependencies;
171 Map<Object, InputLocation> locations;
172
173 Builder(boolean withDefaults) {
174 if (withDefaults) {
175 }
176 }
177
178 Builder(DependencyManagement base, boolean forceCopy) {
179 if (forceCopy) {
180 this.dependencies = base.dependencies;
181 this.locations = base.locations;
182 } else {
183 this.base = base;
184 }
185 }
186
187 @Nonnull
188 public Builder dependencies(Collection<Dependency> dependencies) {
189 this.dependencies = dependencies;
190 return this;
191 }
192
193
194 @Nonnull
195 public Builder location(Object key, InputLocation location) {
196 if (location != null) {
197 if (!(this.locations instanceof HashMap)) {
198 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
199 }
200 this.locations.put(key, location);
201 }
202 return this;
203 }
204
205 @Nonnull
206 public DependencyManagement build() {
207 if (base != null
208 && (dependencies == null || dependencies == base.dependencies)
209 ) {
210 return base;
211 }
212 Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
213 Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
214 Map<Object, InputLocation> locations = new HashMap<>();
215 locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
216 locations.put("dependencies", newlocs.containsKey("dependencies") ? newlocs.get("dependencies") : oldlocs.get("dependencies"));
217 return new DependencyManagement(
218 dependencies != null ? dependencies : (base != null ? base.dependencies : null),
219 locations
220 );
221 }
222 }
223
224 }