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 */
020 package org.sonar.api.resources;
021
022 import org.apache.commons.lang.builder.ToStringBuilder;
023
024 public 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 setDeprecatedKey(key);
033 this.version = version;
034 }
035
036 public String getVersion() {
037 return version;
038 }
039
040 public Library setName(String name) {
041 this.name = name;
042 return this;
043 }
044
045 public Library setDescription(String description) {
046 this.description = description;
047 return this;
048 }
049
050 @Override
051 public String getName() {
052 return name;
053 }
054
055 @Override
056 public String getLongName() {
057 return null;
058 }
059
060 @Override
061 public String getDescription() {
062 return description;
063 }
064
065 @Override
066 public Language getLanguage() {
067 return null;
068 }
069
070 @Override
071 public String getScope() {
072 return Scopes.PROJECT;
073 }
074
075 @Override
076 public String getQualifier() {
077 return Qualifiers.LIBRARY;
078 }
079
080 @Override
081 public Resource getParent() {
082 return null;
083 }
084
085 @Override
086 public boolean matchFilePattern(String antPattern) {
087 return false;
088 }
089
090 public static Library createFromMavenIds(String groupId, String artifactId, String version) {
091 return new Library(String.format(Project.MAVEN_KEY_FORMAT, groupId, artifactId), version);
092 }
093
094 @Override
095 public boolean equals(Object o) {
096 if (this == o) {
097 return true;
098 }
099 if (o == null || getClass() != o.getClass()) {
100 return false;
101 }
102 Library library = (Library) o;
103 if (!getKey().equals(library.getKey())) {
104 return false;
105 }
106 return version.equals(library.version);
107 }
108
109 @Override
110 public int hashCode() {
111 int result = super.hashCode();
112 result = 31 * result + getKey().hashCode();
113 result = 31 * result + version.hashCode();
114 return result;
115 }
116
117 @Override
118 public String toString() {
119 return new ToStringBuilder(this)
120 .append("key", getKey())
121 .append("name", getName())
122 .append("version", version)
123 .toString();
124 }
125 }