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 */
020package org.sonar.xoo.rule;
021
022import org.sonar.api.rule.RuleStatus;
023import org.sonar.api.rule.Severity;
024import org.sonar.api.server.rule.RuleParamType;
025import org.sonar.api.server.rule.RulesDefinition;
026import org.sonar.api.server.rule.RulesDefinitionAnnotationLoader;
027import org.sonar.xoo.Xoo;
028import org.sonar.xoo.checks.Check;
029
030/**
031 * Define all the coding rules that are supported on the repository named "xoo".
032 */
033public class XooRulesDefinition implements RulesDefinition {
034
035  public static final String XOO_REPOSITORY = "xoo";
036
037  @Override
038  public void define(Context context) {
039    NewRepository repository = context.createRepository(XOO_REPOSITORY, Xoo.KEY).setName("Xoo");
040
041    // Load checks
042    new RulesDefinitionAnnotationLoader().load(repository, Check.ALL);
043
044    // define a single rule programmatically. Note that rules
045    // can be loaded from JSON or XML files too.
046    NewRule x1Rule = repository.createRule("x1")
047      .setName("No empty line")
048      .setMarkdownDescription("Generate an issue on *empty* lines of Xoo source files")
049
050      // optional tags
051      .setTags("style", "security")
052
053      // optional status. Default value is READY.
054      .setStatus(RuleStatus.BETA)
055
056      // default severity when the rule is activated on a Quality profile. Default value is MAJOR.
057      .setSeverity(Severity.MINOR);
058
059    // debt-related information
060    x1Rule
061      .setDebtSubCharacteristic(SubCharacteristics.INTEGRATION_TESTABILITY)
062      .setDebtRemediationFunction(x1Rule.debtRemediationFunctions().linearWithOffset("1h", "30min"))
063      .setEffortToFixDescription("Effort to fix issue on one line");
064
065    x1Rule.createParam("acceptWhitespace")
066      .setDefaultValue("false")
067      .setType(RuleParamType.BOOLEAN)
068      .setDescription("= Accept whitespace (``\\s|\\t``) on the line\nThis property is available so that a line containing only whitespace is not considered empty.\n"
069        + "== Example with property set to ``false``\n``xoo\n   <- One issue here\n<- And one here\n``\n\n"
070        + "== Example with property set to ``true``\n``xoo\n   <- No issue here\n<- But one here\n``\n");
071
072    // don't forget to call done() to finalize the definition
073    repository.done();
074  }
075
076}