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.rules;
021
022import java.util.Locale;
023import org.sonar.check.Priority;
024
025/**
026 * @deprecated since 4.2
027 * @see org.sonar.api.rule.Severity
028 */
029@Deprecated
030public enum RulePriority {
031
032  /**
033   * WARNING : DO NOT CHANGE THE ENUMERATION ORDER
034   * the enum ordinal is used for db persistence
035   */
036  INFO, MINOR, MAJOR, CRITICAL, BLOCKER;
037
038  private static final String UNKNOWN_PRIORITY = "Unknown priority ";
039
040  /**
041   * A class to map priority level prior to Sonar 1.10 to the new ones
042   *
043   * @param level an old priority level : Error or Warning
044   * @return the corresponding RulePriority
045   * @deprecated in 3.6
046   */
047  @Deprecated
048  public static RulePriority valueOfString(String level) {
049    try {
050      return RulePriority.valueOf(level.toUpperCase(Locale.ENGLISH));
051
052    } catch (IllegalArgumentException ex) {
053      // backward compatibility
054      if ("ERROR".equalsIgnoreCase(level)) {
055        return RulePriority.MAJOR;
056      } else if ("WARNING".equalsIgnoreCase(level)) {
057        return RulePriority.INFO;
058      }
059    }
060    throw new IllegalArgumentException(UNKNOWN_PRIORITY + level);
061  }
062
063
064  public static RulePriority fromCheckPriority(Priority checkPriority) {
065    if (checkPriority == Priority.BLOCKER) {
066      return RulePriority.BLOCKER;
067    }
068    if (checkPriority == Priority.CRITICAL) {
069      return RulePriority.CRITICAL;
070    }
071    if (checkPriority == Priority.MAJOR) {
072      return RulePriority.MAJOR;
073    }
074    if (checkPriority == Priority.MINOR) {
075      return RulePriority.MINOR;
076    }
077    if (checkPriority == Priority.INFO) {
078      return RulePriority.INFO;
079    }
080    throw new IllegalArgumentException(UNKNOWN_PRIORITY + checkPriority);
081  }
082
083  public static RulePriority valueOfInt(int ordinal) {
084    return RulePriority.values()[ordinal];
085  }
086}