Skip to content

Commit ea4ae0a

Browse files
Merge branch 'feature/ASCA_IgnoreFile' of https://github.com/CheckmarxDev/ast-cli-java-wrapper into feature/ASCA_IgnoreFile
2 parents eb5d646 + 863b1cc commit ea4ae0a

File tree

5 files changed

+61
-19
lines changed

5 files changed

+61
-19
lines changed

checkmarx-ast-cli.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.3.42
1+
2.3.42-iac-engine-fallbackPath

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

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,17 @@
3131

3232
import java.io.IOException;
3333
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.*;
3837

3938
public class CxWrapper {
4039

4140
private static final CollectionType BRANCHES_TYPE = TypeFactory.defaultInstance()
4241
.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";
4345

4446
@NonNull
4547
private final CxConfig cxConfig;
@@ -409,6 +411,49 @@ public KicsRealtimeResults kicsRealtimeScan(@NonNull String fileSources, String
409411
return Execution.executeCommand(withConfigArguments(arguments), logger, KicsRealtimeResults::fromLine);
410412
}
411413

414+
public <T> T realtimeScan(@NonNull String subCommand, @NonNull String sourcePath, String containerTool, String ignoredFilePath, java.util.function.Function<String, T> resultParser)
415+
public String checkEngineExist(@NonNull String engineName) throws CxException, IOException, InterruptedException {
416+
String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
417+
String osType=Execution.getOperatingSystemType(osName);
418+
return this.checkEngine(engineName,osType);
419+
}
420+
421+
private String checkEngine(String engineName, String osType ) throws CxException, IOException, InterruptedException {
422+
List<String> arguments = new ArrayList<>();
423+
switch (osType){
424+
case OS_MAC:
425+
String enginePath;
426+
arguments.add("/bin/sh");
427+
arguments.add("-c");
428+
arguments.add("command -v " + engineName);
429+
try{
430+
enginePath= Execution.executeCommand((arguments), logger, line->line);
431+
}
432+
throw new CxException(
433+
1,
434+
"Engine '" + engineName + "' is not installed or not found at /usr/local/bin)."
435+
);
436+
437+
438+
return enginePath;
439+
case OS_WINDOWS:
440+
case OS_LINUX:
441+
arguments.add(engineName);
442+
arguments.add("--version");
443+
try {
444+
Execution.executeCommand(arguments, logger, line -> line);
445+
return engineName;
446+
} catch (CxException | IOException e) {
447+
throw new CxException(
448+
1,engineName+" is not installed or is not accessible from the system PATH."
449+
);
450+
}
451+
default:
452+
throw new IllegalArgumentException("Unsupported OS: " + osType);
453+
}
454+
455+
}
456+
412457
public <T> T realtimeScan(@NonNull String subCommand, @NonNull String sourcePath, String containerTool, String ignoredFilePath, java.util.function.Function<String, T> resultParser)
413458
throws IOException, InterruptedException, CxException {
414459
this.logger.info("Executing 'scan {}' command using the CLI.", subCommand);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.checkmarx.ast.wrapper;
22

3+
import com.checkmarx.ast.kicsRealtimeResults.KicsRealtimeResults;
34
import lombok.NonNull;
45
import org.slf4j.Logger;
56

@@ -12,10 +13,7 @@
1213
import java.nio.file.Paths;
1314
import java.security.MessageDigest;
1415
import java.security.NoSuchAlgorithmException;
15-
import java.util.Arrays;
16-
import java.util.List;
17-
import java.util.Locale;
18-
import java.util.Objects;
16+
import java.util.*;
1917
import java.util.function.BiFunction;
2018
import java.util.function.Function;
2119

@@ -171,7 +169,7 @@ private static String detectBinaryName(@NonNull Logger logger) {
171169
return fileName;
172170
}
173171

174-
private static String getOperatingSystemType(String osName) {
172+
public static String getOperatingSystemType(String osName) {
175173
if (osName.contains(OS_LINUX)) {
176174
return OS_LINUX;
177175
} else if (osName.contains(OS_WINDOWS)) {
@@ -217,4 +215,6 @@ private static String md5(InputStream a) {
217215
}
218216
return md5;
219217
}
218+
219+
220220
}

src/main/resources/cx.exe

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/test/java/com/checkmarx/ast/TelemetryTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ void testTelemetryAIEventSuccessfulCaseWithMinimalParametersAiLog() throws CxExc
1616
// Test case: AI logging with specific parameters and some empty values
1717
Assertions.assertDoesNotThrow(() -> {
1818
String result = wrapper.telemetryAIEvent(
19-
"Copilot", // aiProvider
20-
"JetBrains IntelliJ IDEA", // agent
19+
"Cursor", // aiProvider
20+
"Cursos", // agent
2121
"click", // eventType
22-
"viewDetails", // subType
22+
"ast-results.viewPackageDetails", // subType
2323
"secrets", // engine
2424
"high", // problemSeverity
2525
"", // scanType (empty)
@@ -34,7 +34,7 @@ void testTelemetryAIEventSuccessfulCaseWithMinimalParametersDetectionLog() throw
3434
// Test case: Detection logging with most parameters empty and specific scan data
3535
Assertions.assertDoesNotThrow(() -> {
3636
String result = wrapper.telemetryAIEvent(
37-
"", // aiProvider (empty)
37+
"", // aiProvider (empty)
3838
"", // agent (empty)
3939
"", // eventType (empty)
4040
"", // subType (empty)
@@ -52,7 +52,7 @@ void testTelemetryAIEventSuccessfulCaseWithEdgeCaseParameters() throws CxExcepti
5252
// Test case: Edge case with minimal required parameters
5353
Assertions.assertDoesNotThrow(() -> {
5454
String result = wrapper.telemetryAIEvent(
55-
"test-provider", // aiProvider (minimal value)
55+
"test-provider", // aiProvider (minimal value)
5656
"java-wrapper", // agent (minimal value)
5757
"", // eventType (empty)
5858
"", // subType (empty)
@@ -64,4 +64,4 @@ void testTelemetryAIEventSuccessfulCaseWithEdgeCaseParameters() throws CxExcepti
6464
);
6565
}, "Telemetry AI event should execute successfully for edge case");
6666
}
67-
}
67+
}

0 commit comments

Comments
 (0)