Package org.sonar.api.utils

Examples of org.sonar.api.utils.StaxParser


  }

  private void parse(String path) throws XMLStreamException {
    File xml = TestUtils.getResource(getClass(), path);
    SurefireStaxHandler staxParser = new SurefireStaxHandler(index);
    StaxParser parser = new StaxParser(staxParser, false);
    parser.parse(xml);
  }
View Full Code Here


    save(index, context);
  }

  private void parseFiles(File[] reports, UnitTestIndex index) {
    SurefireStaxHandler staxParser = new SurefireStaxHandler(index);
    StaxParser parser = new StaxParser(staxParser, false);
    for (File report : reports) {
      try {
        parser.parse(report);
      } catch (XMLStreamException e) {
        throw new SonarException("Fail to parse the Surefire report: " + report, e);
      }
    }
  }
View Full Code Here

    final org.sonar.api.resources.File dummyFile = new org.sonar.api.resources.File("test");
    givenAProject().containingSourceDirectory("dummy");
    final SensorContext context = mock(SensorContext.class);

    final List<Violation> parseResults = new ArrayList<Violation>();
    final StaxParser parser = new StaxParser(new OCLintXMLStreamHandler(parseResults, project(), context));

    when(context.getResource(any(Resource.class))).thenReturn(dummyFile);

    parser.parse(new StringInputStream(VALID_REPORT));

    assertEquals(VIOLATION_LINE, parseResults.get(0).getLineId());
  }
View Full Code Here

    final org.sonar.api.resources.File dummyFile = new org.sonar.api.resources.File("test");
    givenAProject().containingSourceDirectory("dummy");
    final SensorContext context = mock(SensorContext.class);

    final List<Violation> parseResults = new ArrayList<Violation>();
    final StaxParser parser = new StaxParser(new OCLintXMLStreamHandler(parseResults, project(), context));

    when(context.getResource(any(Resource.class))).thenReturn(dummyFile);

    parser.parse(new StringInputStream(VALID_REPORT));

    assertEquals(RulePriority.MAJOR, parseResults.get(0).getRule().getSeverity());
  }
View Full Code Here

    final org.sonar.api.resources.File dummyFile = new org.sonar.api.resources.File("test");
    givenAProject().containingSourceDirectory("dummy");
    final SensorContext context = mock(SensorContext.class);

    final List<Violation> parseResults = new ArrayList<Violation>();
    final StaxParser parser = new StaxParser(new OCLintXMLStreamHandler(parseResults, project(), context));

    when(context.getResource(any(Resource.class))).thenReturn(dummyFile);

    parser.parse(new StringInputStream(VALID_REPORT));

    assertEquals(RULE_KEY, parseResults.get(0).getRule().getKey());
  }
View Full Code Here

    public Map<String, CoverageMeasuresBuilder> parseReport(
            final InputStream xmlFile) {

        final Map<String, CoverageMeasuresBuilder> measuresForReport = new HashMap<String, CoverageMeasuresBuilder>();
        try {
            final StaxParser parser = new StaxParser(
                    new CoberturaXMLStreamHandler(measuresForReport));
            parser.parse(xmlFile);
        } catch (final XMLStreamException e) {
            LoggerFactory.getLogger(getClass()).error(
                    "Error while parsing XML stream.", e);
        }
        return measuresForReport;
View Full Code Here

    }

    public Collection<Violation> parseReport(final InputStream inputStream) {
        final Collection<Violation> violations = new ArrayList<Violation>();
        try {
            final StaxParser parser = new StaxParser(
                    new OCLintXMLStreamHandler(violations, project, context));
            parser.parse(inputStream);
            LoggerFactory.getLogger(getClass()).error(
                    "Reporting {} violations.", violations.size());
        } catch (final XMLStreamException e) {
            LoggerFactory.getLogger(getClass()).error(
                    "Error while parsing XML stream.", e);
View Full Code Here

  private final int BRANCH_LINE = 35;

  @Test
  public void streamLeavesTheMapEmptyWhenNoLinesAreFound() throws XMLStreamException {
    final Map<String, CoverageMeasuresBuilder> parseResults = new HashMap<String, CoverageMeasuresBuilder>();
    final StaxParser parser = new StaxParser(new CoberturaXMLStreamHandler(parseResults));

    parser.parse(new StringInputStream(EMPTY_REPORT));

    assertTrue(parseResults.isEmpty());
  }
View Full Code Here

  }

  @Test
  public void streamAddsACoverageMeasureBuilderForClassesInTheReport() throws XMLStreamException {
    final Map<String, CoverageMeasuresBuilder> parseResults = new HashMap<String, CoverageMeasuresBuilder>();
    final StaxParser parser = new StaxParser(new CoberturaXMLStreamHandler(parseResults));

    parser.parse(new StringInputStream(VALID_REPORT));

    assertNotNull(parseResults.get(FILE_PATH));
  }
View Full Code Here

  }

  @Test
  public void streamRecords0HitsForLinesWithNoHits() throws XMLStreamException {
    final Map<String, CoverageMeasuresBuilder> parseResults = new HashMap<String, CoverageMeasuresBuilder>();
    final StaxParser parser = new StaxParser(new CoberturaXMLStreamHandler(parseResults));

    parser.parse(new StringInputStream(VALID_REPORT));

    assertEquals(Integer.valueOf(0), parseResults.get(FILE_PATH).getHitsByLine().get(NO_HIT_LINE));
  }
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.