Search in sources :

Example 31 with ScannerReportWriter

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

the class AnalysisContextReportPublisherTest method dumpServerSideModuleProps.

@Test
public void dumpServerSideModuleProps() throws Exception {
    logTester.setLevel(LoggerLevel.DEBUG);
    ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
    publisher.init(writer);
    when(projectRepos.moduleExists("foo")).thenReturn(true);
    when(projectRepos.settings("foo")).thenReturn(ImmutableMap.of(COM_FOO, "bar", SONAR_SKIP, "true"));
    publisher.dumpModuleSettings(ProjectDefinition.create().setProperty("sonar.projectKey", "foo"));
    String content = FileUtils.readFileToString(writer.getFileStructure().analysisLog());
    assertThat(content).doesNotContain(COM_FOO);
    assertThat(content).containsOnlyOnce(SONAR_SKIP);
}
Also used : ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) Test(org.junit.Test)

Example 32 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 33 with ScannerReportWriter

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

the class BatchReportReaderImplTest method setUp.

@Before
public void setUp() {
    BatchReportDirectoryHolder holder = new ImmutableBatchReportDirectoryHolder(tempFolder.newDir());
    underTest = new BatchReportReaderImpl(holder);
    writer = new ScannerReportWriter(holder.getDirectory());
}
Also used : ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) Before(org.junit.Before)

Example 34 with ScannerReportWriter

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

the class ChangedLinesPublisher method writeChangedLines.

private int writeChangedLines(ScmProvider provider, ScannerReportWriter writer, String targetScmBranch) {
    Path rootBaseDir = project.getBaseDir();
    Map<Path, DefaultInputFile> changedFiles = StreamSupport.stream(inputComponentStore.allChangedFilesToPublish().spliterator(), false).collect(Collectors.toMap(DefaultInputFile::path, f -> f));
    Map<Path, Set<Integer>> pathSetMap = provider.branchChangedLines(targetScmBranch, rootBaseDir, changedFiles.keySet());
    int count = 0;
    if (pathSetMap == null) {
        // the compute engine will use SCM dates to estimate which lines are new
        return count;
    }
    for (Map.Entry<Path, DefaultInputFile> e : changedFiles.entrySet()) {
        DefaultInputFile inputFile = e.getValue();
        Set<Integer> changedLines = pathSetMap.get(e.getKey());
        if (changedLines == null) {
            if (branchConfiguration.isPullRequest()) {
                LOG.warn("File '{}' was detected as changed but without having changed lines", e.getKey().toAbsolutePath());
            }
            // assume that no line was changed
            writeChangedLines(writer, e.getValue().scannerId(), Collections.emptySet());
        } else {
            // detect unchanged last empty line
            if (changedLines.size() + 1 == inputFile.lines() && inputFile.lineLength(inputFile.lines()) == 0) {
                changedLines.add(inputFile.lines());
            }
            count++;
            writeChangedLines(writer, e.getValue().scannerId(), changedLines);
        }
    }
    return count;
}
Also used : Path(java.nio.file.Path) BranchConfiguration(org.sonar.scanner.scan.branch.BranchConfiguration) ScmConfiguration(org.sonar.scanner.scm.ScmConfiguration) Optional.empty(java.util.Optional.empty) ScmProvider(org.sonar.api.batch.scm.ScmProvider) InputComponentStore(org.sonar.scanner.scan.filesystem.InputComponentStore) Profiler(org.sonar.api.utils.log.Profiler) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) Set(java.util.Set) ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) Collectors(java.util.stream.Collectors) DefaultInputProject(org.sonar.api.batch.fs.internal.DefaultInputProject) ScannerUtils(org.sonar.api.impl.utils.ScannerUtils) Loggers(org.sonar.api.utils.log.Loggers) Map(java.util.Map) Optional(java.util.Optional) StreamSupport(java.util.stream.StreamSupport) ReferenceBranchSupplier(org.sonar.scanner.repository.ReferenceBranchSupplier) Path(java.nio.file.Path) Collections(java.util.Collections) Logger(org.sonar.api.utils.log.Logger) Set(java.util.Set) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) Map(java.util.Map)

Example 35 with ScannerReportWriter

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

the class DefaultSensorStorageTest method prepare.

@Before
public void prepare() throws Exception {
    MetricFinder metricFinder = mock(MetricFinder.class);
    when(metricFinder.<Integer>findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC);
    when(metricFinder.<String>findByKey(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION);
    when(metricFinder.<Integer>findByKey(CoreMetrics.LINES_TO_COVER_KEY)).thenReturn(CoreMetrics.LINES_TO_COVER);
    settings = new MapSettings();
    moduleIssues = mock(IssuePublisher.class);
    reportPublisher = mock(ReportPublisher.class);
    final File reportDir = temp.newFolder();
    reportWriter = new ScannerReportWriter(reportDir);
    reportReader = new ScannerReportReader(reportDir);
    when(reportPublisher.getWriter()).thenReturn(reportWriter);
    when(reportPublisher.getReader()).thenReturn(reportReader);
    branchConfiguration = mock(BranchConfiguration.class);
    underTest = new DefaultSensorStorage(metricFinder, moduleIssues, settings.asConfig(), reportPublisher, mock(SonarCpdBlockIndex.class), contextPropertiesCache, new ScannerMetrics(), branchConfiguration);
    project = new DefaultInputProject(ProjectDefinition.create().setKey("foo").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
}
Also used : BranchConfiguration(org.sonar.scanner.scan.branch.BranchConfiguration) MetricFinder(org.sonar.api.batch.measure.MetricFinder) ScannerMetrics(org.sonar.core.metric.ScannerMetrics) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) ReportPublisher(org.sonar.scanner.report.ReportPublisher) ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) DefaultInputProject(org.sonar.api.batch.fs.internal.DefaultInputProject) MapSettings(org.sonar.api.config.internal.MapSettings) IssuePublisher(org.sonar.scanner.issue.IssuePublisher) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) 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