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();
}
}
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");
}
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);
}
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");
}
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);
}
Aggregations