use of org.codehaus.staxmate.in.SMInputCursor in project sonarqube by SonarSource.
the class XMLProfileParser method parse.
public RulesProfile parse(Reader reader, ValidationMessages messages) {
RulesProfile profile = RulesProfile.create();
SMInputFactory inputFactory = initStax();
try {
SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader);
// <profile>
rootC.advance();
SMInputCursor cursor = rootC.childElementCursor();
while (cursor.getNext() != null) {
String nodeName = cursor.getLocalName();
if (StringUtils.equals("rules", nodeName)) {
SMInputCursor rulesCursor = cursor.childElementCursor("rule");
processRules(rulesCursor, profile, messages);
} else if (StringUtils.equals("name", nodeName)) {
profile.setName(StringUtils.trim(cursor.collectDescendantText(false)));
} else if (StringUtils.equals("language", nodeName)) {
profile.setLanguage(StringUtils.trim(cursor.collectDescendantText(false)));
}
}
} catch (XMLStreamException e) {
messages.addErrorText("XML is not valid: " + e.getMessage());
}
checkProfile(profile, messages);
return profile;
}
use of org.codehaus.staxmate.in.SMInputCursor in project sonarqube by SonarSource.
the class RulesDefinitionXmlLoader method load.
/**
* Loads rules by reading the XML input stream. The reader is not closed by the method, so it
* should be handled by the caller.
* @since 4.3
*/
public void load(RulesDefinition.NewRepository repo, Reader reader) {
XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE);
// just so it won't try to load DTD in if there's DOCTYPE
xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
SMInputFactory inputFactory = new SMInputFactory(xmlFactory);
try {
SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader);
// <rules>
rootC.advance();
SMInputCursor rulesC = rootC.childElementCursor("rule");
while (rulesC.getNext() != null) {
// <rule>
processRule(repo, rulesC);
}
} catch (XMLStreamException e) {
throw new IllegalStateException("XML is not valid", e);
}
}
use of org.codehaus.staxmate.in.SMInputCursor in project sonarqube by SonarSource.
the class RulesDefinitionXmlLoader method processParameter.
private static ParamStruct processParameter(SMInputCursor ruleC) throws XMLStreamException {
ParamStruct param = new ParamStruct();
// BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT
String keyAttribute = ruleC.getAttrValue("key");
if (isNotBlank(keyAttribute)) {
param.key = trim(keyAttribute);
}
// BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT
String typeAttribute = ruleC.getAttrValue("type");
if (isNotBlank(typeAttribute)) {
param.type = RuleParamType.parse(typeAttribute);
}
SMInputCursor paramC = ruleC.childElementCursor();
while (paramC.getNext() != null) {
String propNodeName = paramC.getLocalName();
String propText = nodeValue(paramC);
if (equalsIgnoreCase("key", propNodeName)) {
param.key = propText;
} else if (equalsIgnoreCase("description", propNodeName)) {
param.description = propText;
} else if (equalsIgnoreCase("type", propNodeName)) {
param.type = RuleParamType.parse(propText);
} else if (equalsIgnoreCase("defaultValue", propNodeName)) {
param.defaultValue = propText;
}
}
return param;
}
use of org.codehaus.staxmate.in.SMInputCursor in project sonarqube by SonarSource.
the class GenericTestExecutionReportParser method parseFiles.
private void parseFiles(SMInputCursor fileCursor, SensorContext context) throws XMLStreamException {
while (fileCursor.getNext() != null) {
checkElementName(fileCursor, "file");
String filePath = mandatoryAttribute(fileCursor, "path");
InputFile inputFile = context.fileSystem().inputFile(context.fileSystem().predicates().hasPath(filePath));
if (inputFile == null) {
numberOfUnknownFiles++;
if (numberOfUnknownFiles <= MAX_STORED_UNKNOWN_FILE_PATHS) {
firstUnknownFiles.add(filePath);
}
continue;
}
Preconditions.checkState(inputFile.language() != null, "Line %s of report refers to a file with an unknown language: %s", fileCursor.getCursorLocation().getLineNumber(), filePath);
Preconditions.checkState(inputFile.type() != InputFile.Type.MAIN, "Line %s of report refers to a file which is not configured as a test file: %s", fileCursor.getCursorLocation().getLineNumber(), filePath);
matchedFileKeys.add(inputFile.absolutePath());
MutableTestPlan testPlan = testPlanBuilder.loadPerspective(MutableTestPlan.class, inputFile);
SMInputCursor testCaseCursor = fileCursor.childElementCursor();
while (testCaseCursor.getNext() != null) {
parseTestCase(testCaseCursor, testPlan);
}
}
}
use of org.codehaus.staxmate.in.SMInputCursor in project sonarqube by SonarSource.
the class DebtRulesXMLImporter method processProperty.
private static Property processProperty(ValidationMessages validationMessages, SMInputCursor cursor) throws XMLStreamException {
SMInputCursor c = cursor.childElementCursor();
String key = null;
int value = 0;
String textValue = null;
while (c.getNext() != null) {
String node = c.getLocalName();
if (StringUtils.equals(node, PROPERTY_KEY)) {
key = c.collectDescendantText().trim();
} else if (StringUtils.equals(node, PROPERTY_VALUE)) {
String s = c.collectDescendantText().trim();
try {
Double valueDouble = NumberUtils.createDouble(s);
value = valueDouble.intValue();
} catch (NumberFormatException ex) {
validationMessages.addErrorText(String.format("Cannot import value '%s' for field %s - Expected a numeric value instead", s, key));
}
} else if (StringUtils.equals(node, PROPERTY_TEXT_VALUE)) {
textValue = c.collectDescendantText().trim();
textValue = "mn".equals(textValue) ? MINUTE : textValue;
}
}
return new Property(key, value, textValue);
}
Aggregations