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