Package org.sonar.api.utils

Examples of org.sonar.api.utils.StaxParser


   */
  public void processReport(final Project project, final SensorContext context, File report)
    throws javax.xml.stream.XMLStreamException {
    CxxUtils.LOG.info("cppcheck V1 - Parsing report '{}'", report);

    StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() {
      /**
       * {@inheritDoc}
       */
      public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException {

        try {
          rootCursor.advance(); // results
        } catch (com.ctc.wstx.exc.WstxEOFException eofExc) {
          throw new EmptyReportException();
        }

        try {
          SMInputCursor errorCursor = rootCursor.childElementCursor("error"); // error
          while (errorCursor.getNext() != null) {
            String file = errorCursor.getAttrValue("file");
            String line = errorCursor.getAttrValue("line");
            String id = errorCursor.getAttrValue("id");
            String msg = errorCursor.getAttrValue("msg");

            if (isInputValid(file, line, id, msg)) {
              sensor.saveUniqueViolation(project, context, CxxCppCheckRuleRepository.KEY, file, line, id, msg);
            } else {
              CxxUtils.LOG.warn("Skipping invalid violation: '{}'", msg);
            }
          }
        } catch (RuntimeException e) {
          throw new XMLStreamException();
        }
      }

      private boolean isInputValid(String file, String line, String id, String msg) {
        return !StringUtils.isEmpty(id) && !StringUtils.isEmpty(msg);
      }
    });

    parser.parse(report);
  }
View Full Code Here


    return DEFAULT_REPORT_PATH;
  }

  @Override
  protected void processReport(final Project project, final SensorContext context, File report) throws javax.xml.stream.XMLStreamException {
    StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() {

      /**
       * {@inheritDoc}
       */
      public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException {
        rootCursor.advance();

        SMInputCursor errorCursor = rootCursor.childElementCursor("error");
        while (errorCursor.getNext() != null) {
          String file = errorCursor.getAttrValue("file");
          String line = errorCursor.getAttrValue("line");
          String id = errorCursor.getAttrValue("id");
          String msg = errorCursor.getAttrValue("msg");

          saveUniqueViolation(project, context, CxxExternalRuleRepository.KEY, file, line, id, msg);
        }
      }
    });

    parser.parse(report);
  }
View Full Code Here

  private void parseReport(Project project, SensorContext context, File report)
      throws javax.xml.stream.XMLStreamException, IOException {
    CxxUtils.LOG.info("Parsing report '{}'", report);

    TestSuiteParser parserHandler = new TestSuiteParser();
    StaxParser parser = new StaxParser(parserHandler, false);
    parser.parse(report);

    for (TestSuite fileReport : parserHandler.getParsedReports()) {
      String fileKey = fileReport.getKey();
      try {
        org.sonar.api.resources.File resource = getTestFile(project, context, fileKey);
View Full Code Here

   */
  public void processReport(final Project project, final SensorContext context, File report)
    throws javax.xml.stream.XMLStreamException {
    CxxUtils.LOG.info("cppcheck V2 - Parsing report '{}'", report);

    StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() {
      /**
       * {@inheritDoc}
       */
      public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException {
        boolean parsed = false;

        try {
          rootCursor.advance();
        } catch (com.ctc.wstx.exc.WstxEOFException eofExc) {
          throw new EmptyReportException();
        }

        try {
          String version = rootCursor.getAttrValue("version");
          if (version.equals("2")) {
            SMInputCursor errorsCursor = rootCursor.childElementCursor("errors");
            if (errorsCursor.getNext() != null) {
              parsed = true;
              SMInputCursor errorCursor = errorsCursor.childElementCursor("error");
              while (errorCursor.getNext() != null) {
                String id = errorCursor.getAttrValue("id");
                String msg = errorCursor.getAttrValue("msg");
                String file = null;
                String line = null;

                SMInputCursor locationCursor = errorCursor.childElementCursor("location");
                if (locationCursor.getNext() != null) {
                  file = locationCursor.getAttrValue("file");
                  line = locationCursor.getAttrValue("line");
                }

                if (isInputValid(file, line, id, msg)) {
                  sensor.saveUniqueViolation(project, context, CxxCppCheckRuleRepository.KEY, file, line, id, msg);
                } else {
                  CxxUtils.LOG.warn("Skipping invalid violation: '{}'", msg);
                }
              }
            }
          }
        } catch (RuntimeException e) {
          throw new XMLStreamException();
        }

        if (!parsed) {
          throw new XMLStreamException();
        }
      }

      private boolean isInputValid(String file, String line, String id, String msg) {
        return !StringUtils.isEmpty(id) && !StringUtils.isEmpty(msg);
      }
    });

    parser.parse(report);
  }
View Full Code Here

  @Override
  protected void processReport(final Project project, final SensorContext context, File report)
      throws javax.xml.stream.XMLStreamException
  {
    StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() {
      /**
       * {@inheritDoc}
       */

      public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException {
        try{
          rootCursor.advance();
        }
        catch(com.ctc.wstx.exc.WstxEOFException eofExc){
          throw new EmptyReportException();
        }

        SMInputCursor errorCursor = rootCursor.childElementCursor("issue");
        try {
        while (errorCursor.getNext() != null){

          String file = errorCursor.getAttrValue("file");
          String line = errorCursor.getAttrValue("line");
          String id = errorCursor.getAttrValue("number");
          String msg = errorCursor.getAttrValue("desc");
            if (isInputValid(file, line, id, msg)) {
              //remap MISRA IDs. Only Unique rules for MISRA 2004 and 2008 has been created in the rule repository
              if(msg.contains("MISRA 2004") || msg.contains("MISRA 2008")) {
                  id = mapMisraRulesToUniqueSonarRules(msg);
              }
              saveUniqueViolation(project, context, CxxPCLintRuleRepository.KEY,
                                  file, line, id, msg);
            } else {
              CxxUtils.LOG.warn("PC-lint warning ignored: {}", msg);
              CxxUtils.LOG.debug("File: " + file + ", Line: " + line + ", ID: "
                  + id + ", msg: " + msg);
            }
         }
        } catch (com.ctc.wstx.exc.WstxUnexpectedCharException e) {
          CxxUtils.LOG.error("Ignore XML error from PC-lint '{}'", e.toString());
        }
      }

      private boolean isInputValid(String file, String line, String id, String msg) {
        if (StringUtils.isEmpty(file) || (Integer.valueOf(line)==0)) {
          // issue for project or file level
          return !StringUtils.isEmpty(id) && !StringUtils.isEmpty(msg);
        }
        return !StringUtils.isEmpty(file) && !StringUtils.isEmpty(id) && !StringUtils.isEmpty(msg);
      }

      /**
      Concatenate M with the MISRA rule
      number to get the new rule id to save the violation to.
      **/
      private String mapMisraRulesToUniqueSonarRules(String msg){
        Pattern pattern = Pattern.compile("Rule\\x20(\\d{1,2}.\\d{1,2}|\\d{1,2}-\\d{1,2}-\\d{1,2}),");
        Matcher matcher = pattern.matcher(msg);
        matcher.find();
        String misraRule = matcher.group(1);
        String newKey = "M" + misraRule;

        String debugText = "Remap MISRA rule " + misraRule + " to key " + newKey;
        CxxUtils.LOG.debug(debugText);
        return newKey;
      }
    });

    parser.parse(report);
  }
View Full Code Here

  @Override
  protected void processReport(final Project project, final SensorContext context, File report)
      throws javax.xml.stream.XMLStreamException
  {
    try {
      StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() {
        /**
         * {@inheritDoc}
         */
        public void stream(SMHierarchicCursor rootCursor) throws javax.xml.stream.XMLStreamException {
          try{
            rootCursor.advance();
          }
          catch(com.ctc.wstx.exc.WstxEOFException eofExc){
            throw new EmptyReportException();
          }

          SMInputCursor fileCursor = rootCursor.childElementCursor("file");
          while (fileCursor.getNext() != null) {
            String name = fileCursor.getAttrValue("name");

            CxxUtils.LOG.info("Vera++ processes file = " + name);
            SMInputCursor errorCursor = fileCursor.childElementCursor("error");
            while (errorCursor.getNext() != null) {
              if (!name.equals("error")) {
                String line = errorCursor.getAttrValue("line");
                String message = errorCursor.getAttrValue("message");
                String source = errorCursor.getAttrValue("source");

                saveUniqueViolation(project, context, CxxVeraxxRuleRepository.KEY,
                                    name, line, source, message);
              } else {
                CxxUtils.LOG.debug("Error in file '{}', with message '{}'",
                    errorCursor.getAttrValue("line"),
                    errorCursor.getAttrValue("message"));
              }
            }
          }
        }
      });

      parser.parse(report);
    } catch (com.ctc.wstx.exc.WstxUnexpectedCharException e) {
      CxxUtils.LOG.error("Ignore XML error from Veraxx '{}'", e.toString());
    }
  }
View Full Code Here

   */
  public Set<ValgrindError> parseReport(File report)
      throws javax.xml.stream.XMLStreamException
  {
    ValgrindReportStreamHandler streamHandler = new ValgrindReportStreamHandler();
    new StaxParser(streamHandler).parse(report);
    return streamHandler.valgrindErrors;
  }
View Full Code Here

  public void parseReport(File xmlFile, final Map<String, CoverageMeasuresBuilder> coverageData)
      throws XMLStreamException
  {
    CxxUtils.LOG.info("Bullseye - Parsing report '{}'", xmlFile);

    StaxParser topLevelparser = new StaxParser(new StaxParser.XmlStreamHandler() {
      /**
       * {@inheritDoc}
       */
      public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException {
        rootCursor.advance();
        collectCoverageLeafNodes(rootCursor.getAttrValue("dir"), rootCursor.childElementCursor("src"), coverageData);
      }
    });
   
    StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() {
      /**
       * {@inheritDoc}
       */
      public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException {
        rootCursor.advance();
        collectCoverage2(rootCursor.getAttrValue("dir"), rootCursor.childElementCursor("folder"), coverageData);
      }
    });
   
    topLevelparser.parse(xmlFile);
    parser.parse(xmlFile);
  }
View Full Code Here

   */
  public void parseReport(File xmlFile, final Map<String, CoverageMeasuresBuilder> coverageData)
    throws XMLStreamException {
    CxxUtils.LOG.info("Parsing report '{}'", xmlFile);

    StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() {
      /**
       * {@inheritDoc}
       */
      public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException {
        rootCursor.advance();
        collectModuleMeasures(rootCursor.descendantElementCursor("module"), coverageData);
      }
    });
    parser.parse(xmlFile);
  }
View Full Code Here

  public void parseReport(File xmlFile, final Map<String, CoverageMeasuresBuilder> coverageData)
      throws XMLStreamException
  {
    CxxUtils.LOG.info("Parsing report '{}'", xmlFile);

    StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() {
      /**
       * {@inheritDoc}
       */
      public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException {
        rootCursor.advance();
        collectPackageMeasures(rootCursor.descendantElementCursor("package"), coverageData);
      }
    });
    parser.parse(xmlFile);
  }
View Full Code Here

TOP

Related Classes of org.sonar.api.utils.StaxParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.