|
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; |
@@ -409,6 +411,30 @@ public KicsRealtimeResults kicsRealtimeScan(@NonNull String fileSources, String |
409 | 411 | return Execution.executeCommand(withConfigArguments(arguments), logger, KicsRealtimeResults::fromLine); |
410 | 412 | } |
411 | 413 |
|
| 414 | + public String checkEngineExist(@NonNull String engineName) throws CxException, IOException, InterruptedException { |
| 415 | + String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH); |
| 416 | + String osType=Execution.getOperatingSystemType(osName); |
| 417 | + return this.checkEngine(engineName,osType); |
| 418 | + } |
| 419 | + |
| 420 | + private String checkEngine(String engineName, String osType ) throws CxException, IOException, InterruptedException { |
| 421 | + List<String> arguments = new ArrayList<>(); |
| 422 | + switch (osType){ |
| 423 | + case OS_LINUX: |
| 424 | + case OS_MAC: |
| 425 | + arguments.add("/bin/sh"); |
| 426 | + arguments.add("-c"); |
| 427 | + arguments.add("which " + engineName); |
| 428 | + break; |
| 429 | + case OS_WINDOWS: |
| 430 | + arguments.add(engineName); |
| 431 | + arguments.add("--version"); |
| 432 | + break; |
| 433 | + |
| 434 | + } |
| 435 | + return Execution.executeCommand((arguments), logger, line->line); |
| 436 | + } |
| 437 | + |
412 | 438 | public <T> T realtimeScan(@NonNull String subCommand, @NonNull String sourcePath, String containerTool, String ignoredFilePath, java.util.function.Function<String, T> resultParser) |
413 | 439 | throws IOException, InterruptedException, CxException { |
414 | 440 | this.logger.info("Executing 'scan {}' command using the CLI.", subCommand); |
|
0 commit comments