static String mandatoryAttribute(SMInputCursor cursor, String attributeName) throws XMLStreamException { String attributeValue = cursor.getAttrValue(attributeName); if (attributeValue == null) { throw new IllegalStateException( "Missing attribute \"" + attributeName + "\" in element \"" + cursor.getLocalName() + "\" at line " + cursor.getCursorLocation().getLineNumber()); } return attributeValue; }
String keyAttribute = ruleC.getAttrValue("key"); if (isNotBlank(keyAttribute)) { param.key = trim(keyAttribute); String typeAttribute = ruleC.getAttrValue("type"); if (isNotBlank(typeAttribute)) { param.type = RuleParamType.parse(typeAttribute);
SMInputCursor bCursor = cursor.childElementCursor("b"); while (bCursor.getNext() != null) { String from = bCursor.getAttrValue("s"); String size = bCursor.getAttrValue("l"); boolean disableLink = Boolean.parseBoolean(bCursor.getAttrValue("t")); String componentDbKey = bCursor.getAttrValue("r"); if (from != null && size != null && componentDbKey != null) { if (disableLink) {
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 static void parseLineToCover(SMInputCursor cursor, NewCoverage newCoverage) throws XMLStreamException { checkElementName(cursor, "lineToCover"); String lineNumberAsString = mandatoryAttribute(cursor, LINE_NUMBER_ATTR); int lineNumber = intValue(lineNumberAsString, cursor, LINE_NUMBER_ATTR, 1); boolean covered = getCoveredValue(cursor); newCoverage.lineHits(lineNumber, covered ? 1 : 0); String branchesToCoverAsString = cursor.getAttrValue(BRANCHES_TO_COVER_ATTR); if (branchesToCoverAsString != null) { int branchesToCover = intValue(branchesToCoverAsString, cursor, BRANCHES_TO_COVER_ATTR, 0); String coveredBranchesAsString = cursor.getAttrValue(COVERED_BRANCHES_ATTR); int coveredBranches = 0; if (coveredBranchesAsString != null) { coveredBranches = intValue(coveredBranchesAsString, cursor, COVERED_BRANCHES_ATTR, 0); if (coveredBranches > branchesToCover) { throw new IllegalStateException("\"coveredBranches\" should not be greater than \"branchesToCover\" on line " + cursor.getCursorLocation().getLineNumber()); } } newCoverage.conditions(lineNumber, branchesToCover, coveredBranches); } }
private static void processRule(Rule rule, SMInputCursor ruleC) throws XMLStreamException { String keyAttribute = ruleC.getAttrValue("key"); if (StringUtils.isNotBlank(keyAttribute)) { rule.setKey(StringUtils.trim(keyAttribute)); String priorityAttribute = ruleC.getAttrValue("priority"); if (StringUtils.isNotBlank(priorityAttribute)) { rule.setSeverity(RulePriority.valueOf(StringUtils.trim(priorityAttribute)));
String keyAttribute = ruleC.getAttrValue("key"); if (isNotBlank(keyAttribute)) { key = trim(keyAttribute); String priorityAttribute = ruleC.getAttrValue("priority"); if (isNotBlank(priorityAttribute)) { severity = trim(priorityAttribute);
private static String getTestCaseName(SMInputCursor testCaseCursor) throws XMLStreamException { String classname = testCaseCursor.getAttrValue("classname"); String name = testCaseCursor.getAttrValue("name"); if (StringUtils.contains(classname, "$")) { return StringUtils.substringAfter(classname, "$") + "/" + name; } return name; }
private String getTestCaseName(SMInputCursor testCaseCursor) throws XMLStreamException { String classname = testCaseCursor.getAttrValue("classname"); String name = testCaseCursor.getAttrValue("name"); if (StringUtils.contains(classname, "$")) { return StringUtils.substringAfter(classname, "$") + "/" + name; } return name; }
private static String getClassname(SMInputCursor testCaseCursor, String defaultClassname) throws XMLStreamException { String testClassName = testCaseCursor.getAttrValue("classname"); if (StringUtils.isNotBlank(testClassName) && testClassName.endsWith(")")) { int openParenthesisIndex = testClassName.indexOf('('); if (openParenthesisIndex > 0) { testClassName = testClassName.substring(0, openParenthesisIndex); } } return StringUtils.defaultIfBlank(testClassName, defaultClassname); }
private CoverageMeasuresBuilder builderFor(final SMInputCursor clazz) throws XMLStreamException { final String fileName = clazz.getAttrValue("filename"); CoverageMeasuresBuilder builder = measuresForReport.get(fileName); if (builder == null) { builder = CoverageMeasuresBuilder.create(); measuresForReport.put(fileName, builder); } return builder; } }
private long getTimeAttributeInMS(SMInputCursor testCaseCursor) throws XMLStreamException { // hardcoded to Locale.ENGLISH see http://jira.codehaus.org/browse/SONAR-602 try { Double time = ParsingUtils.parseNumber(testCaseCursor.getAttrValue("time"), Locale.ENGLISH); return !Double.isNaN(time) ? new Double(ParsingUtils.scaleValue(time * 1000, 3)).longValue() : 0L; } catch (ParseException e) { throw new XMLStreamException(e); } }
private void collectViolationsFor(final SMInputCursor file) throws XMLStreamException { final String filePath = file.getAttrValue("name"); LoggerFactory.getLogger(getClass()).debug( "Collection violations for {}", filePath); final org.sonar.api.resources.File resource = findResource(filePath); if (fileExists(resource)) { LoggerFactory.getLogger(getClass()).debug( "File {} was found in the project.", filePath); collectFileViolations(resource, file); } }
private static double parseTime(SMInputCursor testCaseCursor) throws XMLStreamException { double time; try { Double tmp = ParsingUtils.parseNumber(testCaseCursor.getAttrValue("time"), Locale.ENGLISH); time = ParsingUtils.scaleValue(tmp * 1000, 3); } catch (ParseException e) { throw new XMLStreamException(e); } return time; }
private static double parseTime(SMInputCursor testCaseCursor) throws XMLStreamException { double time; try { Double tmp = ParsingUtils.parseNumber(testCaseCursor.getAttrValue("time"), Locale.ENGLISH); time = ParsingUtils.scaleValue(tmp * 1000, 3); } catch (ParseException e) { throw new XMLStreamException(e); } return time; }
private void setStackAndMessage(UnitTestResult result, SMInputCursor stackAndMessageCursor) throws XMLStreamException { result.setMessage(stackAndMessageCursor.getAttrValue("message")); String stack = stackAndMessageCursor.collectDescendantText(); result.setStackTrace(stack); }
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 boolean canBeIncludedInFileMetrics(SMInputCursor metricsCursor) throws ParseException, XMLStreamException { while (metricsCursor.getNext() != null && isClass(metricsCursor)) { // skip class elements on 1.x xml format } return ParsingUtils.parseNumber(metricsCursor.getAttrValue("elements")) > 0; }
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; }