001/*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2008-2012 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * Sonar 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 * Sonar 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
017 * License along with Sonar; if not, write to the Free Software
018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
019 */
020package org.sonar.server.plugins;
021
022import org.sonar.updatecenter.common.Plugin;
023import org.sonar.updatecenter.common.Release;
024
025import java.util.ArrayList;
026import java.util.List;
027
028public final class SonarUpdate implements Comparable<SonarUpdate> {
029
030  private Release release;
031  private List<Plugin> compatiblePlugins = new ArrayList<Plugin>();
032  private List<Plugin> incompatiblePlugins = new ArrayList<Plugin>();
033  private List<Release> pluginsToUpgrade = new ArrayList<Release>();
034
035  public SonarUpdate(Release release) {
036    this.release = release;
037  }
038
039  public Release getRelease() {
040    return release;
041  }
042
043  public List<Plugin> getCompatiblePlugins() {
044    return compatiblePlugins;
045  }
046
047  public List<Plugin> getIncompatiblePlugins() {
048    return incompatiblePlugins;
049  }
050
051  public List<Release> getPluginsToUpgrade() {
052    return pluginsToUpgrade;
053  }
054
055  public boolean hasWarnings() {
056    return isIncompatible() || requiresPluginUpgrades();
057  }
058
059  public boolean requiresPluginUpgrades() {
060    return !pluginsToUpgrade.isEmpty();
061  }
062
063  public boolean isIncompatible() {
064    return !incompatiblePlugins.isEmpty();
065  }
066
067  public void addCompatiblePlugin(Plugin plugin) {
068    compatiblePlugins.add(plugin);
069  }
070
071  public void addIncompatiblePlugin(Plugin plugin) {
072    incompatiblePlugins.add(plugin);
073  }
074
075  public void addPluginToUpgrade(Release plugin) {
076    pluginsToUpgrade.add(plugin);
077  }
078
079  @Override
080  public boolean equals(Object o) {
081    if (this == o) {
082      return true;
083    }
084    if (o == null || getClass() != o.getClass()) {
085      return false;
086    }
087    SonarUpdate update = (SonarUpdate) o;
088    return release.equals(update.release);
089  }
090
091  @Override
092  public int hashCode() {
093    return release.hashCode();
094  }
095
096  public int compareTo(SonarUpdate su) {
097    return release.compareTo(su.release);
098  }
099}