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