From bf22538c7ee89054b194715ceaa1d33e62c0da4c Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Tue, 7 Mar 2017 17:55:18 +0100 Subject: [PATCH] SONAR-8623 Index all source files, even the ones with no supported language --- .../scanner/report/MeasuresPublisher.java | 2 +- .../mediumtest/fs/FileSystemMediumTest.java | 33 ++++++++++++------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MeasuresPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MeasuresPublisher.java index 238880b78af..535708283d2 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MeasuresPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MeasuresPublisher.java @@ -82,7 +82,7 @@ public class MeasuresPublisher implements ReportPublisherStep { public void publish(ScannerReportWriter writer) { final ScannerReport.Measure.Builder builder = ScannerReport.Measure.newBuilder(); - for (final InputComponent c : componentStore.all()) { + for (final InputComponent c : componentStore.allFilesToPublish()) { DefaultInputComponent component = (DefaultInputComponent) c; // Recompute all coverage measures from line data to take into account the possible merge of several reports updateCoverageFromLineData(component); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java index 96e8df3f64d..a5670e4aeeb 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java @@ -20,6 +20,8 @@ package org.sonar.scanner.mediumtest.fs; import com.google.common.collect.ImmutableMap; + +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -215,6 +217,7 @@ public class FileSystemMediumTest { assertThat(logs.getAllAsString()).contains("2 files indexed"); assertThat(logs.getAllAsString()).contains("'src/sample.xoo' generated metadata"); assertThat(logs.getAllAsString()).doesNotContain("'src/sample.java' generated metadata"); + } @Test @@ -246,25 +249,33 @@ public class FileSystemMediumTest { public void dontPublishFilesWithoutDetectedLanguage() throws IOException { builder = createBuilder(); - File srcDir = new File(baseDir, "src"); - srcDir.mkdir(); + Path mainDir = baseDir.toPath().resolve("src").resolve("main"); + Files.createDirectories(mainDir); - File xooFile = new File(srcDir, "sample.xoo"); - FileUtils.write(xooFile, "Sample xoo\ncontent"); + Path testDir = baseDir.toPath().resolve("src").resolve("test"); + Files.createDirectories(testDir); + + Path testXooFile = testDir.resolve("sample.java"); + Files.write(testXooFile, "Sample xoo\ncontent".getBytes(StandardCharsets.UTF_8)); + + Path xooFile = mainDir.resolve("sample.xoo"); + Files.write(xooFile, "Sample xoo\ncontent".getBytes(StandardCharsets.UTF_8)); - File javaFile = new File(srcDir, "sample.java"); - FileUtils.write(javaFile, "Sample xoo\ncontent"); + Path javaFile = mainDir.resolve("sample.java"); + Files.write(javaFile, "Sample xoo\ncontent".getBytes(StandardCharsets.UTF_8)); TaskResult result = tester.newTask() .properties(builder - .put("sonar.sources", "src") + .put("sonar.sources", "src/main") + .put("sonar.tests", "src/test") .build()) .start(); - assertThat(logs.getAllAsString()).contains("2 files indexed"); - assertThat(logs.getAllAsString()).contains("'src/sample.xoo' generated metadata"); - assertThat(logs.getAllAsString()).doesNotContain("'src/sample.java' generated metadata"); - DefaultInputFile javaInputFile = (DefaultInputFile) result.inputFile("src/sample.java"); + assertThat(logs.getAllAsString()).contains("3 files indexed"); + assertThat(logs.getAllAsString()).contains("'src/main/sample.xoo' generated metadata"); + assertThat(logs.getAllAsString()).doesNotContain("'src/main/sample.java' generated metadata"); + assertThat(logs.getAllAsString()).doesNotContain("'src/test/sample.java' generated metadata"); + DefaultInputFile javaInputFile = (DefaultInputFile) result.inputFile("src/main/sample.java"); assertThat(result.getReportComponent(javaInputFile.key())).isNull(); } -- 2.39.5