Search in sources :

Example 1 with RuleDebt

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

the class DebtRulesXMLImporter method importXML.

public List<RuleDebt> importXML(Reader xml, ValidationMessages validationMessages) {
    List<RuleDebt> ruleDebts = newArrayList();
    try {
        SMInputFactory inputFactory = initStax();
        SMHierarchicCursor cursor = inputFactory.rootElementCursor(xml);
        // advance to <sqale>
        cursor.advance();
        SMInputCursor rootCursor = cursor.childElementCursor(CHARACTERISTIC);
        while (rootCursor.getNext() != null) {
            process(ruleDebts, validationMessages, rootCursor);
        }
        cursor.getStreamReader().closeCompletely();
    } catch (XMLStreamException e) {
        throw new IllegalStateException("XML is not valid", e);
    }
    return ruleDebts;
}
Also used : SMInputCursor(org.codehaus.staxmate.in.SMInputCursor) SMHierarchicCursor(org.codehaus.staxmate.in.SMHierarchicCursor) XMLStreamException(javax.xml.stream.XMLStreamException) SMInputFactory(org.codehaus.staxmate.SMInputFactory) RuleDebt(org.sonar.server.debt.DebtModelXMLExporter.RuleDebt)

Example 2 with RuleDebt

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

the class DeprecatedRulesDefinitionLoader method loadRuleDebtsFromXml.

public List<RuleDebt> loadRuleDebtsFromXml(String pluginKey) {
    Reader xmlFileReader = null;
    try {
        xmlFileReader = languageModelFinder.createReaderForXMLFile(pluginKey);
        ValidationMessages validationMessages = ValidationMessages.create();
        List<RuleDebt> rules = importer.importXML(xmlFileReader, validationMessages);
        validationMessages.log(LOG);
        return rules;
    } finally {
        IOUtils.closeQuietly(xmlFileReader);
    }
}
Also used : Reader(java.io.Reader) RuleDebt(org.sonar.server.debt.DebtModelXMLExporter.RuleDebt) ValidationMessages(org.sonar.api.utils.ValidationMessages)

Example 3 with RuleDebt

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

the class DebtRulesXMLImporterTest method convert_constant_per_issue_with_coefficient_by_constant_per_issue_with_offset.

@Test
public void convert_constant_per_issue_with_coefficient_by_constant_per_issue_with_offset() throws Exception {
    String xml = getFileContent("convert_constant_per_issue_with_coefficient_by_constant_per_issue_with_offset.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("3h");
}
Also used : RuleDebt(org.sonar.server.debt.DebtModelXMLExporter.RuleDebt) Test(org.junit.Test)

Example 4 with RuleDebt

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

the class DebtRulesXMLImporterTest method import_linear.

@Test
public void import_linear() throws Exception {
    String xml = getFileContent("import_linear.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 5 with RuleDebt

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

the class DebtModelXMLExporterTest method export_xml.

@Test
public void export_xml() throws Exception {
    List<RuleDebt> rules = newArrayList(new RuleDebt().setRuleKey(RuleKey.of("checkstyle", "Regexp")).setFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name()).setCoefficient("3d").setOffset("15min"));
    assertThat(underTest.export(rules)).isXmlEqualTo(getFileContent("export_xml.xml"));
}
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