aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api-impl
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2023-06-09 11:30:21 +0200
committersonartech <sonartech@sonarsource.com>2023-06-12 20:02:49 +0000
commit713f0434372e85f5273ab7b544ca616a0f379f44 (patch)
tree00d5c73d5d3afca0bff9e8c253c61b32c6d809f0 /sonar-plugin-api-impl
parenta86f840b160eeeca5c712689321cf4b205da8256 (diff)
downloadsonarqube-713f0434372e85f5273ab7b544ca616a0f379f44.tar.gz
sonarqube-713f0434372e85f5273ab7b544ca616a0f379f44.zip
SONAR-19532 PythonXUnitSensor takes too long due to non-optimized file query
Diffstat (limited to 'sonar-plugin-api-impl')
-rw-r--r--sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/DefaultFilePredicates.java5
-rw-r--r--sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/IsPredicate.java43
-rw-r--r--sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/predicates/DefaultFilePredicatesTest.java3
3 files changed, 5 insertions, 46 deletions
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/DefaultFilePredicates.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/DefaultFilePredicates.java
index 37345e7d455..bc0a5dc87fb 100644
--- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/DefaultFilePredicates.java
+++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/DefaultFilePredicates.java
@@ -133,7 +133,10 @@ public class DefaultFilePredicates implements FilePredicates {
@Override
public FilePredicate is(File ioFile) {
- return new IsPredicate(ioFile.toPath());
+ if (ioFile.isAbsolute()) {
+ return hasAbsolutePath(ioFile.getAbsolutePath());
+ }
+ return hasRelativePath(ioFile.getPath());
}
@Override
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/IsPredicate.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/IsPredicate.java
deleted file mode 100644
index 80b861e40f1..00000000000
--- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/IsPredicate.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.api.batch.fs.internal.predicates;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import org.sonar.api.batch.fs.InputFile;
-
-public class IsPredicate extends AbstractFilePredicate {
-
- private final Path path;
-
- public IsPredicate(Path path) {
- this.path = path;
- }
-
- @Override
- public boolean apply(InputFile inputFile) {
- try {
- return Files.isSameFile(path, inputFile.path());
- } catch (IOException e) {
- return false;
- }
- }
-}
diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/predicates/DefaultFilePredicatesTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/predicates/DefaultFilePredicatesTest.java
index a9c81f2682c..17c6a424915 100644
--- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/predicates/DefaultFilePredicatesTest.java
+++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/predicates/DefaultFilePredicatesTest.java
@@ -153,8 +153,7 @@ public class DefaultFilePredicatesTest {
Files.touch(javaFile.file());
// relative file
- Path workingDir = Paths.get(System.getProperty("user.dir"));
- Path relativePath = workingDir.relativize(javaFile.path());
+ Path relativePath = moduleBasePath.relativize(javaFile.path());
assertThat(predicates.is(relativePath.toFile()).apply(javaFile)).isTrue();
// absolute file