Java Code Examples for org.codehaus.staxmate.in.SMInputCursor#getAttrValue()
The following examples show how to use
org.codehaus.staxmate.in.SMInputCursor#getAttrValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CheckstyleProfileImporter.java From sonar-checkstyle with GNU Lesser General Public License v3.0 | 6 votes |
private Module loadModule(SMInputCursor parentCursor) throws XMLStreamException { final Module result = new Module(); result.name = parentCursor.getAttrValue("name"); final SMInputCursor cursor = parentCursor.childElementCursor(); while (cursor.getNext() != null) { final String nodeName = cursor.getLocalName(); if (MODULE_NODE.equals(nodeName)) { result.modules.add(loadModule(cursor)); } else if ("property".equals(nodeName)) { final String key = cursor.getAttrValue("name"); final String value = cursor.getAttrValue("value"); result.properties.put(key, value); } } return result; }
Example 2
Source File: CoberturaReportParser.java From sonar-lua with GNU Lesser General Public License v3.0 | 6 votes |
private static void collectFileData(SMInputCursor clazz, NewCoverage newCoverage) throws XMLStreamException { SMInputCursor line = clazz.childElementCursor("lines").advance().childElementCursor("line"); while (line.getNext() != null) { int lineId = Integer.parseInt(line.getAttrValue("number")); try { newCoverage.lineHits(lineId, (int) ParsingUtils.parseNumber(line.getAttrValue("hits"), Locale.ENGLISH)); } catch (ParseException e) { throw new IllegalStateException(e); } String isBranch = line.getAttrValue("branch"); String text = line.getAttrValue("condition-coverage"); if (StringUtils.equals(isBranch, "true") && StringUtils.isNotBlank(text)) { String[] conditions = StringUtils.split(StringUtils.substringBetween(text, "(", ")"), "/"); newCoverage.conditions(lineId, Integer.parseInt(conditions[1]), Integer.parseInt(conditions[0])); } } newCoverage.save(); }
Example 3
Source File: CloverXmlReportParser.java From sonar-clover with Apache License 2.0 | 5 votes |
private void collectFileMeasures(SMInputCursor fileCursor) throws ParseException, XMLStreamException { fileCursor.setFilter(SMFilterFactory.getElementOnlyFilter("file")); while (fileCursor.getNext() != null) { if (fileCursor.asEvent().isStartElement()) { String path = fileCursor.getAttrValue("path"); if (path != null) { SMInputCursor fileChildrenCursor = fileCursor.childCursor(new SimpleFilter(SMEvent.START_ELEMENT)); InputFile resource = getInputFile(path); if (resource != null) { saveHitsData(resource, fileChildrenCursor); } } } } }
Example 4
Source File: CloverXmlReportParser.java From sonar-clover with Apache License 2.0 | 5 votes |
private void saveHitsData(InputFile resource, SMInputCursor lineCursor) throws ParseException, XMLStreamException { final NewCoverage coverage = context.newCoverage().onFile(resource); // cursor should be on the metrics element if (!canBeIncludedInFileMetrics(lineCursor)) { // cursor should now be on the line cursor; exclude this file if there are no elements to cover ((DefaultInputFile) resource).setExcludedForCoverage(true); } while (lineCursor.getNext() != null) { // skip class elements on format 2_3_2 if (isClass(lineCursor)) { continue; } final int lineId = Integer.parseInt(lineCursor.getAttrValue("num")); String count = lineCursor.getAttrValue("count"); if (StringUtils.isNotBlank(count)) { final int hits = Integer.parseInt(count); coverage.lineHits(lineId, hits); } else { int trueCount = (int) ParsingUtils.parseNumber(lineCursor.getAttrValue("truecount")); int falseCount = (int) ParsingUtils.parseNumber(lineCursor.getAttrValue("falsecount")); int coveredConditions = 0; if (trueCount > 0) { coveredConditions++; } if (falseCount > 0) { coveredConditions++; } coverage.conditions(lineId, 2, coveredConditions); } } coverage.save(); }
Example 5
Source File: CoberturaReportParser.java From sonar-lua with GNU Lesser General Public License v3.0 | 5 votes |
private static void collectFileMeasures(SensorContext context, SMInputCursor clazz) throws XMLStreamException { FileSystem fileSystem = context.fileSystem(); FilePredicates predicates = fileSystem.predicates(); Map<String, InputFile> inputFileByFilename = new HashMap<>(); while (clazz.getNext() != null) { String fileName = clazz.getAttrValue("filename"); InputFile inputFile; // mxml files are not supported by the plugin if (inputFileByFilename.containsKey(fileName)) { inputFile = inputFileByFilename.get(fileName); } else { String key = fileName.startsWith(File.separator) ? fileName : (File.separator + fileName); inputFile = fileSystem.inputFile(predicates.and( predicates.matchesPathPattern("file:**" + key.replace(File.separator, "/")), predicates.hasType(InputFile.Type.MAIN), predicates.hasLanguage(Lua.KEY))); inputFileByFilename.put(fileName, inputFile); if (inputFile == null && !fileName.endsWith(".mxml")) { LOG.warn("Cannot save coverage result for file: {}, because resource not found.", fileName); } } if (inputFile != null) { collectFileData( clazz, context.newCoverage() .onFile(inputFile) .ofType(CoverageType.UNIT) ); } else { SMInputCursor line = clazz.childElementCursor("lines").advance().childElementCursor("line"); while (line.getNext() != null) { // advance } } } }