001/*
002 * SonarQube
003 * Copyright (C) 2009-2017 SonarSource SA
004 * mailto:info AT sonarsource DOT com
005 *
006 * This program 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 * This program 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
024/**
025 * @deprecated since 5.2 No more design features
026 */
027@Deprecated
028public final class Library extends Resource {
029
030  private String name;
031  private String description;
032  private String version;
033
034  public Library(String key, String version) {
035    setKey(key);
036    this.version = version;
037  }
038
039  public String getVersion() {
040    return version;
041  }
042
043  public Library setName(String name) {
044    this.name = name;
045    return this;
046  }
047
048  public Library setDescription(String description) {
049    this.description = description;
050    return this;
051  }
052
053  @Override
054  public String getName() {
055    return name;
056  }
057
058  @Override
059  public String getLongName() {
060    return null;
061  }
062
063  @Override
064  public String getDescription() {
065    return description;
066  }
067
068  @Override
069  public Language getLanguage() {
070    return null;
071  }
072
073  @Override
074  public String getScope() {
075    return Scopes.PROJECT;
076  }
077
078  @Override
079  public String getQualifier() {
080    return Qualifiers.LIBRARY;
081  }
082
083  @Override
084  public Resource getParent() {
085    return null;
086  }
087
088  @Override
089  public boolean matchFilePattern(String antPattern) {
090    return false;
091  }
092
093  public static Library createFromMavenIds(String groupId, String artifactId, String version) {
094    return new Library(String.format("%s:%s", groupId, artifactId), version);
095  }
096
097  @Override
098  public boolean equals(Object o) {
099    if (this == o) {
100      return true;
101    }
102    if (o == null || getClass() != o.getClass()) {
103      return false;
104    }
105    Library library = (Library) o;
106    if (!getKey().equals(library.getKey())) {
107      return false;
108    }
109    return version.equals(library.version);
110  }
111
112  @Override
113  public int hashCode() {
114    int result = super.hashCode();
115    result = 31 * result + getKey().hashCode();
116    result = 31 * result + version.hashCode();
117    return result;
118  }
119
120  @Override
121  public String toString() {
122    return new ToStringBuilder(this)
123      .append("key", getKey())
124      .append("name", getName())
125      .append("version", version)
126      .toString();
127  }
128}