aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/main/java/org/sonar
diff options
context:
space:
mode:
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>2023-05-08 10:58:39 +0200
committersonartech <sonartech@sonarsource.com>2023-05-08 20:03:47 +0000
commitbc1cd787ad0d474bfec5614eb0ca8ab5b1d9fc3f (patch)
tree3c34297f64885b03c51fc49737b4440702ffa10a /sonar-scanner-engine/src/main/java/org/sonar
parent204d9b7f21fb8807c8a53756d1234a00023a9206 (diff)
downloadsonarqube-bc1cd787ad0d474bfec5614eb0ca8ab5b1d9fc3f.tar.gz
sonarqube-bc1cd787ad0d474bfec5614eb0ca8ab5b1d9fc3f.zip
SONAR-18210 not computing the whole file metadata when only status is needed.
Co-authored-by: Duarte Meneses <duarte.meneses@sonarsource.com>
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java7
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/MetadataGenerator.java4
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/StatusDetection.java16
3 files changed, 22 insertions, 5 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 e07679e003f..2d177d4edee 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
@@ -68,6 +68,7 @@ public class FileIndexer {
private final InputComponentStore componentStore;
private final SensorStrategy sensorStrategy;
private final LanguageDetection langDetection;
+ private final StatusDetection statusDetection;
private final ScmChangedFiles scmChangedFiles;
private boolean warnInclusionsAlreadyLogged;
@@ -78,7 +79,7 @@ public class FileIndexer {
public FileIndexer(DefaultInputProject project, ScannerComponentIdGenerator scannerComponentIdGenerator, InputComponentStore componentStore,
ProjectExclusionFilters projectExclusionFilters, ProjectCoverageAndDuplicationExclusions projectCoverageAndDuplicationExclusions, IssueExclusionsLoader issueExclusionsLoader,
MetadataGenerator metadataGenerator, SensorStrategy sensorStrategy, LanguageDetection languageDetection, AnalysisWarnings analysisWarnings, ScanProperties properties,
- InputFileFilter[] filters, ScmChangedFiles scmChangedFiles) {
+ InputFileFilter[] filters, ScmChangedFiles scmChangedFiles, StatusDetection statusDetection) {
this.project = project;
this.scannerComponentIdGenerator = scannerComponentIdGenerator;
this.componentStore = componentStore;
@@ -92,6 +93,7 @@ public class FileIndexer {
this.filters = filters;
this.projectExclusionFilters = projectExclusionFilters;
this.scmChangedFiles = scmChangedFiles;
+ this.statusDetection = statusDetection;
}
void indexFile(DefaultInputModule module, ModuleExclusionFilters moduleExclusionFilters, ModuleCoverageAndDuplicationExclusions moduleCoverageAndDuplicationExclusions,
@@ -145,7 +147,8 @@ public class FileIndexer {
scmChangedFiles.getOldRelativeFilePath(realAbsoluteFile)
);
- DefaultInputFile inputFile = new DefaultInputFile(indexedFile, f -> metadataGenerator.setMetadata(module.key(), f, module.getEncoding()));
+ DefaultInputFile inputFile = new DefaultInputFile(indexedFile, f -> metadataGenerator.setMetadata(module.key(), f, module.getEncoding()),
+ f -> f.setStatus(statusDetection.findStatusFromScm(f)));
if (language != null && language.isPublishAllFiles()) {
inputFile.setPublished(true);
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/MetadataGenerator.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/MetadataGenerator.java
index 627cb3adc17..562fcbe338a 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/MetadataGenerator.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/MetadataGenerator.java
@@ -63,7 +63,9 @@ public class MetadataGenerator {
inputFile.setCharset(charset);
Metadata metadata = fileMetadata.readMetadata(is, charset, inputFile.absolutePath(), exclusionsScanner.createCharHandlerFor(inputFile));
inputFile.setMetadata(metadata);
- inputFile.setStatus(statusDetection.status(moduleKeyWithBranch, inputFile, metadata.hash()));
+ if(!inputFile.isStatusSet()) {
+ inputFile.setStatus(statusDetection.status(moduleKeyWithBranch, inputFile, metadata.hash()));
+ }
LOG.debug("'{}' generated metadata{} with charset '{}'", inputFile, inputFile.type() == Type.TEST ? " as test " : "", charset);
} catch (Exception e) {
throw new IllegalStateException(e);
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/StatusDetection.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/StatusDetection.java
index 8c7d8af91da..65349df4120 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/StatusDetection.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/StatusDetection.java
@@ -41,13 +41,25 @@ public class StatusDetection {
this.scmChangedFiles = scmChangedFiles;
}
+ public boolean isScmStatusAvailable() {
+ return scmChangedFiles.isValid();
+ }
+
InputFile.Status status(String moduleKeyWithBranch, DefaultInputFile inputFile, String hash) {
- if (scmChangedFiles.isValid()) {
- return checkChangedWithScm(inputFile);
+ InputFile.Status statusFromScm = findStatusFromScm(inputFile);
+ if (statusFromScm != null) {
+ return statusFromScm;
}
return checkChangedWithProjectRepositories(moduleKeyWithBranch, inputFile, hash);
}
+ InputFile.Status findStatusFromScm(DefaultInputFile inputFile) {
+ if (isScmStatusAvailable()) {
+ return checkChangedWithScm(inputFile);
+ }
+ return null;
+ }
+
private InputFile.Status checkChangedWithProjectRepositories(String moduleKeyWithBranch, DefaultInputFile inputFile, String hash) {
FileData fileDataPerPath = projectRepositories.fileData(moduleKeyWithBranch, inputFile);
if (fileDataPerPath == null) {