use of org.codehaus.staxmate.in.SMInputCursor in project sonarqube by SonarSource.
the class XMLProfileParser method processParameters.
private static void processParameters(SMInputCursor propsCursor, Map<String, String> parameters) throws XMLStreamException {
while (propsCursor.getNext() != null) {
SMInputCursor propCursor = propsCursor.childElementCursor();
String key = null;
String value = null;
while (propCursor.getNext() != null) {
String nodeName = propCursor.getLocalName();
if (StringUtils.equals("key", nodeName)) {
key = StringUtils.trim(propCursor.collectDescendantText(false));
} else if (StringUtils.equals("value", nodeName)) {
value = StringUtils.trim(propCursor.collectDescendantText(false));
}
}
if (key != null) {
parameters.put(key, value);
}
}
}
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 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.codehaus.staxmate.in.SMInputCursor in project sonarqube by SonarSource.
the class QProfileBackuper method parseRuleActivations.
private List<RuleActivation> parseRuleActivations(SMInputCursor rulesCursor) throws XMLStreamException {
List<RuleActivation> activations = Lists.newArrayList();
Set<RuleKey> activatedKeys = Sets.newHashSet();
List<RuleKey> duplicatedKeys = Lists.newArrayList();
while (rulesCursor.getNext() != null) {
SMInputCursor ruleCursor = rulesCursor.childElementCursor();
String repositoryKey = null;
String key = null;
String severity = null;
Map<String, String> parameters = Maps.newHashMap();
while (ruleCursor.getNext() != null) {
String nodeName = ruleCursor.getLocalName();
if (StringUtils.equals("repositoryKey", nodeName)) {
repositoryKey = StringUtils.trim(ruleCursor.collectDescendantText(false));
} else if (StringUtils.equals("key", nodeName)) {
key = StringUtils.trim(ruleCursor.collectDescendantText(false));
} else if (StringUtils.equals("priority", nodeName)) {
severity = StringUtils.trim(ruleCursor.collectDescendantText(false));
} else if (StringUtils.equals("parameters", nodeName)) {
SMInputCursor propsCursor = ruleCursor.childElementCursor("parameter");
readParameters(propsCursor, parameters);
}
}
RuleKey ruleKey = RuleKey.of(repositoryKey, key);
if (activatedKeys.contains(ruleKey)) {
duplicatedKeys.add(ruleKey);
}
activatedKeys.add(ruleKey);
RuleActivation activation = new RuleActivation(ruleKey);
activation.setSeverity(severity);
activation.setParameters(parameters);
activations.add(activation);
}
if (!duplicatedKeys.isEmpty()) {
throw new IllegalArgumentException("The quality profile cannot be restored as it contains duplicates for the following rules: " + RULE_KEY_JOINER.join(duplicatedKeys));
}
return activations;
}
use of org.codehaus.staxmate.in.SMInputCursor in project sonarqube by SonarSource.
the class QProfileBackuper method readParameters.
private void readParameters(SMInputCursor propsCursor, Map<String, String> parameters) throws XMLStreamException {
while (propsCursor.getNext() != null) {
SMInputCursor propCursor = propsCursor.childElementCursor();
String key = null;
String value = null;
while (propCursor.getNext() != null) {
String nodeName = propCursor.getLocalName();
if (StringUtils.equals("key", nodeName)) {
key = StringUtils.trim(propCursor.collectDescendantText(false));
} else if (StringUtils.equals("value", nodeName)) {
value = StringUtils.trim(propCursor.collectDescendantText(false));
}
}
if (key != null) {
parameters.put(key, value);
}
}
}
Aggregations