Skip to content

Commit aa24e6c

Browse files
- Added fallback for macOS engine detection
1 parent 9ffaa3d commit aa24e6c

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/main/java/com/checkmarx/ast/wrapper/CxWrapper.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@
2929
import org.slf4j.Logger;
3030
import org.slf4j.LoggerFactory;
3131

32+
import java.io.File;
3233
import java.io.IOException;
3334
import java.nio.file.Files;
35+
import java.nio.file.Path;
36+
import java.nio.file.Paths;
3437
import java.util.*;
3538

3639
import static com.checkmarx.ast.wrapper.Execution.*;
@@ -426,15 +429,33 @@ private String checkEngine(String engineName, String osType ) throws CxExceptio
426429
arguments.add("/bin/sh");
427430
arguments.add("-c");
428431
arguments.add("command -v " + engineName);
432+
Exception lastException = null;
429433
try{
430434
enginePath= Execution.executeCommand((arguments), logger, line->line);
435+
return enginePath;
431436
} catch (CxException | IOException e) {
432-
throw new CxException(
433-
1,
434-
"Engine '" + engineName + "' is not installed or not found at /usr/local/bin)."
435-
);
437+
lastException = e;
436438
}
437-
return enginePath;
439+
Path dockerPath = Paths.get("/usr/local/bin/docker");
440+
Path podmanPath = Paths.get("/usr/local/bin/podman");
441+
if ("docker".equalsIgnoreCase(engineName)) {
442+
if (Files.isSymbolicLink(dockerPath)) {
443+
return Files.readSymbolicLink(dockerPath).toAbsolutePath().toString();
444+
}
445+
else { return dockerPath.toAbsolutePath().toString(); }
446+
}
447+
else if ("podman".equalsIgnoreCase(engineName)) {
448+
if (Files.exists(podmanPath)) {
449+
if (Files.isSymbolicLink(podmanPath)) {
450+
return Files.readSymbolicLink(podmanPath).toAbsolutePath().toString();
451+
}
452+
else{
453+
return podmanPath.toAbsolutePath().toString();
454+
}
455+
}
456+
}
457+
throw new CxException( 1, "Engine '" + engineName + "' is not installed or not symlinked to /usr/local/bin." );
458+
438459
case OS_WINDOWS:
439460
case OS_LINUX:
440461
arguments.add(engineName);

0 commit comments

Comments
 (0)