1 // =================== DO NOT EDIT THIS FILE ====================
2 // Generated by Modello Velocity from model.vm
3 // template, any modifications will be overwritten.
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 java.util.Objects;
12 import org.apache.maven.api.annotations.Experimental;
13 import org.apache.maven.api.annotations.Generated;
14 import org.apache.maven.api.annotations.Immutable;
15 import org.apache.maven.api.annotations.Nonnull;
16 import org.apache.maven.api.annotations.NotThreadSafe;
17 import org.apache.maven.api.annotations.ThreadSafe;
18
19 /**
20 * A repository contains the information needed for establishing connections with
21 * remote repository.
22 */
23 @Experimental
24 @Generated @ThreadSafe @Immutable
25 public class RepositoryBase
26 implements Serializable, InputLocationTracker
27 {
28 /**
29 * A unique identifier for a repository. This is used to match the repository
30 * to configuration in the {@code settings.xml} file, for example. Furthermore, the identifier is
31 * used during POM inheritance and profile injection to detect repositories that should be merged.
32 */
33 final String id;
34 /**
35 * Human readable name of the repository.
36 */
37 final String name;
38 /**
39 * The url of the repository, in the form {@code protocol://hostname/path}.
40 */
41 final String url;
42 /**
43 * The type of layout this repository uses for locating and storing artifacts -
44 * can be {@code legacy} or {@code default}.
45 */
46 final String layout;
47 /** Locations */
48 final Map<Object, InputLocation> locations;
49
50 /**
51 * Constructor for this class, package protected.
52 * @see Builder#build()
53 */
54 RepositoryBase(
55 String id,
56 String name,
57 String url,
58 String layout,
59 Map<Object, InputLocation> locations
60 ) {
61 this.id = id;
62 this.name = name;
63 this.url = url;
64 this.layout = layout;
65 this.locations = ImmutableCollections.copy(locations);
66 }
67
68 @Override
69 public boolean equals(Object o) {
70 if (this == o) {
71 return true;
72 }
73 if (o == null || !(o instanceof RepositoryBase)) {
74 return false;
75 }
76 RepositoryBase that = (RepositoryBase) o;
77 return Objects.equals( this.id, that.id );
78 }
79
80 @Override
81 public int hashCode() {
82 return Objects.hash(id);
83 }
84
85 /**
86 * A unique identifier for a repository. This is used to match the repository
87 * to configuration in the {@code settings.xml} file, for example. Furthermore, the identifier is
88 * used during POM inheritance and profile injection to detect repositories that should be merged.
89 *
90 * @return a {@code String}
91 */
92 public String getId() {
93 return this.id;
94 }
95
96 /**
97 * Human readable name of the repository.
98 *
99 * @return a {@code String}
100 */
101 public String getName() {
102 return this.name;
103 }
104
105 /**
106 * The url of the repository, in the form {@code protocol://hostname/path}.
107 *
108 * @return a {@code String}
109 */
110 public String getUrl() {
111 return this.url;
112 }
113
114 /**
115 * The type of layout this repository uses for locating and storing artifacts -
116 * can be {@code legacy} or {@code default}.
117 *
118 * @return a {@code String}
119 */
120 public String getLayout() {
121 return this.layout;
122 }
123
124 /**
125 * Gets the location of the specified field in the input source.
126 */
127 public InputLocation getLocation(Object key) {
128 return locations != null ? locations.get(key) : null;
129 }
130
131 /**
132 * Creates a new builder with this object as the basis.
133 *
134 * @return a {@code Builder}
135 */
136 @Nonnull
137 public Builder with() {
138 return newBuilder(this);
139 }
140 /**
141 * Creates a new {@code RepositoryBase} instance using the specified id.
142 *
143 * @param id the new {@code String} to use
144 * @return a {@code RepositoryBase} with the specified id
145 */
146 @Nonnull
147 public RepositoryBase withId(String id) {
148 return newBuilder(this, true).id(id).build();
149 }
150 /**
151 * Creates a new {@code RepositoryBase} instance using the specified name.
152 *
153 * @param name the new {@code String} to use
154 * @return a {@code RepositoryBase} with the specified name
155 */
156 @Nonnull
157 public RepositoryBase withName(String name) {
158 return newBuilder(this, true).name(name).build();
159 }
160 /**
161 * Creates a new {@code RepositoryBase} instance using the specified url.
162 *
163 * @param url the new {@code String} to use
164 * @return a {@code RepositoryBase} with the specified url
165 */
166 @Nonnull
167 public RepositoryBase withUrl(String url) {
168 return newBuilder(this, true).url(url).build();
169 }
170 /**
171 * Creates a new {@code RepositoryBase} instance using the specified layout.
172 *
173 * @param layout the new {@code String} to use
174 * @return a {@code RepositoryBase} with the specified layout
175 */
176 @Nonnull
177 public RepositoryBase withLayout(String layout) {
178 return newBuilder(this, true).layout(layout).build();
179 }
180
181 /**
182 * Creates a new {@code RepositoryBase} instance.
183 * Equivalent to {@code newInstance(true)}.
184 * @see #newInstance(boolean)
185 *
186 * @return a new {@code RepositoryBase}
187 */
188 @Nonnull
189 public static RepositoryBase newInstance() {
190 return newInstance(true);
191 }
192
193 /**
194 * Creates a new {@code RepositoryBase} instance using default values or not.
195 * Equivalent to {@code newBuilder(withDefaults).build()}.
196 *
197 * @param withDefaults the boolean indicating whether default values should be used
198 * @return a new {@code RepositoryBase}
199 */
200 @Nonnull
201 public static RepositoryBase newInstance(boolean withDefaults) {
202 return newBuilder(withDefaults).build();
203 }
204
205 /**
206 * Creates a new {@code RepositoryBase} builder instance.
207 * Equivalent to {@code newBuilder(true)}.
208 * @see #newBuilder(boolean)
209 *
210 * @return a new {@code Builder}
211 */
212 @Nonnull
213 public static Builder newBuilder() {
214 return newBuilder(true);
215 }
216
217 /**
218 * Creates a new {@code RepositoryBase} builder instance using default values or not.
219 *
220 * @param withDefaults the boolean indicating whether default values should be used
221 * @return a new {@code Builder}
222 */
223 @Nonnull
224 public static Builder newBuilder(boolean withDefaults) {
225 return new Builder(withDefaults);
226 }
227
228 /**
229 * Creates a new {@code RepositoryBase} builder instance using the specified object as a basis.
230 * Equivalent to {@code newBuilder(from, false)}.
231 *
232 * @param from the {@code RepositoryBase} instance to use as a basis
233 * @return a new {@code Builder}
234 */
235 @Nonnull
236 public static Builder newBuilder(RepositoryBase from) {
237 return newBuilder(from, false);
238 }
239
240 /**
241 * Creates a new {@code RepositoryBase} builder instance using the specified object as a basis.
242 *
243 * @param from the {@code RepositoryBase} instance to use as a basis
244 * @param forceCopy the boolean indicating if a copy should be forced
245 * @return a new {@code Builder}
246 */
247 @Nonnull
248 public static Builder newBuilder(RepositoryBase from, boolean forceCopy) {
249 return new Builder(from, forceCopy);
250 }
251
252 /**
253 * Builder class used to create RepositoryBase instances.
254 * @see #with()
255 * @see #newBuilder()
256 */
257 @NotThreadSafe
258 public static class Builder
259 {
260 RepositoryBase base;
261 String id;
262 String name;
263 String url;
264 String layout;
265 Map<Object, InputLocation> locations;
266
267 Builder(boolean withDefaults) {
268 if (withDefaults) {
269 this.layout = "default";
270 }
271 }
272
273 Builder(RepositoryBase base, boolean forceCopy) {
274 if (forceCopy) {
275 this.id = base.id;
276 this.name = base.name;
277 this.url = base.url;
278 this.layout = base.layout;
279 this.locations = base.locations;
280 } else {
281 this.base = base;
282 }
283 }
284
285 @Nonnull
286 public Builder id(String id) {
287 this.id = id;
288 return this;
289 }
290
291 @Nonnull
292 public Builder name(String name) {
293 this.name = name;
294 return this;
295 }
296
297 @Nonnull
298 public Builder url(String url) {
299 this.url = url;
300 return this;
301 }
302
303 @Nonnull
304 public Builder layout(String layout) {
305 this.layout = layout;
306 return this;
307 }
308
309
310 @Nonnull
311 public Builder location(Object key, InputLocation location) {
312 if (location != null) {
313 if (!(this.locations instanceof HashMap)) {
314 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
315 }
316 this.locations.put(key, location);
317 }
318 return this;
319 }
320
321 @Nonnull
322 public RepositoryBase build() {
323 if (base != null
324 && (id == null || id == base.id)
325 && (name == null || name == base.name)
326 && (url == null || url == base.url)
327 && (layout == null || layout == base.layout)
328 ) {
329 return base;
330 }
331 Map<Object, InputLocation> locations = null;
332 InputLocation location = null;
333 InputLocation idLocation = null;
334 InputLocation nameLocation = null;
335 InputLocation urlLocation = null;
336 InputLocation layoutLocation = null;
337 if (this.locations != null) {
338 locations = this.locations;
339 }
340 return new RepositoryBase(
341 id != null ? id : (base != null ? base.id : null),
342 name != null ? name : (base != null ? base.name : null),
343 url != null ? url : (base != null ? base.url : null),
344 layout != null ? layout : (base != null ? base.layout : null),
345 locations != null ? locations : (base != null ? base.locations : null)
346 );
347 }
348 }
349
350 }