use of org.sonar.scanner.protocol.output.ScannerReportWriter in project sonarqube by SonarSource.
the class AnalysisContextReportPublisherTest method shouldNotDumpInIssuesMode.
@Test
public void shouldNotDumpInIssuesMode() throws Exception {
when(analysisMode.isIssues()).thenReturn(true);
ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
publisher.init(writer);
publisher.dumpModuleSettings(ProjectDefinition.create().setProperty("sonar.projectKey", "foo"));
assertThat(writer.getFileStructure().analysisLog()).doesNotExist();
}
use of org.sonar.scanner.protocol.output.ScannerReportWriter in project sonarqube by SonarSource.
the class CoveragePublisherTest method publishCoverage.
@Test
public void publishCoverage() throws Exception {
DefaultMeasure<String> utLineHits = new DefaultMeasure<String>().forMetric(CoreMetrics.COVERAGE_LINE_HITS_DATA).withValue("2=1;3=1;5=0;6=3");
when(measureCache.byMetric("foo:src/Foo.php", CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY)).thenReturn((DefaultMeasure) utLineHits);
DefaultMeasure<String> conditionsByLine = new DefaultMeasure<String>().forMetric(CoreMetrics.CONDITIONS_BY_LINE).withValue("3=4");
when(measureCache.byMetric("foo:src/Foo.php", CoreMetrics.CONDITIONS_BY_LINE_KEY)).thenReturn((DefaultMeasure) conditionsByLine);
DefaultMeasure<String> coveredConditionsByUts = new DefaultMeasure<String>().forMetric(CoreMetrics.COVERED_CONDITIONS_BY_LINE).withValue("3=2");
when(measureCache.byMetric("foo:src/Foo.php", CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY)).thenReturn((DefaultMeasure) coveredConditionsByUts);
File outputDir = temp.newFolder();
ScannerReportWriter writer = new ScannerReportWriter(outputDir);
publisher.publish(writer);
try (CloseableIterator<LineCoverage> it = new ScannerReportReader(outputDir).readComponentCoverage(inputFile.batchId())) {
assertThat(it.next()).isEqualTo(LineCoverage.newBuilder().setLine(2).setHits(true).build());
assertThat(it.next()).isEqualTo(LineCoverage.newBuilder().setLine(3).setHits(true).setConditions(4).setCoveredConditions(2).build());
assertThat(it.next()).isEqualTo(LineCoverage.newBuilder().setLine(5).setHits(false).build());
}
}
use of org.sonar.scanner.protocol.output.ScannerReportWriter in project sonarqube by SonarSource.
the class MeasuresPublisherTest method prepare.
@Before
public void prepare() throws IOException {
String moduleKey = "foo";
inputModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder());
inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setPublish(true).build();
InputComponentStore componentCache = new InputComponentStore(new PathResolver());
componentCache.put(inputModule);
componentCache.put(inputFile);
measureCache = mock(MeasureCache.class);
when(measureCache.byComponentKey(anyString())).thenReturn(Collections.<DefaultMeasure<?>>emptyList());
publisher = new MeasuresPublisher(componentCache, measureCache, mock(TestPlanBuilder.class));
outputDir = temp.newFolder();
writer = new ScannerReportWriter(outputDir);
}
use of org.sonar.scanner.protocol.output.ScannerReportWriter in project sonarqube by SonarSource.
the class MetadataPublisherTest method write_metadata.
@Test
public void write_metadata() throws Exception {
settings.setProperty(CoreProperties.CPD_CROSS_PROJECT, "true");
Date date = new Date();
when(qProfiles.findAll()).thenReturn(asList(new QProfile().setKey("q1").setName("Q1").setLanguage("java").setRulesUpdatedAt(date)));
File outputDir = temp.newFolder();
ScannerReportWriter writer = new ScannerReportWriter(outputDir);
underTest.publish(writer);
ScannerReportReader reader = new ScannerReportReader(outputDir);
ScannerReport.Metadata metadata = reader.readMetadata();
assertThat(metadata.getAnalysisDate()).isEqualTo(1234567L);
assertThat(metadata.getProjectKey()).isEqualTo("foo");
assertThat(metadata.getProjectKey()).isEqualTo("foo");
assertThat(metadata.getCrossProjectDuplicationActivated()).isTrue();
assertThat(metadata.getQprofilesPerLanguage()).containsOnly(entry("java", org.sonar.scanner.protocol.output.ScannerReport.Metadata.QProfile.newBuilder().setKey("q1").setName("Q1").setLanguage("java").setRulesUpdatedAt(date.getTime()).build()));
}
use of org.sonar.scanner.protocol.output.ScannerReportWriter in project sonarqube by SonarSource.
the class MetadataPublisherTest method write_project_branch.
@Test
public void write_project_branch() throws Exception {
settings.setProperty(CoreProperties.CPD_CROSS_PROJECT, "true");
settings.setProperty(CoreProperties.PROJECT_BRANCH_PROPERTY, "myBranch");
projectDef.properties().put(CoreProperties.PROJECT_BRANCH_PROPERTY, "myBranch");
projectDef.setKey("foo");
File outputDir = temp.newFolder();
ScannerReportWriter writer = new ScannerReportWriter(outputDir);
underTest.publish(writer);
ScannerReportReader reader = new ScannerReportReader(outputDir);
ScannerReport.Metadata metadata = reader.readMetadata();
assertThat(metadata.getAnalysisDate()).isEqualTo(1234567L);
assertThat(metadata.getProjectKey()).isEqualTo("foo");
assertThat(metadata.getBranch()).isEqualTo("myBranch");
// Cross project duplication disabled on branches
assertThat(metadata.getCrossProjectDuplicationActivated()).isFalse();
}
Aggregations