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