View Javadoc
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 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   * Repository contains the information needed
20   * for establishing connections with remote repository
21   */
22  @Experimental
23  @Generated @ThreadSafe @Immutable
24  public class RepositoryBase
25      extends IdentifiableBase
26      implements Serializable, InputLocationTracker
27  {
28      /**
29       * Human readable name of the repository.
30       */
31      final String name;
32      /**
33       * The url of the repository.
34       */
35      final String url;
36      /**
37       * The type of layout this repository uses for locating and
38       * storing artifacts - can be "legacy" or "default".
39       */
40      final String layout;
41  
42      /**
43        * Constructor for this class, package protected.
44        * @see Builder#build()
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       * Human readable name of the repository.
64       *
65       * @return a {@code String}
66       */
67      public String getName() {
68          return this.name;
69      }
70  
71      /**
72       * The url of the repository.
73       *
74       * @return a {@code String}
75       */
76      public String getUrl() {
77          return this.url;
78      }
79  
80      /**
81       * The type of layout this repository uses for locating and
82       * storing artifacts - can be "legacy" or "default".
83       *
84       * @return a {@code String}
85       */
86      public String getLayout() {
87          return this.layout;
88      }
89  
90      /**
91       * Creates a new builder with this object as the basis.
92       *
93       * @return a {@code Builder}
94       */
95      @Nonnull
96      public Builder with() {
97          return newBuilder(this);
98      }
99      /**
100      * Creates a new {@code RepositoryBase} instance using the specified id.
101      *
102      * @param id the new {@code String} to use
103      * @return a {@code RepositoryBase} with the specified id
104      */
105     @Nonnull
106     public RepositoryBase withId(String id) {
107         return newBuilder(this, true).id(id).build();
108     }
109     /**
110      * Creates a new {@code RepositoryBase} instance using the specified name.
111      *
112      * @param name the new {@code String} to use
113      * @return a {@code RepositoryBase} with the specified name
114      */
115     @Nonnull
116     public RepositoryBase withName(String name) {
117         return newBuilder(this, true).name(name).build();
118     }
119     /**
120      * Creates a new {@code RepositoryBase} instance using the specified url.
121      *
122      * @param url the new {@code String} to use
123      * @return a {@code RepositoryBase} with the specified url
124      */
125     @Nonnull
126     public RepositoryBase withUrl(String url) {
127         return newBuilder(this, true).url(url).build();
128     }
129     /**
130      * Creates a new {@code RepositoryBase} instance using the specified layout.
131      *
132      * @param layout the new {@code String} to use
133      * @return a {@code RepositoryBase} with the specified layout
134      */
135     @Nonnull
136     public RepositoryBase withLayout(String layout) {
137         return newBuilder(this, true).layout(layout).build();
138     }
139 
140     /**
141      * Creates a new {@code RepositoryBase} instance.
142      * Equivalent to {@code newInstance(true)}.
143      * @see #newInstance(boolean)
144      *
145      * @return a new {@code RepositoryBase}
146      */
147     @Nonnull
148     public static RepositoryBase newInstance() {
149         return newInstance(true);
150     }
151 
152     /**
153      * Creates a new {@code RepositoryBase} instance using default values or not.
154      * Equivalent to {@code newBuilder(withDefaults).build()}.
155      *
156      * @param withDefaults the boolean indicating whether default values should be used
157      * @return a new {@code RepositoryBase}
158      */
159     @Nonnull
160     public static RepositoryBase newInstance(boolean withDefaults) {
161         return newBuilder(withDefaults).build();
162     }
163 
164     /**
165      * Creates a new {@code RepositoryBase} builder instance.
166      * Equivalent to {@code newBuilder(true)}.
167      * @see #newBuilder(boolean)
168      *
169      * @return a new {@code Builder}
170      */
171     @Nonnull
172     public static Builder newBuilder() {
173         return newBuilder(true);
174     }
175 
176     /**
177      * Creates a new {@code RepositoryBase} builder instance using default values or not.
178      *
179      * @param withDefaults the boolean indicating whether default values should be used
180      * @return a new {@code Builder}
181      */
182     @Nonnull
183     public static Builder newBuilder(boolean withDefaults) {
184         return new Builder(withDefaults);
185     }
186 
187     /**
188      * Creates a new {@code RepositoryBase} builder instance using the specified object as a basis.
189      * Equivalent to {@code newBuilder(from, false)}.
190      *
191      * @param from the {@code RepositoryBase} instance to use as a basis
192      * @return a new {@code Builder}
193      */
194     @Nonnull
195     public static Builder newBuilder(RepositoryBase from) {
196         return newBuilder(from, false);
197     }
198 
199     /**
200      * Creates a new {@code RepositoryBase} builder instance using the specified object as a basis.
201      *
202      * @param from the {@code RepositoryBase} instance to use as a basis
203      * @param forceCopy the boolean indicating if a copy should be forced
204      * @return a new {@code Builder}
205      */
206     @Nonnull
207     public static Builder newBuilder(RepositoryBase from, boolean forceCopy) {
208         return new Builder(from, forceCopy);
209     }
210 
211     /**
212      * Builder class used to create RepositoryBase instances.
213      * @see #with()
214      * @see #newBuilder()
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 }