001 /*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2013 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.rules;
021
022 import org.sonar.check.Priority;
023
024 /**
025 * A class to hold rules priority
026 */
027 public enum RulePriority {
028
029 /**
030 * WARNING : DO NOT CHANGE THE ENUMERATION ORDER
031 * the enum ordinal is used for db persistence
032 */
033 INFO, MINOR, MAJOR, CRITICAL, BLOCKER;
034
035 /**
036 * A class to map priority level prior to Sonar 1.10 to the new ones
037 *
038 * @param level an old priority level : Error or Warning
039 * @return the corresponding RulePriority
040 * @deprecated in 3.6
041 */
042 @Deprecated
043 public static RulePriority valueOfString(String level) {
044 try {
045 return RulePriority.valueOf(level.toUpperCase());
046
047 } catch (IllegalArgumentException ex) {
048 // backward compatibility
049 if ("ERROR".equalsIgnoreCase(level)) {
050 return RulePriority.MAJOR;
051 } else if ("WARNING".equalsIgnoreCase(level)) {
052 return RulePriority.INFO;
053 }
054 }
055 throw new IllegalArgumentException("Unknown priority " + level);
056 }
057
058
059 public static RulePriority fromCheckPriority(Priority checkPriority) {
060 if (checkPriority == Priority.BLOCKER) {
061 return RulePriority.BLOCKER;
062 }
063 if (checkPriority == Priority.CRITICAL) {
064 return RulePriority.CRITICAL;
065 }
066 if (checkPriority == Priority.MAJOR) {
067 return RulePriority.MAJOR;
068 }
069 if (checkPriority == Priority.MINOR) {
070 return RulePriority.MINOR;
071 }
072 if (checkPriority == Priority.INFO) {
073 return RulePriority.INFO;
074 }
075 throw new IllegalArgumentException("Unknown priority " + checkPriority);
076 }
077 }