public static boolean isAnEndElement(SMInputCursor cursor){ try{ return cursor.asEvent().isEndElement(); }catch(XMLStreamException e){ throw new SonarPluginException("Error while testing if the cursor were a end element", e); } }
public static XMLEvent findXMLEvent(SMInputCursor cursor){ try{ return cursor.asEvent(); }catch(XMLStreamException e){ throw new SonarPluginException("Error while trying to get XMLEvent", e); } }
public static boolean isAStartElement(SMInputCursor cursor){ try{ return cursor.asEvent().isStartElement(); }catch(XMLStreamException e){ throw new SonarPluginException("Error while testing if the cursor were a start element", e); } }
/** * @return */ public List<PhpCodeSnifferViolation> getViolations(File reportFile) { LOG.debug("Report file for PHP_CodeSniffer is " + reportFile); if (reportFile == null || !reportFile.exists()) { throw new SonarException("The XML report '" + reportFile + "' can't be found"); } String reportPath = reportFile.getAbsolutePath(); LOG.debug("Getting violations form report file"); List<PhpCodeSnifferViolation> violations = new ArrayList<PhpCodeSnifferViolation>(); try {// <checkstyle> SMInputFactory inputFactory = new SMInputFactory(XMLInputFactory.newInstance());// <checkstyle> SMInputCursor rootNodeCursor = inputFactory.rootElementCursor(reportFile).advance(); // <file> SMInputCursor fileNodeCursor = rootNodeCursor.childElementCursor(FILE_NODE_NAME).advance(); while (fileNodeCursor.asEvent() != null) { String fileName = fileNodeCursor.getAttrValue(FILE_NAME_ATTRIBUTE_NAME); SMInputCursor violationNodeCursor = fileNodeCursor.childElementCursor().advance(); // <error> while (violationNodeCursor.asEvent() != null) { violations.add(getViolation(fileName, violationNodeCursor)); violationNodeCursor.advance(); } fileNodeCursor.advance(); } rootNodeCursor.getStreamReader().closeCompletely(); } catch (XMLStreamException e) { throw new XmlParserException("Unable to parse the XML Report '" + reportPath + "'", e); } return violations; }
SMInputCursor cursor = inf.rootElementCursor(findbugsXmlReport).advance(); SMInputCursor bugInstanceCursor = cursor.childElementCursor("BugInstance").advance(); while (bugInstanceCursor.asEvent() != null) { XmlBugInstance xmlBugInstance = new XmlBugInstance(); xmlBugInstance.type = bugInstanceCursor.getAttrValue("type"); while (bugInstanceChildCursor.asEvent() != null) { String nodeName = bugInstanceChildCursor.getLocalName(); if ("LongMessage".equals(nodeName)) {
SMInputCursor lineCursor = fileCursor.descendantElementCursor("line"); while (lineCursor.getNext() != null) { if (!lineCursor.asEvent().isStartElement()) { continue;
private void collectFileMeasures(SMInputCursor fileCursor) throws ParseException, XMLStreamException { fileCursor.setFilter(SMFilterFactory.getElementOnlyFilter("file")); while (fileCursor.getNext() != null) { if (fileCursor.asEvent().isStartElement()) { String absoluteFilePath = fileCursor.getAttrValue("path"); if (absoluteFilePath != null) { SMInputCursor fileChildrenCursor = fileCursor.childCursor(new SimpleFilter(SMEvent.START_ELEMENT)); // cursor should be on the metrics element if (canBeIncludedInFileMetrics(fileChildrenCursor)) { // cursor should be now on the line cursor saveHitsData(getResource(absoluteFilePath), fileChildrenCursor); } } } } }