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. 024 * 025 * @see Dependency#getExclusions() 026 */ 027public final class Exclusion 028{ 029 030 private final String groupId; 031 032 private final String artifactId; 033 034 private final String classifier; 035 036 private final String extension; 037 038 /** 039 * Creates an exclusion for artifacts with the specified coordinates. 040 * 041 * @param groupId The group identifier, may be {@code null}. 042 * @param artifactId The artifact identifier, may be {@code null}. 043 * @param classifier The classifier, may be {@code null}. 044 * @param extension The file extension, may be {@code null}. 045 */ 046 public Exclusion( String groupId, String artifactId, String classifier, String extension ) 047 { 048 this.groupId = ( groupId != null ) ? groupId : ""; 049 this.artifactId = ( artifactId != null ) ? artifactId : ""; 050 this.classifier = ( classifier != null ) ? classifier : ""; 051 this.extension = ( extension != null ) ? extension : ""; 052 } 053 054 /** 055 * Gets the group identifier for artifacts to exclude. 056 * 057 * @return The group identifier, never {@code null}. 058 */ 059 public String getGroupId() 060 { 061 return groupId; 062 } 063 064 /** 065 * Gets the artifact identifier for artifacts to exclude. 066 * 067 * @return The artifact identifier, never {@code null}. 068 */ 069 public String getArtifactId() 070 { 071 return artifactId; 072 } 073 074 /** 075 * Gets the classifier for artifacts to exclude. 076 * 077 * @return The classifier, never {@code null}. 078 */ 079 public String getClassifier() 080 { 081 return classifier; 082 } 083 084 /** 085 * Gets the file extension for artifacts to exclude. 086 * 087 * @return The file extension of artifacts to exclude, never {@code null}. 088 */ 089 public String getExtension() 090 { 091 return extension; 092 } 093 094 @Override 095 public String toString() 096 { 097 return getGroupId() + ':' + getArtifactId() + ':' + getExtension() 098 + ( getClassifier().length() > 0 ? ':' + getClassifier() : "" ); 099 } 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}