|
31 | 31 |
|
32 | 32 | import java.io.IOException; |
33 | 33 | import java.nio.file.Files; |
34 | | -import java.util.ArrayList; |
35 | | -import java.util.List; |
36 | | -import java.util.Map; |
37 | | -import java.util.UUID; |
| 34 | +import java.util.*; |
| 35 | + |
| 36 | +import static com.checkmarx.ast.wrapper.Execution.*; |
38 | 37 |
|
39 | 38 | public class CxWrapper { |
40 | 39 |
|
41 | 40 | private static final CollectionType BRANCHES_TYPE = TypeFactory.defaultInstance() |
42 | 41 | .constructCollectionType(List.class, String.class); |
| 42 | + private static final String OS_LINUX = "linux"; |
| 43 | + private static final String OS_WINDOWS = "windows"; |
| 44 | + private static final String OS_MAC = "mac"; |
43 | 45 |
|
44 | 46 | @NonNull |
45 | 47 | private final CxConfig cxConfig; |
@@ -413,6 +415,49 @@ public KicsRealtimeResults kicsRealtimeScan(@NonNull String fileSources, String |
413 | 415 | return Execution.executeCommand(withConfigArguments(arguments), logger, KicsRealtimeResults::fromLine); |
414 | 416 | } |
415 | 417 |
|
| 418 | + public <T> T realtimeScan(@NonNull String subCommand, @NonNull String sourcePath, String containerTool, String ignoredFilePath, java.util.function.Function<String, T> resultParser) |
| 419 | + public String checkEngineExist(@NonNull String engineName) throws CxException, IOException, InterruptedException { |
| 420 | + String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH); |
| 421 | + String osType=Execution.getOperatingSystemType(osName); |
| 422 | + return this.checkEngine(engineName,osType); |
| 423 | + } |
| 424 | + |
| 425 | + private String checkEngine(String engineName, String osType ) throws CxException, IOException, InterruptedException { |
| 426 | + List<String> arguments = new ArrayList<>(); |
| 427 | + switch (osType){ |
| 428 | + case OS_MAC: |
| 429 | + String enginePath; |
| 430 | + arguments.add("/bin/sh"); |
| 431 | + arguments.add("-c"); |
| 432 | + arguments.add("command -v " + engineName); |
| 433 | + try{ |
| 434 | + enginePath= Execution.executeCommand((arguments), logger, line->line); |
| 435 | + } |
| 436 | + throw new CxException( |
| 437 | + 1, |
| 438 | + "Engine '" + engineName + "' is not installed or not found at /usr/local/bin)." |
| 439 | + ); |
| 440 | + |
| 441 | + |
| 442 | + return enginePath; |
| 443 | + case OS_WINDOWS: |
| 444 | + case OS_LINUX: |
| 445 | + arguments.add(engineName); |
| 446 | + arguments.add("--version"); |
| 447 | + try { |
| 448 | + Execution.executeCommand(arguments, logger, line -> line); |
| 449 | + return engineName; |
| 450 | + } catch (CxException | IOException e) { |
| 451 | + throw new CxException( |
| 452 | + 1,engineName+" is not installed or is not accessible from the system PATH." |
| 453 | + ); |
| 454 | + } |
| 455 | + default: |
| 456 | + throw new IllegalArgumentException("Unsupported OS: " + osType); |
| 457 | + } |
| 458 | + |
| 459 | + } |
| 460 | + |
416 | 461 | public <T> T realtimeScan(@NonNull String subCommand, @NonNull String sourcePath, String containerTool, String ignoredFilePath, java.util.function.Function<String, T> resultParser) |
417 | 462 | throws IOException, InterruptedException, CxException { |
418 | 463 | this.logger.info("Executing 'scan {}' command using the CLI.", subCommand); |
|
0 commit comments