private static void process(List<RuleDebt> ruleDebts, ValidationMessages validationMessages, SMInputCursor chcCursor) throws XMLStreamException { SMInputCursor cursor = chcCursor.childElementCursor(); while (cursor.getNext() != null) { String node = cursor.getLocalName(); if (StringUtils.equals(node, CHARACTERISTIC)) { process(ruleDebts, validationMessages, cursor); } else if (StringUtils.equals(node, REPOSITORY_KEY)) { RuleDebt ruleDebt = processRule(validationMessages, cursor); if (ruleDebt != null) { ruleDebts.add(ruleDebt); } } } }
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); } } }
List<RuleKey> duplicatedKeys = new ArrayList<>(); while (rulesCursor.getNext() != null) { SMInputCursor ruleCursor = rulesCursor.childElementCursor(); String repositoryKey = null; String key = null; SMInputCursor propsCursor = ruleCursor.childElementCursor(ATTRIBUTE_PARAMETER); readParameters(propsCursor, parameters);
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); }
SMInputCursor paramC = ruleC.childElementCursor(); while (paramC.getNext() != null) { String propNodeName = paramC.getLocalName();
private void processRules(SMInputCursor rulesCursor, RulesProfile profile, ValidationMessages messages) throws XMLStreamException { Map<String, String> parameters = new HashMap<>(); while (rulesCursor.getNext() != null) { SMInputCursor ruleCursor = rulesCursor.childElementCursor(); SMInputCursor propsCursor = ruleCursor.childElementCursor("parameter"); processParameters(propsCursor, parameters);
while (cursor.getNext() != null) { List<Duplication> duplications = new ArrayList<>(); SMInputCursor bCursor = cursor.childElementCursor("b"); while (bCursor.getNext() != null) { String from = bCursor.getAttrValue("s");
SMInputCursor cursor = ruleC.childElementCursor();
SMInputCursor rulesCursor = cursor.childElementCursor("rule"); rules = parseRuleActivations(rulesCursor);
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>"); } }
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; }
SMInputCursor cursor = ruleC.childElementCursor(); while (cursor.getNext() != null) { String nodeName = cursor.getLocalName();
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); } } }
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); matchedFileKeys.add(inputFile.key()); NewCoverage newCoverage = context.newCoverage().onFile(inputFile); SMInputCursor lineToCoverCursor = fileCursor.childElementCursor(); while (lineToCoverCursor.getNext() != null) { parseLineToCover(lineToCoverCursor, newCoverage); } newCoverage.save(); } }
private void collectFileData(final SMInputCursor clazz) throws XMLStreamException { final CoverageMeasuresBuilder builder = builderFor(clazz); final SMInputCursor line = clazz.childElementCursor("lines").advance() .childElementCursor("line"); while (null != line.getNext()) { recordCoverageFor(line, builder); } }
private void processSubChar(SMInputCursor subCharCursor) throws XMLStreamException { String subCharName = null; SMInputCursor subCharChildCursor = subCharCursor.childElementCursor(); while (subCharChildCursor.getNext() != null) { String childName = subCharChildCursor.getLocalName(); if ("key".equals(childName)) { subCharName = subCharChildCursor.getElemStringValue(); } if ("chc".equals(childName)) { processRule(subCharName, subCharChildCursor); } } }
private static ProjectNode parseProjectNode(SMInputCursor cursor) throws XMLStreamException { ProjectNode result = new ProjectNode(); result.setName(cursor.getAttrValue("name")); SMInputCursor childCursor = cursor.childElementCursor(); while (childCursor.getNext() != null) { if ("package".equals(childCursor.getLocalName())) { result.getPackages().add(parsePackageNode(childCursor)); } else if ("file".equals(childCursor.getLocalName())) { result.getFiles().add(parseFileNode(childCursor)); } } return result; }
private static FileNode parseFileNode(SMInputCursor cursor) throws XMLStreamException { FileNode result = new FileNode(); result.setName(cursor.getAttrValue("name")); SMInputCursor childCursor = cursor.childElementCursor("line"); while (childCursor.getNext() != null) { result.getLines().add(parseLineNode(childCursor)); } return result; }
private void processRoot(InputStreamReader reader, SMInputFactory inputFactory) throws XMLStreamException { SMHierarchicCursor rootCursor = inputFactory.rootElementCursor(reader); rootCursor.advance(); SMInputCursor charCursor = rootCursor.childElementCursor("chc"); while (charCursor.getNext() != null) { SMInputCursor subCharCursor = charCursor.childElementCursor("chc"); while (subCharCursor.getNext() != null) { processSubChar(subCharCursor); } } }