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;
}
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);
}
}
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");
}
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();
}
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"));
}
Aggregations