1
2
3
4
5 package org.apache.maven.api.settings;
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 java.util.Set;
15 import org.apache.maven.api.annotations.Experimental;
16 import org.apache.maven.api.annotations.Generated;
17 import org.apache.maven.api.annotations.Immutable;
18 import org.apache.maven.api.annotations.Nonnull;
19 import org.apache.maven.api.annotations.NotThreadSafe;
20 import org.apache.maven.api.annotations.ThreadSafe;
21
22
23
24
25 @Experimental
26 @Generated @ThreadSafe @Immutable
27 public class Profile
28 extends IdentifiableBase
29 implements Serializable, InputLocationTracker
30 {
31
32
33
34 final Activation activation;
35
36
37
38
39 final Map<String, String> properties;
40
41
42
43 final List<Repository> repositories;
44
45
46
47 final List<Repository> pluginRepositories;
48
49 final Map<Object, InputLocation> locations;
50
51
52
53
54
55 protected Profile(Builder builder) {
56 super(builder);
57 this.activation = builder.activation != null ? builder.activation : (builder.base != null ? builder.base.activation : null);
58 this.properties = ImmutableCollections.copy(builder.properties != null ? builder.properties : (builder.base != null ? builder.base.properties : null));
59 this.repositories = ImmutableCollections.copy(builder.repositories != null ? builder.repositories : (builder.base != null ? builder.base.repositories : null));
60 this.pluginRepositories = ImmutableCollections.copy(builder.pluginRepositories != null ? builder.pluginRepositories : (builder.base != null ? builder.base.pluginRepositories : null));
61 Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
62 Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
63 Map<Object, InputLocation> mutableLocations = new HashMap<>(super.locations);
64 mutableLocations.put("activation", newlocs.containsKey("activation") ? newlocs.get("activation") : oldlocs.get("activation"));
65 mutableLocations.put("properties", newlocs.containsKey("properties") ? newlocs.get("properties") : oldlocs.get("properties"));
66 mutableLocations.put("repositories", newlocs.containsKey("repositories") ? newlocs.get("repositories") : oldlocs.get("repositories"));
67 mutableLocations.put("pluginRepositories", newlocs.containsKey("pluginRepositories") ? newlocs.get("pluginRepositories") : oldlocs.get("pluginRepositories"));
68 this.locations = Collections.unmodifiableMap(mutableLocations);
69 }
70
71
72
73
74
75
76 public Activation getActivation() {
77 return this.activation;
78 }
79
80
81
82
83
84
85
86 @Nonnull
87 public Map<String, String> getProperties() {
88 return this.properties;
89 }
90
91
92
93
94
95
96 @Nonnull
97 public List<Repository> getRepositories() {
98 return this.repositories;
99 }
100
101
102
103
104
105
106 @Nonnull
107 public List<Repository> getPluginRepositories() {
108 return this.pluginRepositories;
109 }
110
111
112
113
114 public InputLocation getLocation(Object key) {
115 return locations != null ? locations.get(key) : null;
116 }
117
118
119
120
121 public Set<Object> getLocationKeys() {
122 return locations != null ? locations.keySet() : null;
123 }
124
125
126
127
128
129
130 @Nonnull
131 public Builder with() {
132 return newBuilder(this);
133 }
134
135
136
137
138
139
140 @Nonnull
141 public Profile withId(String id) {
142 return newBuilder(this, true).id(id).build();
143 }
144
145
146
147
148
149
150 @Nonnull
151 public Profile withActivation(Activation activation) {
152 return newBuilder(this, true).activation(activation).build();
153 }
154
155
156
157
158
159
160 @Nonnull
161 public Profile withProperties(Map<String, String> properties) {
162 return newBuilder(this, true).properties(properties).build();
163 }
164
165
166
167
168
169
170 @Nonnull
171 public Profile withRepositories(Collection<Repository> repositories) {
172 return newBuilder(this, true).repositories(repositories).build();
173 }
174
175
176
177
178
179
180 @Nonnull
181 public Profile withPluginRepositories(Collection<Repository> pluginRepositories) {
182 return newBuilder(this, true).pluginRepositories(pluginRepositories).build();
183 }
184
185
186
187
188
189
190
191
192 @Nonnull
193 public static Profile newInstance() {
194 return newInstance(true);
195 }
196
197
198
199
200
201
202
203
204 @Nonnull
205 public static Profile newInstance(boolean withDefaults) {
206 return newBuilder(withDefaults).build();
207 }
208
209
210
211
212
213
214
215
216 @Nonnull
217 public static Builder newBuilder() {
218 return newBuilder(true);
219 }
220
221
222
223
224
225
226
227 @Nonnull
228 public static Builder newBuilder(boolean withDefaults) {
229 return new Builder(withDefaults);
230 }
231
232
233
234
235
236
237
238
239 @Nonnull
240 public static Builder newBuilder(Profile from) {
241 return newBuilder(from, false);
242 }
243
244
245
246
247
248
249
250
251 @Nonnull
252 public static Builder newBuilder(Profile from, boolean forceCopy) {
253 return new Builder(from, forceCopy);
254 }
255
256
257
258
259
260
261 @NotThreadSafe
262 public static class Builder
263 extends IdentifiableBase.Builder
264 {
265 Profile base;
266 Activation activation;
267 Map<String, String> properties;
268 Collection<Repository> repositories;
269 Collection<Repository> pluginRepositories;
270
271 protected Builder(boolean withDefaults) {
272 super(withDefaults);
273 if (withDefaults) {
274 }
275 }
276
277 protected Builder(Profile base, boolean forceCopy) {
278 super(base, forceCopy);
279 if (forceCopy) {
280 this.activation = base.activation;
281 this.properties = base.properties;
282 this.repositories = base.repositories;
283 this.pluginRepositories = base.pluginRepositories;
284 this.locations = base.locations;
285 this.importedFrom = base.importedFrom;
286 } else {
287 this.base = base;
288 }
289 }
290
291 @Nonnull
292 public Builder id(String id) {
293 this.id = id;
294 return this;
295 }
296
297 @Nonnull
298 public Builder activation(Activation activation) {
299 this.activation = activation;
300 return this;
301 }
302
303 @Nonnull
304 public Builder properties(Map<String, String> properties) {
305 this.properties = properties;
306 return this;
307 }
308
309 @Nonnull
310 public Builder repositories(Collection<Repository> repositories) {
311 this.repositories = repositories;
312 return this;
313 }
314
315 @Nonnull
316 public Builder pluginRepositories(Collection<Repository> pluginRepositories) {
317 this.pluginRepositories = pluginRepositories;
318 return this;
319 }
320
321
322 @Nonnull
323 public Builder location(Object key, InputLocation location) {
324 if (location != null) {
325 if (!(this.locations instanceof HashMap)) {
326 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
327 }
328 this.locations.put(key, location);
329 }
330 return this;
331 }
332
333 @Nonnull
334 public Builder importedFrom(InputLocation importedFrom) {
335 this.importedFrom = importedFrom;
336 return this;
337 }
338
339 @Nonnull
340 public Profile build() {
341
342 if (base != null
343 && (id == null || id == base.id)
344 && (activation == null || activation == base.activation)
345 && (properties == null || properties == base.properties)
346 && (repositories == null || repositories == base.repositories)
347 && (pluginRepositories == null || pluginRepositories == base.pluginRepositories)
348 ) {
349 return base;
350 }
351 return new Profile(this);
352 }
353 }
354
355 }