View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.graph;
20  
21  /**
22   * An exclusion of one or more transitive dependencies.
23   *
24   * @see Dependency#getExclusions()
25   */
26  public final class Exclusion {
27  
28      private final String groupId;
29  
30      private final String artifactId;
31  
32      private final String classifier;
33  
34      private final String extension;
35  
36      /**
37       * Creates an exclusion for artifacts with the specified coordinates.
38       *
39       * @param groupId The group identifier, may be {@code null}.
40       * @param artifactId The artifact identifier, may be {@code null}.
41       * @param classifier The classifier, may be {@code null}.
42       * @param extension The file extension, may be {@code null}.
43       */
44      public Exclusion(String groupId, String artifactId, String classifier, String extension) {
45          this.groupId = (groupId != null) ? groupId : "";
46          this.artifactId = (artifactId != null) ? artifactId : "";
47          this.classifier = (classifier != null) ? classifier : "";
48          this.extension = (extension != null) ? extension : "";
49      }
50  
51      /**
52       * Gets the group identifier for artifacts to exclude.
53       *
54       * @return The group identifier, never {@code null}.
55       */
56      public String getGroupId() {
57          return groupId;
58      }
59  
60      /**
61       * Gets the artifact identifier for artifacts to exclude.
62       *
63       * @return The artifact identifier, never {@code null}.
64       */
65      public String getArtifactId() {
66          return artifactId;
67      }
68  
69      /**
70       * Gets the classifier for artifacts to exclude.
71       *
72       * @return The classifier, never {@code null}.
73       */
74      public String getClassifier() {
75          return classifier;
76      }
77  
78      /**
79       * Gets the file extension for artifacts to exclude.
80       *
81       * @return The file extension of artifacts to exclude, never {@code null}.
82       */
83      public String getExtension() {
84          return extension;
85      }
86  
87      @Override
88      public String toString() {
89          return getGroupId()
90                  + ':'
91                  + getArtifactId()
92                  + ':'
93                  + getExtension()
94                  + (!getClassifier().isEmpty() ? ':' + getClassifier() : "");
95      }
96  
97      @Override
98      public boolean equals(Object obj) {
99          if (obj == this) {
100             return true;
101         } else if (obj == null || !getClass().equals(obj.getClass())) {
102             return false;
103         }
104 
105         Exclusion that = (Exclusion) obj;
106 
107         return artifactId.equals(that.artifactId)
108                 && groupId.equals(that.groupId)
109                 && extension.equals(that.extension)
110                 && classifier.equals(that.classifier);
111     }
112 
113     @Override
114     public int hashCode() {
115         int hash = 17;
116         hash = hash * 31 + artifactId.hashCode();
117         hash = hash * 31 + groupId.hashCode();
118         hash = hash * 31 + classifier.hashCode();
119         hash = hash * 31 + extension.hashCode();
120         return hash;
121     }
122 }