aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/main/java/org/sonar/scanner
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar/scanner')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java13
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ScanProperties.java5
2 files changed, 17 insertions, 1 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java
index 9bf40f4a94e..dc79f7262f4 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java
@@ -23,6 +23,7 @@ import java.io.File;
import java.nio.file.Path;
import java.util.LinkedList;
import java.util.Map.Entry;
+import java.util.Optional;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
@@ -145,13 +146,23 @@ public class MetadataPublisher implements ReportPublisherStep {
LOG.debug(e.getMessage());
}
try {
- builder.setScmRevisionId(scmProvider.revisionId(projectBasedir));
+ computeScmRevision().ifPresent(builder::setScmRevisionId);
} catch (UnsupportedOperationException e) {
LOG.debug(e.getMessage());
}
}
}
+ private Optional<String> computeScmRevision() {
+ Optional<String> scmRevision = properties.getScmRevision();
+ ScmProvider scmProvider = scmConfiguration.provider();
+ if (!scmRevision.isPresent() && scmProvider != null) {
+ scmRevision = Optional.ofNullable(scmProvider.revisionId(moduleHierarchy.root().getBaseDir()));
+ }
+
+ return scmRevision;
+ }
+
private void addBranchInformation(ScannerReport.Metadata.Builder builder) {
builder.setBranchName(branchConfiguration.branchName());
BranchType branchType = toProtobufBranchType(branchConfiguration.branchType());
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ScanProperties.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ScanProperties.java
index 1da90cf6bf7..36fd9b5d41e 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ScanProperties.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ScanProperties.java
@@ -40,6 +40,7 @@ public class ScanProperties {
public static final String SONAR_REPORT_EXPORT_PATH = "sonar.report.export.path";
public static final String PRELOAD_FILE_METADATA_KEY = "sonar.preloadFileMetadata";
public static final String FORCE_RELOAD_KEY = "sonar.scm.forceReloadAll";
+ public static final String SCM_REVISION = "sonar.scm.revision";
private final Configuration configuration;
private final DefaultInputProject project;
@@ -78,6 +79,10 @@ public class ScanProperties {
}
}
+ public Optional<String> getScmRevision() {
+ return configuration.get(SCM_REVISION);
+ }
+
/**
* This should be called in the beginning of the analysis to fail fast
*/