Search in sources :

Example 16 with ScannerReportWriter

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

the class ReportIteratorTest method setUp.

@Before
public void setUp() throws Exception {
    File dir = temp.newFolder();
    ScannerReportWriter writer = new ScannerReportWriter(dir);
    writer.writeComponentCoverage(1, newArrayList(ScannerReport.LineCoverage.newBuilder().setLine(1).build()));
    file = new FileStructure(dir).fileFor(FileStructure.Domain.COVERAGES, 1);
}
Also used : FileStructure(org.sonar.scanner.protocol.output.FileStructure) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) File(java.io.File) Before(org.junit.Before)

Example 17 with ScannerReportWriter

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

the class ReportPublisher method start.

@Override
public void start() {
    reportDir = new File(projectReactor.getRoot().getWorkDir(), "batch-report");
    writer = new ScannerReportWriter(reportDir);
    contextPublisher.init(writer);
    if (!analysisMode.isIssues() && !analysisMode.isMediumTest()) {
        String publicUrl = server.getPublicRootUrl();
        if (HttpUrl.parse(publicUrl) == null) {
            throw MessageException.of("Failed to parse public URL set in SonarQube server: " + publicUrl);
        }
    }
}
Also used : ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) File(java.io.File)

Example 18 with ScannerReportWriter

use of org.sonar.scanner.protocol.output.ScannerReportWriter 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 19 with ScannerReportWriter

use of org.sonar.scanner.protocol.output.ScannerReportWriter 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 20 with ScannerReportWriter

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

the class AnalysisContextReportPublisherTest method shouldOnlyDumpPluginsByDefault.

@Test
public void shouldOnlyDumpPluginsByDefault() throws Exception {
    when(pluginRepo.getPluginInfos()).thenReturn(Arrays.asList(new PluginInfo("xoo").setName("Xoo").setVersion(Version.create("1.0"))));
    ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
    publisher.init(writer);
    assertThat(writer.getFileStructure().analysisLog()).exists();
    assertThat(FileUtils.readFileToString(writer.getFileStructure().analysisLog())).contains("Xoo 1.0 (xoo)");
    verifyZeroInteractions(system2);
}
Also used : PluginInfo(org.sonar.core.platform.PluginInfo) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) Test(org.junit.Test)

Aggregations

ScannerReportWriter (org.sonar.scanner.protocol.output.ScannerReportWriter)24 Test (org.junit.Test)14 File (java.io.File)9 Before (org.junit.Before)7 ScannerReportReader (org.sonar.scanner.protocol.output.ScannerReportReader)6 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)5 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)4 PathResolver (org.sonar.api.scan.filesystem.PathResolver)3 InputComponentStore (org.sonar.scanner.scan.filesystem.InputComponentStore)3 Matchers.anyString (org.mockito.Matchers.anyString)2 InputFile (org.sonar.api.batch.fs.InputFile)2 TextRange (org.sonar.api.batch.fs.TextRange)2 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)2 MapSettings (org.sonar.api.config.MapSettings)2 ReportPublisher (org.sonar.scanner.report.ReportPublisher)2 MeasureCache (org.sonar.scanner.scan.measure.MeasureCache)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)1