aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/main
diff options
context:
space:
mode:
authorantoine.vinot <antoine.vinot@sonarsource.com>2024-12-09 11:37:51 +0100
committerSteve Marion <steve.marion@sonarsource.com>2024-12-18 11:13:22 +0100
commita8e00f65e81244bff1a481608d7d1db3d486b635 (patch)
tree1119f3c65e99dea1403b1edf3b1fd7a47d33f485 /sonar-scanner-engine/src/main
parent6397704e429c7c31d6a595d5afcb71d6f121cb60 (diff)
downloadsonarqube-a8e00f65e81244bff1a481608d7d1db3d486b635.tar.gz
sonarqube-a8e00f65e81244bff1a481608d7d1db3d486b635.zip
SONAR-17640 Do not visit directories when all the files will be excluded
Diffstat (limited to 'sonar-scanner-engine/src/main')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/AbstractExclusionFilters.java21
1 files changed, 19 insertions, 2 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/AbstractExclusionFilters.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/AbstractExclusionFilters.java
index 235f297fc69..48ef929337b 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/AbstractExclusionFilters.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/AbstractExclusionFilters.java
@@ -34,6 +34,7 @@ import org.sonar.api.batch.fs.internal.PathPattern;
import org.sonar.api.notifications.AnalysisWarnings;
import static java.lang.String.format;
+import static org.apache.commons.lang3.StringUtils.removeEnd;
import static org.sonar.api.CoreProperties.PROJECT_TESTS_EXCLUSIONS_PROPERTY;
import static org.sonar.api.CoreProperties.PROJECT_TESTS_INCLUSIONS_PROPERTY;
import static org.sonar.api.CoreProperties.PROJECT_TEST_EXCLUSIONS_PROPERTY;
@@ -234,14 +235,30 @@ public abstract class AbstractExclusionFilters {
* @return True if the file should be excluded, false otherwise.
*/
public boolean isExcludedAsParentDirectoryOfExcludedChildren(Path absolutePath, Path relativePath, Path baseDir, InputFile.Type type) {
+ return isExcludedFromExclusionProperty(absolutePath, relativePath, baseDir, type)
+ || isExcludedFromInclusionProperty(absolutePath, relativePath, baseDir, type);
+ }
+
+ private boolean isExcludedFromExclusionProperty(Path absolutePath, Path relativePath, Path baseDir, InputFile.Type type) {
PathPattern[] exclusionPatterns = InputFile.Type.MAIN == type ? mainExclusionsPattern : testExclusionsPattern;
+ return exclusionPatterns.length > 0 && matchPathPattern(absolutePath, relativePath, baseDir, exclusionPatterns);
+ }
+
+ private boolean isExcludedFromInclusionProperty(Path absolutePath, Path relativePath, Path baseDir, InputFile.Type type) {
+ PathPattern[] inclusionPatterns = InputFile.Type.MAIN == type ? mainInclusionsPattern : testInclusionsPattern;
+ return inclusionPatterns.length > 0 && !matchPathPattern(absolutePath, relativePath, baseDir, inclusionPatterns);
+ }
+
+ private boolean matchPathPattern(Path absolutePath, Path relativePath, Path baseDir, PathPattern[] exclusionPatterns) {
return Stream.of(exclusionPatterns)
.map(PathPattern::toString)
- .filter(ps -> ps.endsWith("/**/*"))
- .map(ps -> ps.substring(0, ps.length() - 5))
+ .filter(ps -> ps.endsWith("/**/*") || ps.endsWith("/**"))
+ .map(ps -> removeEnd(ps, "/**/*"))
+ .map(ps -> removeEnd(ps, "/**"))
.map(baseDir::resolve)
.anyMatch(exclusionRootPath -> absolutePath.startsWith(exclusionRootPath)
|| PathPattern.create(exclusionRootPath.toString()).match(absolutePath, relativePath));
}
+
}