001/* 002 * Copyright 2012-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot.cli.compiler.dependencies; 018 019import java.util.Collections; 020import java.util.List; 021 022import org.springframework.util.Assert; 023 024/** 025 * A single dependency. 026 * 027 * @author Phillip Webb 028 * @since 1.3.0 029 */ 030public final class Dependency { 031 032 private final String groupId; 033 034 private final String artifactId; 035 036 private final String version; 037 038 private final List<Exclusion> exclusions; 039 040 /** 041 * Create a new {@link Dependency} instance. 042 * @param groupId the group ID 043 * @param artifactId the artifact ID 044 * @param version the version 045 */ 046 public Dependency(String groupId, String artifactId, String version) { 047 this(groupId, artifactId, version, Collections.emptyList()); 048 } 049 050 /** 051 * Create a new {@link Dependency} instance. 052 * @param groupId the group ID 053 * @param artifactId the artifact ID 054 * @param version the version 055 * @param exclusions the exclusions 056 */ 057 public Dependency(String groupId, String artifactId, String version, 058 List<Exclusion> exclusions) { 059 Assert.notNull(groupId, "GroupId must not be null"); 060 Assert.notNull(artifactId, "ArtifactId must not be null"); 061 Assert.notNull(version, "Version must not be null"); 062 Assert.notNull(exclusions, "Exclusions must not be null"); 063 this.groupId = groupId; 064 this.artifactId = artifactId; 065 this.version = version; 066 this.exclusions = Collections.unmodifiableList(exclusions); 067 } 068 069 /** 070 * Return the dependency group id. 071 * @return the group ID 072 */ 073 public String getGroupId() { 074 return this.groupId; 075 } 076 077 /** 078 * Return the dependency artifact id. 079 * @return the artifact ID 080 */ 081 public String getArtifactId() { 082 return this.artifactId; 083 } 084 085 /** 086 * Return the dependency version. 087 * @return the version 088 */ 089 public String getVersion() { 090 return this.version; 091 } 092 093 /** 094 * Return the dependency exclusions. 095 * @return the exclusions 096 */ 097 public List<Exclusion> getExclusions() { 098 return this.exclusions; 099 } 100 101 @Override 102 public boolean equals(Object obj) { 103 if (this == obj) { 104 return true; 105 } 106 if (obj == null) { 107 return false; 108 } 109 if (getClass() == obj.getClass()) { 110 Dependency other = (Dependency) obj; 111 boolean result = true; 112 result = result && this.groupId.equals(other.groupId); 113 result = result && this.artifactId.equals(other.artifactId); 114 result = result && this.version.equals(other.version); 115 result = result && this.exclusions.equals(other.exclusions); 116 return result; 117 } 118 return false; 119 } 120 121 @Override 122 public int hashCode() { 123 final int prime = 31; 124 int result = 1; 125 result = prime * result + this.groupId.hashCode(); 126 result = prime * result + this.artifactId.hashCode(); 127 result = prime * result + this.version.hashCode(); 128 result = prime * result + this.exclusions.hashCode(); 129 return result; 130 } 131 132 @Override 133 public String toString() { 134 return this.groupId + ":" + this.artifactId + ":" + this.version; 135 } 136 137 /** 138 * A dependency exclusion. 139 */ 140 public static final class Exclusion { 141 142 private final String groupId; 143 144 private final String artifactId; 145 146 Exclusion(String groupId, String artifactId) { 147 Assert.notNull(groupId, "GroupId must not be null"); 148 Assert.notNull(groupId, "ArtifactId must not be null"); 149 this.groupId = groupId; 150 this.artifactId = artifactId; 151 } 152 153 /** 154 * Return the exclusion artifact ID. 155 * @return the exclusion artifact ID 156 */ 157 public String getArtifactId() { 158 return this.artifactId; 159 } 160 161 /** 162 * Return the exclusion group ID. 163 * @return the exclusion group ID 164 */ 165 public String getGroupId() { 166 return this.groupId; 167 } 168 169 @Override 170 public boolean equals(Object obj) { 171 if (this == obj) { 172 return true; 173 } 174 if (obj == null) { 175 return false; 176 } 177 if (getClass() == obj.getClass()) { 178 Exclusion other = (Exclusion) obj; 179 boolean result = true; 180 result = result && this.groupId.equals(other.groupId); 181 result = result && this.artifactId.equals(other.artifactId); 182 return result; 183 } 184 return false; 185 } 186 187 @Override 188 public int hashCode() { 189 return this.groupId.hashCode() * 31 + this.artifactId.hashCode(); 190 } 191 192 @Override 193 public String toString() { 194 return this.groupId + ":" + this.artifactId; 195 } 196 197 } 198 199}