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