Skip to content

Commit 77bcdde

Browse files
committed
Support cx-linux-arm aka running om Mac Docker
1 parent bc8d330 commit 77bcdde

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import java.io.IOException;
88
import java.util.ArrayList;
9-
import java.util.Arrays;
109
import java.util.List;
1110

1211
public class CxThinWrapper {
@@ -22,7 +21,7 @@ public CxThinWrapper() throws IOException {
2221

2322
public CxThinWrapper(@NonNull Logger logger) throws IOException {
2423
this.logger = logger;
25-
this.executable = Execution.getTempBinary();
24+
this.executable = Execution.getTempBinary(logger);
2625
this.logger.info("Executable path: {} ", executable);
2726
}
2827

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public CxWrapper(@NonNull CxConfig cxConfig, @NonNull Logger logger) throws IOEx
4949
this.cxConfig = cxConfig;
5050
this.logger = logger;
5151
this.executable = StringUtils.isBlank(this.cxConfig.getPathToExecutable())
52-
? Execution.getTempBinary()
52+
? Execution.getTempBinary(logger)
5353
: this.cxConfig.getPathToExecutable();
5454
this.logger.info("Executable path: {} ", executable);
5555
}

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

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

3+
import lombok.NonNull;
34
import org.slf4j.Logger;
45

56
import java.io.*;
@@ -23,10 +24,10 @@ private Execution() {
2324

2425
}
2526

26-
private static final String OS_NAME = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
2727
private static final String OS_LINUX = "linux";
2828
private static final String OS_WINDOWS = "windows";
29-
private static final List<String> OS_MAC = Arrays.asList("mac os x", "darwin", "osx");
29+
private static final String OS_MAC = "mac";
30+
private static final List<String> OS_MAC_NAMES = Arrays.asList("mac os x", "darwin", "osx");
3031
private static final String FILE_NAME_LINUX = "cx-linux";
3132
private static final String FILE_NAME_LINUX_ARM = "cx-linux-arm";
3233
private static final String FILE_NAME_MAC = "cx-mac";
@@ -108,9 +109,9 @@ static String executeCommand(List<String> arguments,
108109
StandardCharsets.UTF_8);
109110
}
110111

111-
static String getTempBinary() throws IOException {
112+
static String getTempBinary(@NonNull Logger logger) throws IOException {
112113
if (executable == null) {
113-
String fileName = detectBinaryName();
114+
String fileName = detectBinaryName(logger);
114115
if (fileName == null) {
115116
throw new IOException("Unsupported architecture");
116117
}
@@ -143,28 +144,39 @@ private static Process buildProcess(List<String> commands) throws IOException {
143144
return lmBuilder.start();
144145
}
145146

146-
private static String detectBinaryName() {
147-
String osName = OS_NAME;
147+
private static String detectBinaryName(@NonNull Logger logger) {
148+
String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
148149
String osArch = System.getProperty("os.arch").toLowerCase(Locale.ENGLISH);
149150
String fileName = null;
150151

152+
switch (getOperatingSystemType(osName)) {
153+
case OS_LINUX:
154+
fileName = osArch.contains("arm") || osArch.contains("aarch64") ? FILE_NAME_LINUX_ARM : FILE_NAME_LINUX;
155+
break;
156+
case OS_WINDOWS:
157+
fileName = FILE_NAME_WINDOWS;
158+
break;
159+
case OS_MAC:
160+
fileName = FILE_NAME_MAC;
161+
break;
162+
default:
163+
// Handle unknown OS
164+
logger.error("Unsupported operating system: {} Architecture: {}", osName, osArch);
165+
break;
166+
}
167+
return fileName;
168+
}
169+
170+
private static String getOperatingSystemType(String osName) {
151171
if (osName.contains(OS_LINUX)) {
152-
if (osArch.contains("arm") || osArch.contains("aarch64")) {
153-
fileName = FILE_NAME_LINUX_ARM;
154-
} else {
155-
fileName = FILE_NAME_LINUX;
156-
}
172+
return OS_LINUX;
157173
} else if (osName.contains(OS_WINDOWS)) {
158-
fileName = FILE_NAME_WINDOWS;
174+
return OS_WINDOWS;
175+
} else if (OS_MAC_NAMES.stream().anyMatch(osName::contains)) {
176+
return OS_MAC;
159177
} else {
160-
for (String macStr : OS_MAC) {
161-
if (osName.contains(macStr)) {
162-
fileName = FILE_NAME_MAC;
163-
break;
164-
}
165-
}
178+
return "UNKNOWN"; // Handle unknown OS (optional)
166179
}
167-
return fileName;
168180
}
169181

170182
private static void copyURLToFile(URL source, File destination) throws IOException {

0 commit comments

Comments
 (0)