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