001 /* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2008-2011 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 */ 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 */ 041 public static RulePriority valueOfString(String level) { 042 try { 043 return RulePriority.valueOf(level.toUpperCase()); 044 045 } catch (IllegalArgumentException ex) { 046 // backward compatibility 047 if (level.equalsIgnoreCase("ERROR")) { 048 return RulePriority.MAJOR; 049 } else if (level.equalsIgnoreCase("WARNING")) { 050 return RulePriority.INFO; 051 } 052 } 053 throw new IllegalArgumentException("Unknown priority " + level); 054 } 055 056 057 public static RulePriority fromCheckPriority(Priority checkPriority) { 058 if (checkPriority == Priority.BLOCKER) { 059 return RulePriority.BLOCKER; 060 } 061 if (checkPriority == Priority.CRITICAL) { 062 return RulePriority.CRITICAL; 063 } 064 if (checkPriority == Priority.MAJOR) { 065 return RulePriority.MAJOR; 066 } 067 if (checkPriority == Priority.MINOR) { 068 return RulePriority.MINOR; 069 } 070 if (checkPriority == Priority.INFO) { 071 return RulePriority.INFO; 072 } 073 return null; 074 } 075 076 public Priority toCheckPriority() { 077 if (this == BLOCKER) { 078 return Priority.BLOCKER; 079 } 080 if (this == CRITICAL) { 081 return Priority.CRITICAL; 082 } 083 if (this == MAJOR) { 084 return Priority.MAJOR; 085 } 086 if (this == MINOR) { 087 return Priority.MINOR; 088 } 089 if (this == INFO) { 090 return Priority.INFO; 091 } 092 return null; 093 } 094 }