aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api-impl
diff options
context:
space:
mode:
authorKlaudio Sinani <klaudio.sinani@sonarsource.com>2022-08-10 13:37:31 +0200
committersonartech <sonartech@sonarsource.com>2022-10-26 20:03:10 +0000
commit84f0224faf4e45999e793f8d06b66c065dfc6399 (patch)
treebeb055ee1d93aa0966ca01d8cbed088202ae59ef /sonar-plugin-api-impl
parent30e6c8d94430d7087f14196032d77e3034262e83 (diff)
downloadsonarqube-84f0224faf4e45999e793f8d06b66c065dfc6399.tar.gz
sonarqube-84f0224faf4e45999e793f8d06b66c065dfc6399.zip
SONAR-13579 Detect files moves in Pull Request scope
SONAR-13579 Get database files from target branch instead of snapshot SONAR-13579 Store old relative file path to `FileAttributes` class
Diffstat (limited to 'sonar-plugin-api-impl')
-rw-r--r--sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/DefaultIndexedFile.java23
-rw-r--r--sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java9
2 files changed, 29 insertions, 3 deletions
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/DefaultIndexedFile.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/DefaultIndexedFile.java
index e18b00ca1f9..be062dec668 100644
--- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/DefaultIndexedFile.java
+++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/DefaultIndexedFile.java
@@ -25,6 +25,7 @@ import java.io.InputStream;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
@@ -38,7 +39,7 @@ import org.sonar.api.utils.PathUtils;
*/
@Immutable
public class DefaultIndexedFile extends DefaultInputComponent implements IndexedFile {
- private static AtomicInteger intGenerator = new AtomicInteger(0);
+ private static final AtomicInteger intGenerator = new AtomicInteger(0);
private final String projectRelativePath;
private final String moduleRelativePath;
@@ -47,17 +48,23 @@ public class DefaultIndexedFile extends DefaultInputComponent implements Indexed
private final Type type;
private final Path absolutePath;
private final SensorStrategy sensorStrategy;
+ private final String oldFilePath;
/**
* Testing purposes only!
*/
public DefaultIndexedFile(String projectKey, Path baseDir, String relativePath, @Nullable String language) {
this(baseDir.resolve(relativePath), projectKey, relativePath, relativePath, Type.MAIN, language, intGenerator.getAndIncrement(),
- new SensorStrategy());
+ new SensorStrategy(), null);
}
public DefaultIndexedFile(Path absolutePath, String projectKey, String projectRelativePath, String moduleRelativePath, Type type, @Nullable String language, int batchId,
SensorStrategy sensorStrategy) {
+ this(absolutePath, projectKey, projectRelativePath, moduleRelativePath, type, language, batchId, sensorStrategy, null);
+ }
+
+ public DefaultIndexedFile(Path absolutePath, String projectKey, String projectRelativePath, String moduleRelativePath, Type type, @Nullable String language, int batchId,
+ SensorStrategy sensorStrategy, @Nullable String oldFilePath) {
super(batchId);
this.projectKey = projectKey;
this.projectRelativePath = PathUtils.sanitize(projectRelativePath);
@@ -66,6 +73,7 @@ public class DefaultIndexedFile extends DefaultInputComponent implements Indexed
this.language = language;
this.sensorStrategy = sensorStrategy;
this.absolutePath = absolutePath;
+ this.oldFilePath = oldFilePath;
}
@Override
@@ -96,6 +104,15 @@ public class DefaultIndexedFile extends DefaultInputComponent implements Indexed
return absolutePath;
}
+ @CheckForNull
+ public String oldPath() {
+ return oldFilePath;
+ }
+
+ public boolean isMovedFile() {
+ return Objects.nonNull(this.oldPath());
+ }
+
@Override
public InputStream inputStream() throws IOException {
return Files.newInputStream(path());
@@ -117,7 +134,7 @@ public class DefaultIndexedFile extends DefaultInputComponent implements Indexed
*/
@Override
public String key() {
- return new StringBuilder().append(projectKey).append(":").append(projectRelativePath).toString();
+ return String.join(":", projectKey, projectRelativePath);
}
@Override
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
index 382461fbc5a..fe4c116bebd 100644
--- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
+++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
@@ -177,6 +177,15 @@ public class DefaultInputFile extends DefaultInputComponent implements InputFile
return indexedFile.absolutePath();
}
+ @CheckForNull
+ public String oldPath() {
+ return indexedFile.oldPath();
+ }
+
+ public boolean isMovedFile() {
+ return indexedFile.isMovedFile();
+ }
+
@Override
public File file() {
return indexedFile.file();