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     */
020    package org.sonar.plugins.pmd;
021    
022    import org.sonar.api.rules.RulePriority;
023    
024    public final class PmdLevelUtils {
025    
026      private PmdLevelUtils() {
027        // only static methods
028      }
029    
030      public static RulePriority fromLevel(String level) {
031        if ("1".equals(level)) {
032          return RulePriority.BLOCKER;
033        }
034        if ("2".equals(level)) {
035          return RulePriority.CRITICAL;
036        }
037        if ("3".equals(level)) {
038          return RulePriority.MAJOR;
039        }
040        if ("4".equals(level)) {
041          return RulePriority.MINOR;
042        }
043        if ("5".equals(level)) {
044          return RulePriority.INFO;
045        }
046        return null;
047      }
048    
049      public static String toLevel(RulePriority priority) {
050        if (priority.equals(RulePriority.BLOCKER)) {
051          return "1";
052        }
053        if (priority.equals(RulePriority.CRITICAL)) {
054          return "2";
055        }
056        if (priority.equals(RulePriority.MAJOR)) {
057          return "3";
058        }
059        if (priority.equals(RulePriority.MINOR)) {
060          return "4";
061        }
062        if (priority.equals(RulePriority.INFO)) {
063          return "5";
064        }
065        throw new IllegalArgumentException("Level not supported: " + priority);
066      }
067    }