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 InputLocation location;
38
39 final InputLocation dependenciesLocation;
40
41 final Map<Object, InputLocation> locations;
42
43
44
45
46
47 DependencyManagement(
48 Collection<Dependency> dependencies,
49 Map<Object, InputLocation> locations,
50 InputLocation location,
51 InputLocation dependenciesLocation
52 )
53 {
54 this.dependencies = ImmutableCollections.copy( dependencies );
55 this.locations = ImmutableCollections.copy( locations );
56 this.location = location;
57 this.dependenciesLocation = dependenciesLocation;
58 }
59
60
61
62
63
64
65
66
67 @Nonnull
68 public List<Dependency> getDependencies()
69 {
70 return this.dependencies;
71 }
72
73
74
75
76 public InputLocation getLocation( Object key )
77 {
78 if ( key instanceof String )
79 {
80 switch ( ( String ) key )
81 {
82 case "":
83 return location;
84 case "dependencies":
85 return dependenciesLocation;
86 }
87 }
88 return locations != null ? locations.get( key ) : null;
89 }
90
91
92
93
94
95
96 @Nonnull
97 public Builder with()
98 {
99 return newBuilder( this );
100 }
101
102
103
104
105
106
107 @Nonnull
108 public DependencyManagement withDependencies( Collection<Dependency> dependencies )
109 {
110 return with().dependencies( dependencies ).build();
111 }
112
113
114
115
116
117
118
119
120 @Nonnull
121 public static DependencyManagement newInstance()
122 {
123 return newInstance( true );
124 }
125
126
127
128
129
130
131
132
133 @Nonnull
134 public static DependencyManagement newInstance( boolean withDefaults )
135 {
136 return newBuilder( withDefaults ).build();
137 }
138
139
140
141
142
143
144
145
146 @Nonnull
147 public static Builder newBuilder()
148 {
149 return newBuilder( true );
150 }
151
152
153
154
155
156
157
158 @Nonnull
159 public static Builder newBuilder( boolean withDefaults )
160 {
161 return new Builder( withDefaults );
162 }
163
164
165
166
167
168
169
170
171 @Nonnull
172 public static Builder newBuilder( DependencyManagement from )
173 {
174 return newBuilder( from, false );
175 }
176
177
178
179
180
181
182
183
184 @Nonnull
185 public static Builder newBuilder( DependencyManagement from, boolean forceCopy )
186 {
187 return new Builder( from, forceCopy );
188 }
189
190
191
192
193
194
195 @NotThreadSafe
196 public static class Builder
197 {
198 DependencyManagement base;
199 Collection<Dependency> dependencies;
200 Map<Object, InputLocation> locations;
201
202 Builder( boolean withDefaults )
203 {
204 if ( withDefaults )
205 {
206 }
207 }
208
209 Builder( DependencyManagement base, boolean forceCopy )
210 {
211 if ( forceCopy )
212 {
213 this.dependencies = base.dependencies;
214 }
215 else
216 {
217 this.base = base;
218 }
219 }
220
221 @Nonnull
222 public Builder dependencies( Collection<Dependency> dependencies )
223 {
224 this.dependencies = dependencies;
225 return this;
226 }
227
228
229 @Nonnull
230 public Builder location( Object key, InputLocation location )
231 {
232 if ( location != null )
233 {
234 if ( this.locations == null )
235 {
236 this.locations = new HashMap<>();
237 }
238 this.locations.put( key, location );
239 }
240 return this;
241 }
242
243 @Nonnull
244 public DependencyManagement build()
245 {
246 if ( base != null
247 && ( dependencies == null || dependencies == base.dependencies )
248 )
249 {
250 return base;
251 }
252 Map<Object, InputLocation> locations = null;
253 InputLocation location = null;
254 InputLocation dependenciesLocation = null;
255 if ( this.locations != null )
256 {
257 locations = this.locations;
258 location = locations.remove( "" );
259 dependenciesLocation = locations.remove( "dependencies" );
260 }
261 return new DependencyManagement(
262 dependencies != null ? dependencies : ( base != null ? base.dependencies : null ),
263 locations != null ? locations : ( base != null ? base.locations : null ),
264 location != null ? location : ( base != null ? base.location : null ),
265 dependenciesLocation != null ? dependenciesLocation : ( base != null ? base.dependenciesLocation : null )
266 );
267 }
268 }
269
270 }