|
29 | 29 | import org.slf4j.Logger; |
30 | 30 | import org.slf4j.LoggerFactory; |
31 | 31 |
|
| 32 | +import java.io.File; |
32 | 33 | import java.io.IOException; |
33 | 34 | import java.nio.file.Files; |
| 35 | +import java.nio.file.Path; |
| 36 | +import java.nio.file.Paths; |
34 | 37 | import java.util.*; |
35 | 38 |
|
36 | 39 | import static com.checkmarx.ast.wrapper.Execution.*; |
@@ -426,15 +429,33 @@ private String checkEngine(String engineName, String osType ) throws CxExceptio |
426 | 429 | arguments.add("/bin/sh"); |
427 | 430 | arguments.add("-c"); |
428 | 431 | arguments.add("command -v " + engineName); |
| 432 | + Exception lastException = null; |
429 | 433 | try{ |
430 | 434 | enginePath= Execution.executeCommand((arguments), logger, line->line); |
| 435 | + return enginePath; |
431 | 436 | } 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; |
436 | 438 | } |
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 | + |
438 | 459 | case OS_WINDOWS: |
439 | 460 | case OS_LINUX: |
440 | 461 | arguments.add(engineName); |
|
0 commit comments