Search in sources :

Example 11 with ScannerReportReader

use of org.sonar.scanner.protocol.output.ScannerReportReader in project sonarqube by SonarSource.

the class CpdExecutorTest method setUp.

@Before
public void setUp() throws IOException {
    File outputDir = temp.newFolder();
    baseDir = temp.newFolder();
    settings = new MapSettings();
    publisher = mock(ReportPublisher.class);
    when(publisher.getWriter()).thenReturn(new ScannerReportWriter(outputDir));
    index = new SonarCpdBlockIndex(publisher, settings);
    componentStore = new InputComponentStore(new PathResolver());
    executor = new CpdExecutor(settings, index, publisher, componentStore);
    reader = new ScannerReportReader(outputDir);
    componentStore.put(TestInputFileBuilder.newDefaultInputModule("foo", baseDir));
    batchComponent1 = createComponent("src/Foo.php", 5);
    batchComponent2 = createComponent("src/Foo2.php", 5);
    batchComponent3 = createComponent("src/Foo3.php", 5);
}
Also used : ReportPublisher(org.sonar.scanner.report.ReportPublisher) ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) SonarCpdBlockIndex(org.sonar.scanner.cpd.index.SonarCpdBlockIndex) MapSettings(org.sonar.api.config.MapSettings) InputComponentStore(org.sonar.scanner.scan.filesystem.InputComponentStore) PathResolver(org.sonar.api.scan.filesystem.PathResolver) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Before(org.junit.Before)

Example 12 with ScannerReportReader

use of org.sonar.scanner.protocol.output.ScannerReportReader in project sonarqube by SonarSource.

the class ActiveRulesPublisherTest method write.

@Test
public void write() throws Exception {
    File outputDir = temp.newFolder();
    ScannerReportWriter writer = new ScannerReportWriter(outputDir);
    NewActiveRule ar = new ActiveRulesBuilder().create(RuleKey.of("java", "S001")).setSeverity("BLOCKER").setParam("p1", "v1");
    ActiveRules activeRules = new DefaultActiveRules(Arrays.asList(ar));
    ActiveRulesPublisher underTest = new ActiveRulesPublisher(activeRules);
    underTest.publish(writer);
    ScannerReportReader reader = new ScannerReportReader(outputDir);
    try (CloseableIterator<ScannerReport.ActiveRule> readIt = reader.readActiveRules()) {
        ScannerReport.ActiveRule reportAr = readIt.next();
        assertThat(reportAr.getRuleRepository()).isEqualTo("java");
        assertThat(reportAr.getRuleKey()).isEqualTo("S001");
        assertThat(reportAr.getSeverity()).isEqualTo(Constants.Severity.BLOCKER);
        assertThat(reportAr.getParamsByKey()).hasSize(1);
        assertThat(reportAr.getParamsByKey().entrySet().iterator().next().getKey()).isEqualTo("p1");
        assertThat(reportAr.getParamsByKey().entrySet().iterator().next().getValue()).isEqualTo("v1");
        assertThat(readIt.hasNext()).isFalse();
    }
}
Also used : ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) ActiveRulesPublisher(org.sonar.scanner.report.ActiveRulesPublisher) NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) ActiveRules(org.sonar.api.batch.rule.ActiveRules) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) File(java.io.File) Test(org.junit.Test)

Example 13 with ScannerReportReader

use of org.sonar.scanner.protocol.output.ScannerReportReader in project sonarqube by SonarSource.

the class ScmMediumTest method getChangesets.

private ScannerReport.Changesets getChangesets(File baseDir, String path) {
    File reportDir = new File(baseDir, ".sonar/batch-report");
    ScannerReportReader reader = new ScannerReportReader(reportDir);
    Component project = reader.readComponent(reader.readMetadata().getRootComponentRef());
    Component dir = reader.readComponent(project.getChildRef(0));
    for (Integer fileRef : dir.getChildRefList()) {
        Component file = reader.readComponent(fileRef);
        if (file.getPath().equals(path)) {
            return reader.readChangesets(file.getRef());
        }
    }
    return null;
}
Also used : ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) Component(org.sonar.scanner.protocol.output.ScannerReport.Component) File(java.io.File)

Example 14 with ScannerReportReader

use of org.sonar.scanner.protocol.output.ScannerReportReader in project sonarqube by SonarSource.

the class ComponentsPublisherTest method add_components_to_report.

@Test
public void add_components_to_report() throws Exception {
    ProjectAnalysisInfo projectAnalysisInfo = mock(ProjectAnalysisInfo.class);
    when(projectAnalysisInfo.analysisDate()).thenReturn(DateUtils.parseDate("2012-12-12"));
    ProjectDefinition rootDef = ProjectDefinition.create().setKey("foo").setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "1.0").setName("Root project").setDescription("Root description");
    DefaultInputModule root = new DefaultInputModule(rootDef, 1);
    ProjectDefinition module1Def = ProjectDefinition.create().setKey("module1").setName("Module1").setDescription("Module description");
    rootDef.addSubProject(module1Def);
    DefaultInputModule module1 = new DefaultInputModule(module1Def, 2);
    moduleHierarchy = mock(InputModuleHierarchy.class);
    when(moduleHierarchy.root()).thenReturn(root);
    when(moduleHierarchy.children(root)).thenReturn(Collections.singleton(module1));
    tree.index(module1, root);
    DefaultInputDir dir = new DefaultInputDir("module1", "src", 3);
    tree.index(dir, module1);
    DefaultInputFile file = new TestInputFileBuilder("module1", "src/Foo.java", 4).setLines(2).build();
    tree.index(file, dir);
    DefaultInputFile file2 = new TestInputFileBuilder("module1", "src/Foo2.java", 5).setPublish(false).setLines(2).build();
    tree.index(file2, dir);
    DefaultInputFile fileWithoutLang = new TestInputFileBuilder("module1", "src/make", 6).setLines(10).build();
    tree.index(fileWithoutLang, dir);
    DefaultInputFile testFile = new TestInputFileBuilder("module1", "test/FooTest.java", 7).setType(Type.TEST).setLines(4).build();
    tree.index(testFile, dir);
    ComponentsPublisher publisher = new ComponentsPublisher(moduleHierarchy, tree);
    publisher.publish(writer);
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isTrue();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 2)).isTrue();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 3)).isTrue();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 4)).isTrue();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 6)).isTrue();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 7)).isTrue();
    // not marked for publishing
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 5)).isFalse();
    // no such reference
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 8)).isFalse();
    ScannerReportReader reader = new ScannerReportReader(outputDir);
    Component rootProtobuf = reader.readComponent(1);
    assertThat(rootProtobuf.getKey()).isEqualTo("foo");
    assertThat(rootProtobuf.getDescription()).isEqualTo("Root description");
    assertThat(rootProtobuf.getVersion()).isEqualTo("1.0");
    assertThat(rootProtobuf.getLinkCount()).isEqualTo(0);
    Component module1Protobuf = reader.readComponent(2);
    assertThat(module1Protobuf.getKey()).isEqualTo("module1");
    assertThat(module1Protobuf.getDescription()).isEqualTo("Module description");
    assertThat(module1Protobuf.getVersion()).isEqualTo("1.0");
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) InputModuleHierarchy(org.sonar.api.batch.fs.internal.InputModuleHierarchy) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) ProjectAnalysisInfo(org.sonar.scanner.ProjectAnalysisInfo) ComponentsPublisher(org.sonar.scanner.report.ComponentsPublisher) Component(org.sonar.scanner.protocol.output.ScannerReport.Component) DefaultInputDir(org.sonar.api.batch.fs.internal.DefaultInputDir) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Example 15 with ScannerReportReader

use of org.sonar.scanner.protocol.output.ScannerReportReader in project sonarqube by SonarSource.

the class ScannerReportViewerApp method loadReport.

private void loadReport(File file) {
    reader = new ScannerReportReader(file);
    metadata = reader.readMetadata();
    updateTitle();
    loadComponents();
}
Also used : ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader)

Aggregations

ScannerReportReader (org.sonar.scanner.protocol.output.ScannerReportReader)15 Test (org.junit.Test)9 File (java.io.File)7 ScannerReportWriter (org.sonar.scanner.protocol.output.ScannerReportWriter)6 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)5 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)4 Component (org.sonar.scanner.protocol.output.ScannerReport.Component)4 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)3 DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)3 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)3 InputModuleHierarchy (org.sonar.api.batch.fs.internal.InputModuleHierarchy)3 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)3 ProjectAnalysisInfo (org.sonar.scanner.ProjectAnalysisInfo)3 ComponentsPublisher (org.sonar.scanner.report.ComponentsPublisher)3 Matchers.anyString (org.mockito.Matchers.anyString)2 DefaultMeasure (org.sonar.api.batch.sensor.measure.internal.DefaultMeasure)2 ReportPublisher (org.sonar.scanner.report.ReportPublisher)2 Date (java.util.Date)1 Before (org.junit.Before)1 InputComponent (org.sonar.api.batch.fs.InputComponent)1