001/* 002 * SonarQube, open source software quality management tool. 003 * Copyright (C) 2008-2014 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * SonarQube is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * SonarQube is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License 017 * along with this program; if not, write to the Free Software Foundation, 018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 */ 020package org.sonar.api.resources; 021 022import org.apache.commons.lang.builder.ToStringBuilder; 023 024public final class Library extends Resource { 025 026 private String name; 027 private String description; 028 private String version; 029 030 public Library(String key, String version) { 031 setKey(key); 032 this.version = version; 033 } 034 035 public String getVersion() { 036 return version; 037 } 038 039 public Library setName(String name) { 040 this.name = name; 041 return this; 042 } 043 044 public Library setDescription(String description) { 045 this.description = description; 046 return this; 047 } 048 049 @Override 050 public String getName() { 051 return name; 052 } 053 054 @Override 055 public String getLongName() { 056 return null; 057 } 058 059 @Override 060 public String getDescription() { 061 return description; 062 } 063 064 @Override 065 public Language getLanguage() { 066 return null; 067 } 068 069 @Override 070 public String getScope() { 071 return Scopes.PROJECT; 072 } 073 074 @Override 075 public String getQualifier() { 076 return Qualifiers.LIBRARY; 077 } 078 079 @Override 080 public Resource getParent() { 081 return null; 082 } 083 084 @Override 085 public boolean matchFilePattern(String antPattern) { 086 return false; 087 } 088 089 public static Library createFromMavenIds(String groupId, String artifactId, String version) { 090 return new Library(String.format(Project.MAVEN_KEY_FORMAT, groupId, artifactId), version); 091 } 092 093 @Override 094 public boolean equals(Object o) { 095 if (this == o) { 096 return true; 097 } 098 if (o == null || getClass() != o.getClass()) { 099 return false; 100 } 101 Library library = (Library) o; 102 if (!getKey().equals(library.getKey())) { 103 return false; 104 } 105 return version.equals(library.version); 106 } 107 108 @Override 109 public int hashCode() { 110 int result = super.hashCode(); 111 result = 31 * result + getKey().hashCode(); 112 result = 31 * result + version.hashCode(); 113 return result; 114 } 115 116 @Override 117 public String toString() { 118 return new ToStringBuilder(this) 119 .append("key", getKey()) 120 .append("name", getName()) 121 .append("version", version) 122 .toString(); 123 } 124}