private static String nodeValue(SMInputCursor cursor) throws XMLStreamException { return trim(cursor.collectDescendantText(false)); }
private static 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(ATTRIBUTE_PARAMETER_KEY, nodeName)) { key = StringUtils.trim(propCursor.collectDescendantText(false)); } else if (StringUtils.equals(ATTRIBUTE_PARAMETER_VALUE, nodeName)) { value = StringUtils.trim(propCursor.collectDescendantText(false)); } } if (key != null) { parameters.put(key, value); } } }
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); } } }
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); }
@CheckForNull private static RuleDebt processRule(ValidationMessages validationMessages, SMInputCursor cursor) throws XMLStreamException { String ruleRepositoryKey = cursor.collectDescendantText().trim(); String ruleKey = null; Properties properties = new Properties(); while (cursor.getNext() != null) { String node = cursor.getLocalName(); if (StringUtils.equals(node, PROPERTY)) { properties.add(processProperty(validationMessages, cursor)); } else if (StringUtils.equals(node, RULE_KEY)) { ruleKey = cursor.collectDescendantText().trim(); } } if (isNotBlank(ruleRepositoryKey) && isNotBlank(ruleKey)) { return createRule(RuleKey.of(ruleRepositoryKey, ruleKey), properties, validationMessages); } return null; }
String nodeName = ruleCursor.getLocalName(); if (StringUtils.equals(ATTRIBUTE_REPOSITORY_KEY, nodeName)) { repositoryKey = StringUtils.trim(ruleCursor.collectDescendantText(false)); key = StringUtils.trim(ruleCursor.collectDescendantText(false)); severity = StringUtils.trim(ruleCursor.collectDescendantText(false));
rule.setName(StringUtils.trim(cursor.collectDescendantText(false))); rule.setDescription(StringUtils.trim(cursor.collectDescendantText(false))); rule.setKey(StringUtils.trim(cursor.collectDescendantText(false))); rule.setConfigKey(StringUtils.trim(cursor.collectDescendantText(false))); rule.setSeverity(RulePriority.valueOf(StringUtils.trim(cursor.collectDescendantText(false)))); rule.setCardinality(Cardinality.valueOf(StringUtils.trim(cursor.collectDescendantText(false)))); rule.setStatus(StringUtils.trim(cursor.collectDescendantText(false))); tags.add(StringUtils.trim(cursor.collectDescendantText(false)));
repositoryKey = StringUtils.trim(ruleCursor.collectDescendantText(false)); key = StringUtils.trim(ruleCursor.collectDescendantText(false)); priority = RulePriority.valueOf(StringUtils.trim(ruleCursor.collectDescendantText(false)));
String nodeName = cursor.getLocalName(); if (StringUtils.equals(ATTRIBUTE_NAME, nodeName)) { profileName = StringUtils.trim(cursor.collectDescendantText(false)); profileLang = StringUtils.trim(cursor.collectDescendantText(false));
public RulesProfile parse(Reader reader, ValidationMessages messages) { RulesProfile profile = RulesProfile.create(); SMInputFactory inputFactory = initStax(); try { SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader); rootC.advance(); // <profile> 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; }
private static void processParameter(Rule rule, SMInputCursor ruleC) throws XMLStreamException { RuleParam param = rule.createParameter(); String keyAttribute = ruleC.getAttrValue("key"); if (StringUtils.isNotBlank(keyAttribute)) { /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */ param.setKey(StringUtils.trim(keyAttribute)); } String typeAttribute = ruleC.getAttrValue("type"); if (StringUtils.isNotBlank(typeAttribute)) { /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */ param.setType(type(StringUtils.trim(typeAttribute))); } SMInputCursor paramC = ruleC.childElementCursor(); while (paramC.getNext() != null) { String propNodeName = paramC.getLocalName(); String propText = StringUtils.trim(paramC.collectDescendantText(false)); if (StringUtils.equalsIgnoreCase("key", propNodeName)) { param.setKey(propText); } else if (StringUtils.equalsIgnoreCase("description", propNodeName)) { param.setDescription(propText); } else if (StringUtils.equalsIgnoreCase("type", propNodeName)) { param.setType(type(propText)); } else if (StringUtils.equalsIgnoreCase("defaultValue", propNodeName)) { param.setDefaultValue(propText); } } if (StringUtils.isEmpty(param.getKey())) { throw new SonarException("Node <key> is missing in <param>"); } }
private void parseTestCase(SMInputCursor cursor, MutableTestPlan testPlan) throws XMLStreamException { checkElementName(cursor, "testCase"); MutableTestCase testCase = testPlan.addTestCase(mandatoryAttribute(cursor, NAME_ATTR)); TestCase.Status status = TestCase.Status.OK; testCase.setDurationInMs(longValue(mandatoryAttribute(cursor, DURATION_ATTR), cursor, DURATION_ATTR, 0)); SMInputCursor child = cursor.descendantElementCursor(); if (child.getNext() != null) { String elementName = child.getLocalName(); if (SKIPPED.equals(elementName)) { status = TestCase.Status.SKIPPED; } else if (FAILURE.equals(elementName)) { status = TestCase.Status.FAILURE; } else if (ERROR.equals(elementName)) { status = TestCase.Status.ERROR; } if (TestCase.Status.OK != status) { testCase.setMessage(mandatoryAttribute(child, MESSAGE_ATTR)); testCase.setStackTrace(child.collectDescendantText()); } } testCase.setStatus(status); }
/** * Return the key of the rule pointed by ruleCursor. */ private String processKey(SMInputCursor ruleCursor) throws XMLStreamException { SMInputCursor childCursor = ruleCursor.childElementCursor("key"); childCursor.getNext(); return StringUtils.trim(childCursor.collectDescendantText(false)); }
private static void setStackAndMessage(UnitTestResult result, SMInputCursor stackAndMessageCursor) throws XMLStreamException { result.setMessage(stackAndMessageCursor.getAttrValue("message")); String stack = stackAndMessageCursor.collectDescendantText(); result.setStackTrace(stack); }
private void setStackAndMessage(UnitTestResult result, SMInputCursor stackAndMessageCursor) throws XMLStreamException { result.setMessage(stackAndMessageCursor.getAttrValue("message")); String stack = stackAndMessageCursor.collectDescendantText(); result.setStackTrace(stack); }
private void setStackAndMessage(UnitTestResult result, SMInputCursor stackAndMessageCursor) throws XMLStreamException { result.setMessage(stackAndMessageCursor.getAttrValue("message")); String stack = stackAndMessageCursor.collectDescendantText(); result.setStackTrace(stack); }
private void setStackAndMessage(UnitTestResult result, SMInputCursor stackAndMessageCursor) throws XMLStreamException { result.setMessage(stackAndMessageCursor.getAttrValue("message")); String stack = stackAndMessageCursor.collectDescendantText(); result.setStackTrace(stack); }
private void parseRuleDefects(SMInputCursor cursor, Rule currentRule) throws XMLStreamException { gendarmeViolationMaker.setCurrentRule(currentRule); gendarmeViolationMaker.setCurrentDefaultViolationMessage(""); SMInputCursor childCursor = cursor.childElementCursor(); while (childCursor.getNext() != null) { if ("problem".equals(childCursor.getQName().getLocalPart())) { gendarmeViolationMaker.setCurrentDefaultViolationMessage(childCursor.collectDescendantText().trim()); } else if ("target".equals(childCursor.getQName().getLocalPart())) { parseTargetBloc(childCursor); } } }
private static ScanInfo processScanInfo(SMInputCursor siC) throws XMLStreamException { SMInputCursor childCursor = siC.childCursor(); ScanInfo scanInfo = new ScanInfo(); while (childCursor.getNext() != null) { String nodeName = childCursor.getLocalName(); if (StringUtils.equalsIgnoreCase("engineVersion", nodeName)) { scanInfo.setEngineVersion(StringUtils.trim(childCursor.collectDescendantText(false))); } } return scanInfo; }
private static void setStackAndMessage(UnitTestResult result, SMInputCursor stackAndMessageCursor) throws XMLStreamException { result.setMessage(stackAndMessageCursor.getAttrValue("message")); String stack = stackAndMessageCursor.collectDescendantText(); result.setStackTrace(stack); }