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