2 * Sonar, open source software quality management tool.
3 * Copyright (C) 2009 SonarSource SA
4 * mailto:contact AT sonarsource DOT com
6 * Sonar is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * Sonar is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Sonar; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
20 package org.sonar.updatecenter.common;
24 public abstract class Artifact implements Comparable<Artifact> {
27 protected SortedSet<Release> releases = new TreeSet<Release>();
29 protected Artifact(String key) {
33 public final String getKey() {
37 public final Artifact setKey(String key) {
42 public final Artifact setReleases(Collection<Release> releases) {
43 this.releases.clear();
44 if (releases != null) {
45 for (Release release : releases) {
52 public final Release addRelease(Release release) {
53 releases.add(release);
57 public final Release addRelease(Version version) {
58 return addRelease(new Release(this, version));
61 public final Release getRelease(Version version) {
62 for (Release release : getReleases()) {
63 if (release.getVersion().equals(version)) {
70 public final SortedSet<Release> getReleases() {
75 * Shortcut for Ruby code
77 public final SortedSet<Release> getReleasesGreaterThan(String version) {
78 return getReleasesGreaterThan(Version.create(version));
81 public final SortedSet<Release> getReleasesGreaterThan(Version version) {
82 TreeSet<Release> result = new TreeSet<Release>();
83 for (Release release : releases) {
84 if (release.getVersion().compareTo(version)>0) {
91 public final SortedSet<Version> getVersions() {
92 SortedSet<Version> versions = new TreeSet<Version>();
93 for (Release release : releases) {
94 versions.add(release.getVersion());
99 public final Release getLastRelease() {
100 return releases.isEmpty() ? null : releases.last();
103 public final Release getLastCompatibleRelease(Version sonarVersion) {
104 Release result = null;
105 for (Release r : releases) {
106 if (r.supportSonarVersion(sonarVersion)) {
113 public final Release getLastCompatibleReleaseIfUpgrade(Version sonarVersion) {
114 Release result = null;
115 for (Release r : releases) {
116 if (r.getLastRequiredSonarVersion()!=null && r.getLastRequiredSonarVersion().compareTo(sonarVersion)>=0) {
124 public final boolean equals(Object o) {
128 if (!(o instanceof Artifact)) {
131 Artifact artifact = (Artifact) o;
132 return key.equals(artifact.key);
136 public final int hashCode() {
137 return key.hashCode();
140 public final int compareTo(Artifact other) {
144 return key.compareTo(other.key);