Skip to content

Commit 830e515

Browse files
authored
feat/SCA-21471 (#389)
* Needed to fix null issue in JFrog artifactory * Needed to fix null issue in JFrog artifactory * Support cx-linux-arm aka running om Mac Docker * Configure Git LFS for large binaries * Support cx-linux-arm aka running om Mac Docker * Support cx-linux-arm aka running om Mac Docker
1 parent 5d30721 commit 830e515

File tree

9 files changed

+58
-23
lines changed

9 files changed

+58
-23
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
src/main/resources/cx-linux filter=lfs diff=lfs merge=lfs -text
2+
src/main/resources/cx-linux-arm filter=lfs diff=lfs merge=lfs -text
23
src/main/resources/cx.exe filter=lfs diff=lfs merge=lfs -text
34
src/main/resources/cx-mac filter=lfs diff=lfs merge=lfs -text

.github/scripts/update_cli.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
release=$1
44
filename_windows=ast-cli_${release}_windows_x64.zip
55
filename_linux=ast-cli_${release}_linux_x64.tar.gz
6+
filename_linuxarm=ast-cli_${release}_linux_arm64.tar.gz
67
filename_darwin=ast-cli_${release}_darwin_x64.tar.gz
78

89
#Windows
@@ -22,6 +23,15 @@ mv ./tmp/cx ./src/main/resources/cx-linux
2223
rm -r tmp
2324
rm ${filename_linux}
2425

26+
#linuxarm
27+
echo "Updating linuxarm binary"
28+
wget https://github.com/checkmarx/ast-cli/releases/download/${release}/${filename_linuxarm}
29+
mkdir ./tmp/
30+
tar -xvzf ${filename_linuxarm} -C ./tmp/
31+
mv ./tmp/cx ./src/main/resources/cx-linux-arm
32+
rm -r tmp
33+
rm ${filename_linuxarm}
34+
2535
#darwin
2636
echo "Updating mac binary"
2737
wget https://github.com/checkmarx/ast-cli/releases/download/${release}/${filename_darwin}

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ jobs:
4040
if [ ! -f "src/main/resources/cx-linux" ]; then
4141
echo "cx-linux binary does not exist"; exit 1;
4242
fi
43+
- name: Check existence of cx-linux-arm binary
44+
run: |
45+
if [ ! -f "src/main/resources/cx-linux-arm" ]; then
46+
echo "cx-linux-arm binary does not exist"; exit 1;
47+
fi
4348
- name: Check existence of cx.exe binary
4449
run: |
4550
if [ ! -f "src/main/resources/cx.exe" ]; then

.github/workflows/update-cli.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ jobs:
5050
if: steps.checkmarx-ast-cli.outputs.current_tag != steps.checkmarx-ast-cli.outputs.release_tag
5151
run: |
5252
git lfs track "src/main/resources/cx-linux"
53+
git lfs track "src/main/resources/cx-linux-arm"
5354
git lfs track "src/main/resources/cx.exe"
5455
git lfs track "src/main/resources/cx-mac"
5556
git add .gitattributes
56-
git add src/main/resources/cx-linux src/main/resources/cx.exe src/main/resources/cx-mac
57+
git add src/main/resources/cx-linux src/main/resources/cx-linux-arm src/main/resources/cx.exe src/main/resources/cx-mac
5758
git commit -m "Track Checkmarx CLI binaries with Git LFS"
5859
5960
- name: Create Pull Request

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ List<String> toArguments() {
5757
commands.add(CxConstants.BASE_AUTH_URI);
5858
commands.add(getBaseAuthUri());
5959
}
60-
61-
commands.addAll(getAdditionalParameters());
60+
if (getAdditionalParameters() != null)
61+
commands.addAll(getAdditionalParameters());
6262

6363
return commands;
6464
}

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: 36 additions & 17 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,11 +24,12 @@ 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";
32+
private static final String FILE_NAME_LINUX_ARM = "cx-linux-arm";
3133
private static final String FILE_NAME_MAC = "cx-mac";
3234
private static final String FILE_NAME_WINDOWS = "cx.exe";
3335
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
@@ -107,9 +109,9 @@ static String executeCommand(List<String> arguments,
107109
StandardCharsets.UTF_8);
108110
}
109111

110-
static String getTempBinary() throws IOException {
112+
static String getTempBinary(@NonNull Logger logger) throws IOException {
111113
if (executable == null) {
112-
String fileName = detectBinaryName();
114+
String fileName = detectBinaryName(logger);
113115
if (fileName == null) {
114116
throw new IOException("Unsupported architecture");
115117
}
@@ -142,24 +144,41 @@ private static Process buildProcess(List<String> commands) throws IOException {
142144
return lmBuilder.start();
143145
}
144146

145-
private static String detectBinaryName() {
146-
String arch = OS_NAME;
147+
private static String detectBinaryName(@NonNull Logger logger) {
148+
String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
149+
String osArch = System.getProperty("os.arch").toLowerCase(Locale.ENGLISH);
147150
String fileName = null;
148-
if (arch.contains(OS_LINUX)) {
149-
fileName = FILE_NAME_LINUX;
150-
} else if (arch.contains(OS_WINDOWS)) {
151-
fileName = FILE_NAME_WINDOWS;
152-
} else {
153-
for (String macStr : OS_MAC) {
154-
if (arch.contains(macStr)) {
155-
fileName = FILE_NAME_MAC;
156-
break;
157-
}
158-
}
151+
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;
159166
}
160167
return fileName;
161168
}
162169

170+
private static String getOperatingSystemType(String osName) {
171+
if (osName.contains(OS_LINUX)) {
172+
return OS_LINUX;
173+
} else if (osName.contains(OS_WINDOWS)) {
174+
return OS_WINDOWS;
175+
} else if (OS_MAC_NAMES.stream().anyMatch(osName::contains)) {
176+
return OS_MAC;
177+
} else {
178+
return "UNKNOWN"; // Handle unknown OS
179+
}
180+
}
181+
163182
private static void copyURLToFile(URL source, File destination) throws IOException {
164183
final byte[] buf = new byte[8192];
165184
try (InputStream reader = source.openStream();

src/main/resources/cx-linux-arm

61.3 MB
Binary file not shown.

0 commit comments

Comments
 (0)