Skip to content

Commit 7609d9f

Browse files
- Added check for engine verification in path
1 parent 0bd805c commit 7609d9f

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -420,19 +420,40 @@ public String checkEngineExist(@NonNull String engineName) throws CxException, I
420420
private String checkEngine(String engineName, String osType ) throws CxException, IOException, InterruptedException {
421421
List<String> arguments = new ArrayList<>();
422422
switch (osType){
423-
case OS_LINUX:
424423
case OS_MAC:
424+
String enginePath;
425425
arguments.add("/bin/sh");
426426
arguments.add("-c");
427-
arguments.add("which " + engineName);
428-
break;
427+
arguments.add("command -v " + engineName);
428+
try{
429+
enginePath= Execution.executeCommand((arguments), logger, line->line);
430+
}
431+
catch (CxException e){
432+
throw new CxException(1,"Engine "+engineName+" is not installed on the system");
433+
}
434+
435+
if(!enginePath.startsWith("/usr/local/bin/")){
436+
throw new CxException(1, engineName+ " was found at: " + enginePath + "\n" +
437+
"Please create a symlink at /usr/local/bin/docker:\n\n" +
438+
"sudo ln -s " + enginePath + " /usr/local/bin/"+engineName +"\n");
439+
}
440+
return enginePath;
429441
case OS_WINDOWS:
442+
case OS_LINUX:
430443
arguments.add(engineName);
431444
arguments.add("--version");
432-
break;
433-
445+
try {
446+
Execution.executeCommand(arguments, logger, line -> line);
447+
return engineName; // docker is available via PATH
448+
} catch (CxException | IOException e) {
449+
throw new CxException(
450+
1,engineName+" is not installed or is not accessible from the system PATH."
451+
);
452+
}
453+
default:
454+
throw new IllegalArgumentException("Unsupported OS: " + osType);
434455
}
435-
return Execution.executeCommand((arguments), logger, line->line);
456+
436457
}
437458

438459
public <T> T realtimeScan(@NonNull String subCommand, @NonNull String sourcePath, String containerTool, String ignoredFilePath, java.util.function.Function<String, T> resultParser)

0 commit comments

Comments
 (0)