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.model;
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   * Describes where an artifact has moved to. If any of the values are omitted, it is
20   * assumed to be the same as it was before.
21   */
22  @Experimental
23  @Generated @ThreadSafe @Immutable
24  public class Relocation
25      implements Serializable, InputLocationTracker
26  {
27      /**
28       * The group ID the artifact has moved to.
29       */
30      final String groupId;
31      /**
32       * The new artifact ID of the artifact.
33       */
34      final String artifactId;
35      /**
36       * The new version of the artifact.
37       */
38      final String version;
39      /**
40       * An additional message to show the user about the move, such as the reason.
41       */
42      final String message;
43      /** Locations */
44      final Map<Object, InputLocation> locations;
45  
46      /**
47        * Constructor for this class, package protected.
48        * @see Builder#build()
49        */
50      Relocation(
51          String groupId,
52          String artifactId,
53          String version,
54          String message,
55          Map<Object, InputLocation> locations
56      ) {
57          this.groupId = groupId;
58          this.artifactId = artifactId;
59          this.version = version;
60          this.message = message;
61          this.locations = ImmutableCollections.copy(locations);
62      }
63  
64      /**
65       * The group ID the artifact has moved to.
66       *
67       * @return a {@code String}
68       */
69      public String getGroupId() {
70          return this.groupId;
71      }
72  
73      /**
74       * The new artifact ID of the artifact.
75       *
76       * @return a {@code String}
77       */
78      public String getArtifactId() {
79          return this.artifactId;
80      }
81  
82      /**
83       * The new version of the artifact.
84       *
85       * @return a {@code String}
86       */
87      public String getVersion() {
88          return this.version;
89      }
90  
91      /**
92       * An additional message to show the user about the move, such as the reason.
93       *
94       * @return a {@code String}
95       */
96      public String getMessage() {
97          return this.message;
98      }
99  
100     /**
101      * Gets the location of the specified field in the input source.
102      */
103     public InputLocation getLocation(Object key) {
104         return locations != null ? locations.get(key) : null;
105     }
106 
107     /**
108      * Creates a new builder with this object as the basis.
109      *
110      * @return a {@code Builder}
111      */
112     @Nonnull
113     public Builder with() {
114         return newBuilder(this);
115     }
116     /**
117      * Creates a new {@code Relocation} instance using the specified groupId.
118      *
119      * @param groupId the new {@code String} to use
120      * @return a {@code Relocation} with the specified groupId
121      */
122     @Nonnull
123     public Relocation withGroupId(String groupId) {
124         return newBuilder(this, true).groupId(groupId).build();
125     }
126     /**
127      * Creates a new {@code Relocation} instance using the specified artifactId.
128      *
129      * @param artifactId the new {@code String} to use
130      * @return a {@code Relocation} with the specified artifactId
131      */
132     @Nonnull
133     public Relocation withArtifactId(String artifactId) {
134         return newBuilder(this, true).artifactId(artifactId).build();
135     }
136     /**
137      * Creates a new {@code Relocation} instance using the specified version.
138      *
139      * @param version the new {@code String} to use
140      * @return a {@code Relocation} with the specified version
141      */
142     @Nonnull
143     public Relocation withVersion(String version) {
144         return newBuilder(this, true).version(version).build();
145     }
146     /**
147      * Creates a new {@code Relocation} instance using the specified message.
148      *
149      * @param message the new {@code String} to use
150      * @return a {@code Relocation} with the specified message
151      */
152     @Nonnull
153     public Relocation withMessage(String message) {
154         return newBuilder(this, true).message(message).build();
155     }
156 
157     /**
158      * Creates a new {@code Relocation} instance.
159      * Equivalent to {@code newInstance(true)}.
160      * @see #newInstance(boolean)
161      *
162      * @return a new {@code Relocation}
163      */
164     @Nonnull
165     public static Relocation newInstance() {
166         return newInstance(true);
167     }
168 
169     /**
170      * Creates a new {@code Relocation} instance using default values or not.
171      * Equivalent to {@code newBuilder(withDefaults).build()}.
172      *
173      * @param withDefaults the boolean indicating whether default values should be used
174      * @return a new {@code Relocation}
175      */
176     @Nonnull
177     public static Relocation newInstance(boolean withDefaults) {
178         return newBuilder(withDefaults).build();
179     }
180 
181     /**
182      * Creates a new {@code Relocation} builder instance.
183      * Equivalent to {@code newBuilder(true)}.
184      * @see #newBuilder(boolean)
185      *
186      * @return a new {@code Builder}
187      */
188     @Nonnull
189     public static Builder newBuilder() {
190         return newBuilder(true);
191     }
192 
193     /**
194      * Creates a new {@code Relocation} builder instance using default values or not.
195      *
196      * @param withDefaults the boolean indicating whether default values should be used
197      * @return a new {@code Builder}
198      */
199     @Nonnull
200     public static Builder newBuilder(boolean withDefaults) {
201         return new Builder(withDefaults);
202     }
203 
204     /**
205      * Creates a new {@code Relocation} builder instance using the specified object as a basis.
206      * Equivalent to {@code newBuilder(from, false)}.
207      *
208      * @param from the {@code Relocation} instance to use as a basis
209      * @return a new {@code Builder}
210      */
211     @Nonnull
212     public static Builder newBuilder(Relocation from) {
213         return newBuilder(from, false);
214     }
215 
216     /**
217      * Creates a new {@code Relocation} builder instance using the specified object as a basis.
218      *
219      * @param from the {@code Relocation} instance to use as a basis
220      * @param forceCopy the boolean indicating if a copy should be forced
221      * @return a new {@code Builder}
222      */
223     @Nonnull
224     public static Builder newBuilder(Relocation from, boolean forceCopy) {
225         return new Builder(from, forceCopy);
226     }
227 
228     /**
229      * Builder class used to create Relocation instances.
230      * @see #with()
231      * @see #newBuilder()
232      */
233     @NotThreadSafe
234     public static class Builder
235     {
236         Relocation base;
237         String groupId;
238         String artifactId;
239         String version;
240         String message;
241         Map<Object, InputLocation> locations;
242 
243         Builder(boolean withDefaults) {
244             if (withDefaults) {
245             }
246         }
247 
248         Builder(Relocation base, boolean forceCopy) {
249             if (forceCopy) {
250                 this.groupId = base.groupId;
251                 this.artifactId = base.artifactId;
252                 this.version = base.version;
253                 this.message = base.message;
254                 this.locations = base.locations;
255             } else {
256                 this.base = base;
257             }
258         }
259 
260         @Nonnull
261         public Builder groupId(String groupId) {
262             this.groupId = groupId;
263             return this;
264         }
265 
266         @Nonnull
267         public Builder artifactId(String artifactId) {
268             this.artifactId = artifactId;
269             return this;
270         }
271 
272         @Nonnull
273         public Builder version(String version) {
274             this.version = version;
275             return this;
276         }
277 
278         @Nonnull
279         public Builder message(String message) {
280             this.message = message;
281             return this;
282         }
283 
284 
285         @Nonnull
286         public Builder location(Object key, InputLocation location) {
287             if (location != null) {
288                 if (!(this.locations instanceof HashMap)) {
289                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
290                 }
291                 this.locations.put(key, location);
292             }
293             return this;
294         }
295 
296         @Nonnull
297         public Relocation build() {
298             if (base != null
299                     && (groupId == null || groupId == base.groupId)
300                     && (artifactId == null || artifactId == base.artifactId)
301                     && (version == null || version == base.version)
302                     && (message == null || message == base.message)
303             ) {
304                 return base;
305             }
306             Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
307             Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
308             Map<Object, InputLocation> locations = new HashMap<>();
309             locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
310             locations.put("groupId", newlocs.containsKey("groupId") ? newlocs.get("groupId") : oldlocs.get("groupId"));
311             locations.put("artifactId", newlocs.containsKey("artifactId") ? newlocs.get("artifactId") : oldlocs.get("artifactId"));
312             locations.put("version", newlocs.containsKey("version") ? newlocs.get("version") : oldlocs.get("version"));
313             locations.put("message", newlocs.containsKey("message") ? newlocs.get("message") : oldlocs.get("message"));
314             return new Relocation(
315                 groupId != null ? groupId : (base != null ? base.groupId : null),
316                 artifactId != null ? artifactId : (base != null ? base.artifactId : null),
317                 version != null ? version : (base != null ? base.version : null),
318                 message != null ? message : (base != null ? base.message : null),
319                 locations
320             );
321         }
322     }
323 
324 }