aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/main/java/org/sonar/scanner
diff options
context:
space:
mode:
authorKlaudio Sinani <klaudio.sinani@sonarsource.com>2022-10-26 15:16:57 +0200
committersonartech <sonartech@sonarsource.com>2022-10-28 20:03:23 +0000
commitce409098feab4f5f5ca8168cd995775e1fa32cbb (patch)
treea04c7bf89c2b7792dbed6895b6f3db0fd3171cb1 /sonar-scanner-engine/src/main/java/org/sonar/scanner
parent84dfd8b586f0c458d324e815f8b09ce3b395c044 (diff)
downloadsonarqube-ce409098feab4f5f5ca8168cd995775e1fa32cbb.tar.gz
sonarqube-ce409098feab4f5f5ca8168cd995775e1fa32cbb.zip
[NO-JIRA] Fix reported code smells & bugs
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar/scanner')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/ci/vendors/Jenkins.java10
1 files changed, 6 insertions, 4 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/ci/vendors/Jenkins.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/ci/vendors/Jenkins.java
index 50a89f72740..7721daadd6d 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/ci/vendors/Jenkins.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/ci/vendors/Jenkins.java
@@ -20,7 +20,9 @@
package org.sonar.scanner.ci.vendors;
import java.nio.file.Path;
+import java.util.Optional;
import org.apache.commons.lang.StringUtils;
+import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryBuilder;
@@ -99,10 +101,10 @@ public class Jenkins implements CiVendor {
String refName = "refs/remotes/origin/" + gitBranch;
try (Repository repo = builder.build()) {
- Ref ref = repo.exactRef(refName);
- if (ref != null) {
- return ref.getObjectId().getName();
- }
+ return Optional.ofNullable(repo.exactRef(refName))
+ .map(Ref::getObjectId)
+ .map(ObjectId::getName)
+ .orElse(null);
} catch (Exception e) {
LOG.debug("Couldn't find git sha1 in '{}': {}", refName, e.getMessage());
}