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