Search in sources :

Example 6 with RuleDebt

use of org.sonar.server.debt.DebtModelXMLExporter.RuleDebt in project sonarqube by SonarSource.

the class DebtRulesXMLImporterTest method read_integer.

@Test
public void read_integer() throws Exception {
    String xml = getFileContent("read_integer.xml");
    List<RuleDebt> results = underTest.importXML(xml, validationMessages);
    assertThat(results).hasSize(1);
    RuleDebt ruleDebt = results.get(0);
    assertThat(ruleDebt.ruleKey()).isEqualTo(RuleKey.of("checkstyle", "Regexp"));
    assertThat(ruleDebt.function()).isEqualTo(DebtRemediationFunction.Type.LINEAR.name());
    assertThat(ruleDebt.coefficient()).isEqualTo("3h");
    assertThat(ruleDebt.offset()).isNull();
}
Also used : RuleDebt(org.sonar.server.debt.DebtModelXMLExporter.RuleDebt) Test(org.junit.Test)

Example 7 with RuleDebt

use of org.sonar.server.debt.DebtModelXMLExporter.RuleDebt in project sonarqube by SonarSource.

the class DebtRulesXMLImporterTest method replace_mn_by_min.

@Test
public void replace_mn_by_min() throws Exception {
    String xml = getFileContent("replace_mn_by_min.xml");
    List<RuleDebt> results = underTest.importXML(xml, validationMessages);
    assertThat(results).hasSize(1);
    RuleDebt ruleDebt = results.get(0);
    assertThat(ruleDebt.function()).isEqualTo(DebtRemediationFunction.Type.LINEAR.name());
    assertThat(ruleDebt.coefficient()).isEqualTo("3min");
    assertThat(ruleDebt.offset()).isNull();
}
Also used : RuleDebt(org.sonar.server.debt.DebtModelXMLExporter.RuleDebt) Test(org.junit.Test)

Example 8 with RuleDebt

use of org.sonar.server.debt.DebtModelXMLExporter.RuleDebt in project sonarqube by SonarSource.

the class DeprecatedRulesDefinitionLoader method complete.

void complete(RulesDefinition.Context context) {
    // Load rule debt definitions from xml files provided by plugin
    List<RuleDebt> ruleDebts = loadRuleDebtList();
    for (RuleRepository repository : repositories) {
        // RuleRepository API does not handle difference between new and extended repositories,
        RulesDefinition.NewRepository newRepository;
        if (context.repository(repository.getKey()) == null) {
            newRepository = context.createRepository(repository.getKey(), repository.getLanguage());
            newRepository.setName(repository.getName());
        } else {
            newRepository = context.extendRepository(repository.getKey(), repository.getLanguage());
        }
        for (org.sonar.api.rules.Rule rule : repository.createRules()) {
            RulesDefinition.NewRule newRule = newRepository.createRule(rule.getKey());
            newRule.setName(ruleName(repository.getKey(), rule));
            newRule.setHtmlDescription(ruleDescription(repository.getKey(), rule));
            newRule.setInternalKey(rule.getConfigKey());
            newRule.setTemplate(rule.isTemplate());
            newRule.setSeverity(rule.getSeverity().toString());
            newRule.setStatus(rule.getStatus() == null ? RuleStatus.defaultStatus() : RuleStatus.valueOf(rule.getStatus()));
            newRule.setTags(rule.getTags());
            for (RuleParam param : rule.getParams()) {
                RulesDefinition.NewParam newParam = newRule.createParam(param.getKey());
                newParam.setDefaultValue(param.getDefaultValue());
                newParam.setDescription(paramDescription(repository.getKey(), rule.getKey(), param));
                newParam.setType(RuleParamType.parse(param.getType()));
            }
            updateRuleDebtDefinitions(newRule, repository.getKey(), rule.getKey(), ruleDebts);
        }
        newRepository.done();
    }
}
Also used : RulesDefinition(org.sonar.api.server.rule.RulesDefinition) RuleParam(org.sonar.api.rules.RuleParam) RuleRepository(org.sonar.api.rules.RuleRepository) RuleDebt(org.sonar.server.debt.DebtModelXMLExporter.RuleDebt)

Example 9 with RuleDebt

use of org.sonar.server.debt.DebtModelXMLExporter.RuleDebt in project sonarqube by SonarSource.

the class DebtRulesXMLImporterTest method import_badly_formatted_xml.

@Test
public void import_badly_formatted_xml() throws Exception {
    String xml = getFileContent("import_badly_formatted_xml.xml");
    List<RuleDebt> results = underTest.importXML(xml, validationMessages);
    assertThat(results).hasSize(1);
    RuleDebt ruleDebt = results.get(0);
    assertThat(ruleDebt.ruleKey()).isEqualTo(RuleKey.of("checkstyle", "Regexp"));
    assertThat(ruleDebt.function()).isEqualTo(DebtRemediationFunction.Type.LINEAR.name());
    assertThat(ruleDebt.coefficient()).isEqualTo("3h");
    assertThat(ruleDebt.offset()).isNull();
}
Also used : RuleDebt(org.sonar.server.debt.DebtModelXMLExporter.RuleDebt) Test(org.junit.Test)

Example 10 with RuleDebt

use of org.sonar.server.debt.DebtModelXMLExporter.RuleDebt in project sonarqube by SonarSource.

the class DebtRulesXMLImporterTest method import_constant_issue.

@Test
public void import_constant_issue() throws Exception {
    String xml = getFileContent("import_constant_issue.xml");
    List<RuleDebt> results = underTest.importXML(xml, validationMessages);
    assertThat(results).hasSize(1);
    RuleDebt ruleDebt = results.get(0);
    assertThat(ruleDebt.function()).isEqualTo(DebtRemediationFunction.Type.CONSTANT_ISSUE.name());
    assertThat(ruleDebt.coefficient()).isNull();
    assertThat(ruleDebt.offset()).isEqualTo("3d");
}
Also used : RuleDebt(org.sonar.server.debt.DebtModelXMLExporter.RuleDebt) Test(org.junit.Test)

Aggregations

RuleDebt (org.sonar.server.debt.DebtModelXMLExporter.RuleDebt)14 Test (org.junit.Test)11 Reader (java.io.Reader)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 SMInputFactory (org.codehaus.staxmate.SMInputFactory)1 SMHierarchicCursor (org.codehaus.staxmate.in.SMHierarchicCursor)1 SMInputCursor (org.codehaus.staxmate.in.SMInputCursor)1 RuleParam (org.sonar.api.rules.RuleParam)1 RuleRepository (org.sonar.api.rules.RuleRepository)1 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)1 ValidationMessages (org.sonar.api.utils.ValidationMessages)1