001 /*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2014 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.batch.rule.internal;
021
022 import org.apache.commons.lang.StringUtils;
023 import org.sonar.api.rule.RuleKey;
024 import org.sonar.api.rule.Severity;
025
026 import javax.annotation.Nullable;
027
028 import java.util.HashMap;
029 import java.util.Map;
030
031 /**
032 * @since 4.2
033 */
034 public class NewActiveRule {
035 final RuleKey ruleKey;
036 String severity = Severity.defaultSeverity();
037 Map<String, String> params = new HashMap<String, String>();
038 String internalKey, language;
039 private final ActiveRulesBuilder builder;
040
041 NewActiveRule(ActiveRulesBuilder builder, RuleKey ruleKey) {
042 this.builder = builder;
043 this.ruleKey = ruleKey;
044 }
045
046 public NewActiveRule setSeverity(@Nullable String severity) {
047 this.severity = StringUtils.defaultIfBlank(severity, Severity.defaultSeverity());
048 return this;
049 }
050
051 public NewActiveRule setInternalKey(@Nullable String internalKey) {
052 this.internalKey = internalKey;
053 return this;
054 }
055
056 public NewActiveRule setLanguage(@Nullable String language) {
057 this.language = language;
058 return this;
059 }
060
061 public NewActiveRule setParam(String key, @Nullable String value) {
062 // possible improvement : check that the param key exists in rule definition
063 if (value == null) {
064 params.remove(key);
065 } else {
066 params.put(key, value);
067 }
068 return this;
069 }
070
071 public Map<String, String> params() {
072 return params;
073 }
074
075 public ActiveRulesBuilder activate() {
076 builder.activate(this);
077 return builder;
078 }
079 }