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