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.settings;
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 java.util.Optional;
13 import java.util.Set;
14 import java.util.stream.Collectors;
15 import java.util.stream.Stream;
16 import org.apache.maven.api.annotations.Experimental;
17 import org.apache.maven.api.annotations.Generated;
18 import org.apache.maven.api.annotations.Immutable;
19 import org.apache.maven.api.annotations.Nonnull;
20 import org.apache.maven.api.annotations.NotThreadSafe;
21 import org.apache.maven.api.annotations.ThreadSafe;
22
23 /**
24 * Repository contains the information needed
25 * for establishing connections with remote repository
26 */
27 @Experimental
28 @Generated @ThreadSafe @Immutable
29 public class RepositoryBase
30 extends IdentifiableBase
31 implements Serializable, InputLocationTracker
32 {
33 /**
34 * Human readable name of the repository.
35 */
36 final String name;
37 /**
38 * The url of the repository.
39 */
40 final String url;
41 /**
42 * The type of layout this repository uses for locating and
43 * storing artifacts - can be "legacy" or "default".
44 */
45 final String layout;
46
47 /**
48 * Constructor for this class, to be called from its subclasses and {@link Builder}.
49 * @see Builder#build()
50 */
51 protected RepositoryBase(Builder builder) {
52 super(builder);
53 this.name = builder.name != null ? builder.name : (builder.base != null ? builder.base.name : null);
54 this.url = builder.url != null ? builder.url : (builder.base != null ? builder.base.url : null);
55 this.layout = builder.layout != null ? builder.layout : (builder.base != null ? builder.base.layout : null);
56 }
57
58 /**
59 * Human readable name of the repository.
60 *
61 * @return a {@code String}
62 */
63 public String getName() {
64 return this.name;
65 }
66
67 /**
68 * The url of the repository.
69 *
70 * @return a {@code String}
71 */
72 public String getUrl() {
73 return this.url;
74 }
75
76 /**
77 * The type of layout this repository uses for locating and
78 * storing artifacts - can be "legacy" or "default".
79 *
80 * @return a {@code String}
81 */
82 public String getLayout() {
83 return this.layout;
84 }
85
86 /**
87 * Creates a new builder with this object as the basis.
88 *
89 * @return a {@code Builder}
90 */
91 @Nonnull
92 public Builder with() {
93 return newBuilder(this);
94 }
95 /**
96 * Creates a new {@code RepositoryBase} instance using the specified id.
97 *
98 * @param id the new {@code String} to use
99 * @return a {@code RepositoryBase} with the specified id
100 */
101 @Nonnull
102 public RepositoryBase withId(String id) {
103 return newBuilder(this, true).id(id).build();
104 }
105 /**
106 * Creates a new {@code RepositoryBase} instance using the specified name.
107 *
108 * @param name the new {@code String} to use
109 * @return a {@code RepositoryBase} with the specified name
110 */
111 @Nonnull
112 public RepositoryBase withName(String name) {
113 return newBuilder(this, true).name(name).build();
114 }
115 /**
116 * Creates a new {@code RepositoryBase} instance using the specified url.
117 *
118 * @param url the new {@code String} to use
119 * @return a {@code RepositoryBase} with the specified url
120 */
121 @Nonnull
122 public RepositoryBase withUrl(String url) {
123 return newBuilder(this, true).url(url).build();
124 }
125 /**
126 * Creates a new {@code RepositoryBase} instance using the specified layout.
127 *
128 * @param layout the new {@code String} to use
129 * @return a {@code RepositoryBase} with the specified layout
130 */
131 @Nonnull
132 public RepositoryBase withLayout(String layout) {
133 return newBuilder(this, true).layout(layout).build();
134 }
135
136 /**
137 * Creates a new {@code RepositoryBase} instance.
138 * Equivalent to {@code newInstance(true)}.
139 * @see #newInstance(boolean)
140 *
141 * @return a new {@code RepositoryBase}
142 */
143 @Nonnull
144 public static RepositoryBase newInstance() {
145 return newInstance(true);
146 }
147
148 /**
149 * Creates a new {@code RepositoryBase} instance using default values or not.
150 * Equivalent to {@code newBuilder(withDefaults).build()}.
151 *
152 * @param withDefaults the boolean indicating whether default values should be used
153 * @return a new {@code RepositoryBase}
154 */
155 @Nonnull
156 public static RepositoryBase newInstance(boolean withDefaults) {
157 return newBuilder(withDefaults).build();
158 }
159
160 /**
161 * Creates a new {@code RepositoryBase} builder instance.
162 * Equivalent to {@code newBuilder(true)}.
163 * @see #newBuilder(boolean)
164 *
165 * @return a new {@code Builder}
166 */
167 @Nonnull
168 public static Builder newBuilder() {
169 return newBuilder(true);
170 }
171
172 /**
173 * Creates a new {@code RepositoryBase} builder instance using default values or not.
174 *
175 * @param withDefaults the boolean indicating whether default values should be used
176 * @return a new {@code Builder}
177 */
178 @Nonnull
179 public static Builder newBuilder(boolean withDefaults) {
180 return new Builder(withDefaults);
181 }
182
183 /**
184 * Creates a new {@code RepositoryBase} builder instance using the specified object as a basis.
185 * Equivalent to {@code newBuilder(from, false)}.
186 *
187 * @param from the {@code RepositoryBase} instance to use as a basis
188 * @return a new {@code Builder}
189 */
190 @Nonnull
191 public static Builder newBuilder(RepositoryBase from) {
192 return newBuilder(from, false);
193 }
194
195 /**
196 * Creates a new {@code RepositoryBase} builder instance using the specified object as a basis.
197 *
198 * @param from the {@code RepositoryBase} instance to use as a basis
199 * @param forceCopy the boolean indicating if a copy should be forced
200 * @return a new {@code Builder}
201 */
202 @Nonnull
203 public static Builder newBuilder(RepositoryBase from, boolean forceCopy) {
204 return new Builder(from, forceCopy);
205 }
206
207 /**
208 * Builder class used to create RepositoryBase instances.
209 * @see #with()
210 * @see #newBuilder()
211 */
212 @NotThreadSafe
213 public static class Builder
214 extends IdentifiableBase.Builder
215 {
216 RepositoryBase base;
217 String name;
218 String url;
219 String layout;
220
221 protected Builder(boolean withDefaults) {
222 super(withDefaults);
223 if (withDefaults) {
224 this.layout = "default";
225 }
226 }
227
228 protected Builder(RepositoryBase base, boolean forceCopy) {
229 super(base, forceCopy);
230 if (forceCopy) {
231 this.name = base.name;
232 this.url = base.url;
233 this.layout = base.layout;
234 this.locations = base.locations;
235 this.importedFrom = base.importedFrom;
236 } else {
237 this.base = base;
238 }
239 }
240
241 @Nonnull
242 public Builder id(String id) {
243 this.id = id;
244 return this;
245 }
246
247 @Nonnull
248 public Builder name(String name) {
249 this.name = name;
250 return this;
251 }
252
253 @Nonnull
254 public Builder url(String url) {
255 this.url = url;
256 return this;
257 }
258
259 @Nonnull
260 public Builder layout(String layout) {
261 this.layout = layout;
262 return this;
263 }
264
265
266 @Nonnull
267 public Builder location(Object key, InputLocation location) {
268 if (location != null) {
269 if (!(this.locations instanceof HashMap)) {
270 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
271 }
272 this.locations.put(key, location);
273 }
274 return this;
275 }
276
277 @Nonnull
278 public Builder importedFrom(InputLocation importedFrom) {
279 this.importedFrom = importedFrom;
280 return this;
281 }
282
283 @Nonnull
284 public RepositoryBase build() {
285 // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
286 if (base != null
287 && (id == null || id == base.id)
288 && (name == null || name == base.name)
289 && (url == null || url == base.url)
290 && (layout == null || layout == base.layout)
291 ) {
292 return base;
293 }
294 return new RepositoryBase(this);
295 }
296
297 }
298
299 }