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   * The {@code <exclusion>} element contains informations required to exclude
20   * an artifact to the project.
21   * <p>
22   * The {@code groupId} and {@code artifactId} fields are interpreted as glob patterns,
23   * see {@link java.nio.file.FileSystem#getPathMatcher}.
24   */
25  @Experimental
26  @Generated @ThreadSafe @Immutable
27  public class Exclusion
28      implements Serializable, InputLocationTracker
29  {
30      /**
31       * The group ID of the project to exclude.
32       */
33      final String groupId;
34      /**
35       * The artifact ID of the project to exclude.
36       */
37      final String artifactId;
38      /** Locations */
39      final Map<Object, InputLocation> locations;
40  
41      /**
42        * Constructor for this class, package protected.
43        * @see Builder#build()
44        */
45      Exclusion(
46          String groupId,
47          String artifactId,
48          Map<Object, InputLocation> locations
49      ) {
50          this.groupId = groupId;
51          this.artifactId = artifactId;
52          this.locations = ImmutableCollections.copy(locations);
53      }
54  
55      /**
56       * The group ID of the project to exclude.
57       *
58       * @return a {@code String}
59       */
60      public String getGroupId() {
61          return this.groupId;
62      }
63  
64      /**
65       * The artifact ID of the project to exclude.
66       *
67       * @return a {@code String}
68       */
69      public String getArtifactId() {
70          return this.artifactId;
71      }
72  
73      /**
74       * Gets the location of the specified field in the input source.
75       */
76      public InputLocation getLocation(Object key) {
77          return locations != null ? locations.get(key) : null;
78      }
79  
80      /**
81       * Creates a new builder with this object as the basis.
82       *
83       * @return a {@code Builder}
84       */
85      @Nonnull
86      public Builder with() {
87          return newBuilder(this);
88      }
89      /**
90       * Creates a new {@code Exclusion} instance using the specified groupId.
91       *
92       * @param groupId the new {@code String} to use
93       * @return a {@code Exclusion} with the specified groupId
94       */
95      @Nonnull
96      public Exclusion withGroupId(String groupId) {
97          return newBuilder(this, true).groupId(groupId).build();
98      }
99      /**
100      * Creates a new {@code Exclusion} instance using the specified artifactId.
101      *
102      * @param artifactId the new {@code String} to use
103      * @return a {@code Exclusion} with the specified artifactId
104      */
105     @Nonnull
106     public Exclusion withArtifactId(String artifactId) {
107         return newBuilder(this, true).artifactId(artifactId).build();
108     }
109 
110     /**
111      * Creates a new {@code Exclusion} instance.
112      * Equivalent to {@code newInstance(true)}.
113      * @see #newInstance(boolean)
114      *
115      * @return a new {@code Exclusion}
116      */
117     @Nonnull
118     public static Exclusion newInstance() {
119         return newInstance(true);
120     }
121 
122     /**
123      * Creates a new {@code Exclusion} instance using default values or not.
124      * Equivalent to {@code newBuilder(withDefaults).build()}.
125      *
126      * @param withDefaults the boolean indicating whether default values should be used
127      * @return a new {@code Exclusion}
128      */
129     @Nonnull
130     public static Exclusion newInstance(boolean withDefaults) {
131         return newBuilder(withDefaults).build();
132     }
133 
134     /**
135      * Creates a new {@code Exclusion} builder instance.
136      * Equivalent to {@code newBuilder(true)}.
137      * @see #newBuilder(boolean)
138      *
139      * @return a new {@code Builder}
140      */
141     @Nonnull
142     public static Builder newBuilder() {
143         return newBuilder(true);
144     }
145 
146     /**
147      * Creates a new {@code Exclusion} builder instance using default values or not.
148      *
149      * @param withDefaults the boolean indicating whether default values should be used
150      * @return a new {@code Builder}
151      */
152     @Nonnull
153     public static Builder newBuilder(boolean withDefaults) {
154         return new Builder(withDefaults);
155     }
156 
157     /**
158      * Creates a new {@code Exclusion} builder instance using the specified object as a basis.
159      * Equivalent to {@code newBuilder(from, false)}.
160      *
161      * @param from the {@code Exclusion} instance to use as a basis
162      * @return a new {@code Builder}
163      */
164     @Nonnull
165     public static Builder newBuilder(Exclusion from) {
166         return newBuilder(from, false);
167     }
168 
169     /**
170      * Creates a new {@code Exclusion} builder instance using the specified object as a basis.
171      *
172      * @param from the {@code Exclusion} instance to use as a basis
173      * @param forceCopy the boolean indicating if a copy should be forced
174      * @return a new {@code Builder}
175      */
176     @Nonnull
177     public static Builder newBuilder(Exclusion from, boolean forceCopy) {
178         return new Builder(from, forceCopy);
179     }
180 
181     /**
182      * Builder class used to create Exclusion instances.
183      * @see #with()
184      * @see #newBuilder()
185      */
186     @NotThreadSafe
187     public static class Builder
188     {
189         Exclusion base;
190         String groupId;
191         String artifactId;
192         Map<Object, InputLocation> locations;
193 
194         Builder(boolean withDefaults) {
195             if (withDefaults) {
196             }
197         }
198 
199         Builder(Exclusion base, boolean forceCopy) {
200             if (forceCopy) {
201                 this.groupId = base.groupId;
202                 this.artifactId = base.artifactId;
203                 this.locations = base.locations;
204             } else {
205                 this.base = base;
206             }
207         }
208 
209         @Nonnull
210         public Builder groupId(String groupId) {
211             this.groupId = groupId;
212             return this;
213         }
214 
215         @Nonnull
216         public Builder artifactId(String artifactId) {
217             this.artifactId = artifactId;
218             return this;
219         }
220 
221 
222         @Nonnull
223         public Builder location(Object key, InputLocation location) {
224             if (location != null) {
225                 if (!(this.locations instanceof HashMap)) {
226                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
227                 }
228                 this.locations.put(key, location);
229             }
230             return this;
231         }
232 
233         @Nonnull
234         public Exclusion build() {
235             if (base != null
236                     && (groupId == null || groupId == base.groupId)
237                     && (artifactId == null || artifactId == base.artifactId)
238             ) {
239                 return base;
240             }
241             Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
242             Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
243             Map<Object, InputLocation> locations = new HashMap<>();
244             locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
245             locations.put("groupId", newlocs.containsKey("groupId") ? newlocs.get("groupId") : oldlocs.get("groupId"));
246             locations.put("artifactId", newlocs.containsKey("artifactId") ? newlocs.get("artifactId") : oldlocs.get("artifactId"));
247             return new Exclusion(
248                 groupId != null ? groupId : (base != null ? base.groupId : null),
249                 artifactId != null ? artifactId : (base != null ? base.artifactId : null),
250                 locations
251             );
252         }
253     }
254 
255 }