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