001package org.eclipse.aether.graph; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022/** 023 * An exclusion of one or more transitive dependencies. <em>Note:</em> Instances of this class are immutable and the 024 * exposed mutators return new objects rather than changing the current instance. 025 * 026 * @see Dependency#getExclusions() 027 */ 028public final class Exclusion 029{ 030 031 private final String groupId; 032 033 private final String artifactId; 034 035 private final String classifier; 036 037 private final String extension; 038 039 /** 040 * Creates an exclusion for artifacts with the specified coordinates. 041 * 042 * @param groupId The group identifier, may be {@code null}. 043 * @param artifactId The artifact identifier, may be {@code null}. 044 * @param classifier The classifier, may be {@code null}. 045 * @param extension The file extension, may be {@code null}. 046 */ 047 public Exclusion( String groupId, String artifactId, String classifier, String extension ) 048 { 049 this.groupId = ( groupId != null ) ? groupId : ""; 050 this.artifactId = ( artifactId != null ) ? artifactId : ""; 051 this.classifier = ( classifier != null ) ? classifier : ""; 052 this.extension = ( extension != null ) ? extension : ""; 053 } 054 055 /** 056 * Gets the group identifier for artifacts to exclude. 057 * 058 * @return The group identifier, never {@code null}. 059 */ 060 public String getGroupId() 061 { 062 return groupId; 063 } 064 065 /** 066 * Gets the artifact identifier for artifacts to exclude. 067 * 068 * @return The artifact identifier, never {@code null}. 069 */ 070 public String getArtifactId() 071 { 072 return artifactId; 073 } 074 075 /** 076 * Gets the classifier for artifacts to exclude. 077 * 078 * @return The classifier, never {@code null}. 079 */ 080 public String getClassifier() 081 { 082 return classifier; 083 } 084 085 /** 086 * Gets the file extension for artifacts to exclude. 087 * 088 * @return The file extension of artifacts to exclude, never {@code null}. 089 */ 090 public String getExtension() 091 { 092 return extension; 093 } 094 095 @Override 096 public String toString() 097 { 098 return getGroupId() + ':' + getArtifactId() + ':' + getExtension() 099 + ( getClassifier().length() > 0 ? ':' + getClassifier() : "" ); 100 } 101 102 @Override 103 public boolean equals( Object obj ) 104 { 105 if ( obj == this ) 106 { 107 return true; 108 } 109 else if ( obj == null || !getClass().equals( obj.getClass() ) ) 110 { 111 return false; 112 } 113 114 Exclusion that = (Exclusion) obj; 115 116 return artifactId.equals( that.artifactId ) && groupId.equals( that.groupId ) 117 && extension.equals( that.extension ) && classifier.equals( that.classifier ); 118 } 119 120 @Override 121 public int hashCode() 122 { 123 int hash = 17; 124 hash = hash * 31 + artifactId.hashCode(); 125 hash = hash * 31 + groupId.hashCode(); 126 hash = hash * 31 + classifier.hashCode(); 127 hash = hash * 31 + extension.hashCode(); 128 return hash; 129 } 130 131}