diff options
author | Said Tahsin Dane <tasomaniac@gmail.com> | 2020-03-05 15:14:08 -0600 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2020-03-06 20:04:32 +0000 |
commit | ea65d148b2fc1b28b055dc58760b8966e406028f (patch) | |
tree | 4e1f47e74ae6fb0eed31b0a7d94ae3937371f60b /sonar-scanner-engine/src | |
parent | 6c9938e19c97a44e8cec9a33fa6f9b0acbc7609a (diff) | |
download | sonarqube-ea65d148b2fc1b28b055dc58760b8966e406028f.tar.gz sonarqube-ea65d148b2fc1b28b055dc58760b8966e406028f.zip |
Do not warn about a file out of basedir if file is not included
Diffstat (limited to 'sonar-scanner-engine/src')
2 files changed, 34 insertions, 12 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java index 2ccee4d1528..74dbe5bec00 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java @@ -98,14 +98,6 @@ public class FileIndexer { throws IOException { // get case of real file without resolving link Path realAbsoluteFile = sourceFile.toRealPath(LinkOption.NOFOLLOW_LINKS).toAbsolutePath().normalize(); - if (!realAbsoluteFile.startsWith(project.getBaseDir())) { - LOG.warn("File '{}' is ignored. It is not located in project basedir '{}'.", realAbsoluteFile.toAbsolutePath(), project.getBaseDir()); - return; - } - if (!realAbsoluteFile.startsWith(module.getBaseDir())) { - LOG.warn("File '{}' is ignored. It is not located in module basedir '{}'.", realAbsoluteFile.toAbsolutePath(), module.getBaseDir()); - return; - } Path projectRelativePath = project.getBaseDir().relativize(realAbsoluteFile); Path moduleRelativePath = module.getBaseDir().relativize(realAbsoluteFile); boolean included = evaluateInclusionsFilters(moduleExclusionFilters, realAbsoluteFile, projectRelativePath, moduleRelativePath, type); @@ -118,6 +110,14 @@ public class FileIndexer { exclusionCounter.increaseByPatternsCount(); return; } + if (!realAbsoluteFile.startsWith(project.getBaseDir())) { + LOG.warn("File '{}' is ignored. It is not located in project basedir '{}'.", realAbsoluteFile.toAbsolutePath(), project.getBaseDir()); + return; + } + if (!realAbsoluteFile.startsWith(module.getBaseDir())) { + LOG.warn("File '{}' is ignored. It is not located in module basedir '{}'.", realAbsoluteFile.toAbsolutePath(), module.getBaseDir()); + return; + } String language = langDetection.language(realAbsoluteFile, projectRelativePath); 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 bb62d3454e9..7d2bb6cc9fb 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 @@ -167,8 +167,7 @@ public class FileSystemMediumTest { assertThat(logTester.logs()).contains("2 files indexed"); assertThat(logTester.logs()).contains("'src/sample.xoo' generated metadata with charset 'UTF-8'"); - assertThat(logTester.logs().stream().collect(joining("\n"))).doesNotContain("'src/sample.java' generated metadata"); - + assertThat(String.join("\n", logTester.logs())).doesNotContain("'src/sample.java' generated metadata"); } @Test @@ -225,8 +224,8 @@ public class FileSystemMediumTest { assertThat(logTester.logs()).contains("3 files indexed"); assertThat(logTester.logs()).contains("'src/main/sample.xoo' generated metadata with charset 'UTF-8'"); - assertThat(logTester.logs().stream().collect(joining("\n"))).doesNotContain("'src/main/sample.java' generated metadata"); - assertThat(logTester.logs().stream().collect(joining("\n"))).doesNotContain("'src/test/sample.java' generated metadata"); + assertThat(String.join("\n", logTester.logs())).doesNotContain("'src/main/sample.java' generated metadata"); + assertThat(String.join("\n", logTester.logs())).doesNotContain("'src/test/sample.java' generated metadata"); DefaultInputFile javaInputFile = (DefaultInputFile) result.inputFile("src/main/sample.java"); thrown.expect(IllegalStateException.class); @@ -1030,6 +1029,29 @@ public class FileSystemMediumTest { } @Test + public void dont_log_warn_about_files_out_of_basedir_if_they_arent_included() throws IOException { + File srcDir = new File(baseDir, "src"); + srcDir.mkdir(); + + File xooFile = new File(srcDir, "sample1.xoo"); + FileUtils.write(xooFile, "Sample xoo\ncontent", StandardCharsets.UTF_8); + + File outsideBaseDir = temp.newFolder().getCanonicalFile(); + File xooFile2 = new File(outsideBaseDir, "another.xoo"); + FileUtils.write(xooFile2, "Sample xoo 2\ncontent", StandardCharsets.UTF_8); + + AnalysisResult result = tester.newAnalysis() + .properties(builder + .put("sonar.sources", "src," + PathUtils.canonicalPath(xooFile2)) + .put("sonar.inclusions", "**/sample1.xoo") + .build()) + .execute(); + + assertThat(result.inputFiles()).hasSize(1); + assertThat(logTester.logs(LoggerLevel.WARN)).doesNotContain("File '" + xooFile2.getAbsolutePath() + "' is ignored. It is not located in project basedir '" + baseDir + "'."); + } + + @Test public void ignore_files_outside_module_basedir() throws IOException { File moduleA = new File(baseDir, "moduleA"); moduleA.mkdir(); |