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