Search in sources :

Example 36 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 NewActiveRule.Builder().setRuleKey(RuleKey.of("java", "S001")).setSeverity("BLOCKER").setParam("p1", "v1").setCreatedAt(1_000L).setUpdatedAt(2_000L).setQProfileKey("qp1").build();
    ActiveRules activeRules = new DefaultActiveRules(singletonList(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.getCreatedAt()).isEqualTo(1_000L);
        assertThat(reportAr.getUpdatedAt()).isEqualTo(2_000L);
        assertThat(reportAr.getQProfileKey()).isEqualTo("qp1");
        assertThat(reportAr.getParamsByKeyMap()).hasSize(1);
        assertThat(reportAr.getParamsByKeyMap().entrySet().iterator().next().getKey()).isEqualTo("p1");
        assertThat(reportAr.getParamsByKeyMap().entrySet().iterator().next().getValue()).isEqualTo("v1");
        assertThat(readIt.hasNext()).isFalse();
    }
}
Also used : ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) 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 37 with ScannerReportWriter

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

the class AnalysisContextReportPublisherTest method dumpServerSideProjectProps.

@Test
public void dumpServerSideProjectProps() throws Exception {
    logTester.setLevel(LoggerLevel.DEBUG);
    ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
    DefaultInputModule rootModule = new DefaultInputModule(ProjectDefinition.create().setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()).setProperty("sonar.projectKey", "foo"));
    when(store.allModules()).thenReturn(singletonList(rootModule));
    when(hierarchy.root()).thenReturn(rootModule);
    when(projectServerSettings.properties()).thenReturn(ImmutableMap.of(COM_FOO, "bar", SONAR_SKIP, "true"));
    publisher.init(writer);
    List<String> lines = FileUtils.readLines(writer.getFileStructure().analysisLog(), StandardCharsets.UTF_8);
    assertThat(lines).containsExactly("SonarQube plugins:", "Global server settings:", "Project server settings:", "  - com.foo=bar", "  - sonar.skip=true", "Project scanner properties:", "  - sonar.projectKey=foo");
}
Also used : DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) Test(org.junit.Test)

Example 38 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(singletonList(new PluginInfo("xoo").setName("Xoo").setVersion(Version.create("1.0"))));
    ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
    DefaultInputModule rootModule = new DefaultInputModule(ProjectDefinition.create().setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
    when(store.allModules()).thenReturn(singletonList(rootModule));
    when(hierarchy.root()).thenReturn(rootModule);
    publisher.init(writer);
    assertThat(writer.getFileStructure().analysisLog()).exists();
    assertThat(FileUtils.readFileToString(writer.getFileStructure().analysisLog(), StandardCharsets.UTF_8)).contains("Xoo 1.0 (xoo)");
    verifyZeroInteractions(system2);
}
Also used : DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) PluginInfo(org.sonar.core.platform.PluginInfo) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) Test(org.junit.Test)

Example 39 with ScannerReportWriter

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

the class AnalysisContextReportPublisherTest method shouldShortenModuleProperties.

@Test
public void shouldShortenModuleProperties() throws Exception {
    File baseDir = temp.newFolder();
    ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
    DefaultInputModule rootModule = new DefaultInputModule(ProjectDefinition.create().setBaseDir(baseDir).setWorkDir(temp.newFolder()).setProperty("sonar.projectKey", "foo").setProperty("sonar.projectBaseDir", baseDir.toString()).setProperty("sonar.aVeryLongProp", StringUtils.repeat("abcde", 1000)));
    when(store.allModules()).thenReturn(singletonList(rootModule));
    when(hierarchy.root()).thenReturn(rootModule);
    publisher.init(writer);
    assertThat(writer.getFileStructure().analysisLog()).exists();
    assertThat(FileUtils.readFileToString(writer.getFileStructure().analysisLog(), StandardCharsets.UTF_8)).containsSubsequence("sonar.aVeryLongProp=" + StringUtils.repeat("abcde", 199) + "ab...", "sonar.projectBaseDir=" + baseDir.toString(), "sonar.projectKey=foo");
}
Also used : DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) File(java.io.File) Test(org.junit.Test)

Example 40 with ScannerReportWriter

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

the class ComponentsPublisherTest method setUp.

@Before
public void setUp() throws IOException {
    branchConfiguration = mock(BranchConfiguration.class);
    outputDir = temp.newFolder();
    writer = new ScannerReportWriter(outputDir);
}
Also used : BranchConfiguration(org.sonar.scanner.scan.branch.BranchConfiguration) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) Before(org.junit.Before)

Aggregations

ScannerReportWriter (org.sonar.scanner.protocol.output.ScannerReportWriter)44 Test (org.junit.Test)25 File (java.io.File)21 ScannerReportReader (org.sonar.scanner.protocol.output.ScannerReportReader)16 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)14 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)11 Before (org.junit.Before)10 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)8 TextRange (org.sonar.api.batch.fs.TextRange)5 BranchConfiguration (org.sonar.scanner.scan.branch.BranchConfiguration)5 InputComponentStore (org.sonar.scanner.scan.filesystem.InputComponentStore)5 DefaultInputProject (org.sonar.api.batch.fs.internal.DefaultInputProject)4 InputFile (org.sonar.api.batch.fs.InputFile)3 DefaultMeasure (org.sonar.api.batch.sensor.measure.internal.DefaultMeasure)3 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 Path (java.nio.file.Path)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 StreamSupport (java.util.stream.StreamSupport)2