diff options
author | Steve Marion <steve.marion@sonarsource.com> | 2023-09-20 10:23:36 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-09-20 20:02:50 +0000 |
commit | 1237a2eb3ab3a94d78cbbb223126278b7bee1fc1 (patch) | |
tree | ddf322833caf54457a225e809fcbc9416ba7f2b6 /server/sonar-webserver-core/src/main | |
parent | e96a172a7e74905d3d75c9e6e52fb5fd32b377aa (diff) | |
download | sonarqube-1237a2eb3ab3a94d78cbbb223126278b7bee1fc1.tar.gz sonarqube-1237a2eb3ab3a94d78cbbb223126278b7bee1fc1.zip |
NO-JIRA make test independent of running container
Diffstat (limited to 'server/sonar-webserver-core/src/main')
-rw-r--r-- | server/sonar-webserver-core/src/main/java/org/sonar/server/platform/ContainerSupportImpl.java | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/ContainerSupportImpl.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/ContainerSupportImpl.java index e6d81ac1a9b..fe54544fd97 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/ContainerSupportImpl.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/ContainerSupportImpl.java @@ -81,7 +81,7 @@ public class ContainerSupportImpl implements ContainerSupport { } private boolean isDocker() { - return executeCommand(MOUNT_GREP_COMMAND).contains("/docker") && paths2.exists("/.dockerenv"); + return getMountOverlays().contains("/docker") && paths2.exists("/.dockerenv"); } private boolean isPodman() { @@ -89,11 +89,11 @@ public class ContainerSupportImpl implements ContainerSupport { } private boolean isBuildah() { - return paths2.exists(CONTAINER_FILE_PATH) && executeCommand(CAT_COMMAND).contains("engine=\"buildah-"); + return paths2.exists(CONTAINER_FILE_PATH) && readContainerenvFile().contains("engine=\"buildah-"); } private boolean isContainerd() { - return executeCommand(MOUNT_GREP_COMMAND).contains("/containerd"); + return getMountOverlays().contains("/containerd"); } private boolean isGeneralContainer() { @@ -101,7 +101,16 @@ public class ContainerSupportImpl implements ContainerSupport { } @VisibleForTesting - String executeCommand(String[] command) { + String getMountOverlays() { + return executeCommand(MOUNT_GREP_COMMAND); + } + + @VisibleForTesting + String readContainerenvFile() { + return executeCommand(CAT_COMMAND); + } + + private static String executeCommand(String[] command) { try { Process process = new ProcessBuilder().command(command).start(); try (Scanner scanner = new Scanner(process.getInputStream(), UTF_8)) { |