diff --git a/.gitattributes b/.gitattributes index 6d67ae83..abbedb9b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ src/main/resources/cx-linux filter=lfs diff=lfs merge=lfs -text +src/main/resources/cx-linux-arm filter=lfs diff=lfs merge=lfs -text src/main/resources/cx.exe filter=lfs diff=lfs merge=lfs -text src/main/resources/cx-mac filter=lfs diff=lfs merge=lfs -text diff --git a/.github/scripts/update_cli.sh b/.github/scripts/update_cli.sh index 3a7113f6..50aee4db 100755 --- a/.github/scripts/update_cli.sh +++ b/.github/scripts/update_cli.sh @@ -3,6 +3,7 @@ release=$1 filename_windows=ast-cli_${release}_windows_x64.zip filename_linux=ast-cli_${release}_linux_x64.tar.gz +filename_linuxarm=ast-cli_${release}_linux_arm64.tar.gz filename_darwin=ast-cli_${release}_darwin_x64.tar.gz #Windows @@ -22,6 +23,15 @@ mv ./tmp/cx ./src/main/resources/cx-linux rm -r tmp rm ${filename_linux} +#linuxarm +echo "Updating linuxarm binary" +wget https://github.com/checkmarx/ast-cli/releases/download/${release}/${filename_linuxarm} +mkdir ./tmp/ +tar -xvzf ${filename_linuxarm} -C ./tmp/ +mv ./tmp/cx ./src/main/resources/cx-linux-arm +rm -r tmp +rm ${filename_linuxarm} + #darwin echo "Updating mac binary" wget https://github.com/checkmarx/ast-cli/releases/download/${release}/${filename_darwin} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b6116fdc..fed1f695 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,6 +40,11 @@ jobs: if [ ! -f "src/main/resources/cx-linux" ]; then echo "cx-linux binary does not exist"; exit 1; fi + - name: Check existence of cx-linux-arm binary + run: | + if [ ! -f "src/main/resources/cx-linux-arm" ]; then + echo "cx-linux-arm binary does not exist"; exit 1; + fi - name: Check existence of cx.exe binary run: | if [ ! -f "src/main/resources/cx.exe" ]; then diff --git a/.github/workflows/update-cli.yml b/.github/workflows/update-cli.yml index 9ec4124f..b3129b50 100644 --- a/.github/workflows/update-cli.yml +++ b/.github/workflows/update-cli.yml @@ -50,10 +50,11 @@ jobs: if: steps.checkmarx-ast-cli.outputs.current_tag != steps.checkmarx-ast-cli.outputs.release_tag run: | git lfs track "src/main/resources/cx-linux" + git lfs track "src/main/resources/cx-linux-arm" git lfs track "src/main/resources/cx.exe" git lfs track "src/main/resources/cx-mac" git add .gitattributes - git add src/main/resources/cx-linux src/main/resources/cx.exe src/main/resources/cx-mac + git add src/main/resources/cx-linux src/main/resources/cx-linux-arm src/main/resources/cx.exe src/main/resources/cx-mac git commit -m "Track Checkmarx CLI binaries with Git LFS" - name: Create Pull Request diff --git a/src/main/java/com/checkmarx/ast/wrapper/CxConfig.java b/src/main/java/com/checkmarx/ast/wrapper/CxConfig.java index 7c0189ca..5423de55 100644 --- a/src/main/java/com/checkmarx/ast/wrapper/CxConfig.java +++ b/src/main/java/com/checkmarx/ast/wrapper/CxConfig.java @@ -57,8 +57,8 @@ List toArguments() { commands.add(CxConstants.BASE_AUTH_URI); commands.add(getBaseAuthUri()); } - - commands.addAll(getAdditionalParameters()); + if (getAdditionalParameters() != null) + commands.addAll(getAdditionalParameters()); return commands; } diff --git a/src/main/java/com/checkmarx/ast/wrapper/CxThinWrapper.java b/src/main/java/com/checkmarx/ast/wrapper/CxThinWrapper.java index 2e51d5df..b195b206 100644 --- a/src/main/java/com/checkmarx/ast/wrapper/CxThinWrapper.java +++ b/src/main/java/com/checkmarx/ast/wrapper/CxThinWrapper.java @@ -6,7 +6,6 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; public class CxThinWrapper { @@ -22,7 +21,7 @@ public CxThinWrapper() throws IOException { public CxThinWrapper(@NonNull Logger logger) throws IOException { this.logger = logger; - this.executable = Execution.getTempBinary(); + this.executable = Execution.getTempBinary(logger); this.logger.info("Executable path: {} ", executable); } diff --git a/src/main/java/com/checkmarx/ast/wrapper/CxWrapper.java b/src/main/java/com/checkmarx/ast/wrapper/CxWrapper.java index 3f20df19..c72e1bd5 100644 --- a/src/main/java/com/checkmarx/ast/wrapper/CxWrapper.java +++ b/src/main/java/com/checkmarx/ast/wrapper/CxWrapper.java @@ -49,7 +49,7 @@ public CxWrapper(@NonNull CxConfig cxConfig, @NonNull Logger logger) throws IOEx this.cxConfig = cxConfig; this.logger = logger; this.executable = StringUtils.isBlank(this.cxConfig.getPathToExecutable()) - ? Execution.getTempBinary() + ? Execution.getTempBinary(logger) : this.cxConfig.getPathToExecutable(); this.logger.info("Executable path: {} ", executable); } diff --git a/src/main/java/com/checkmarx/ast/wrapper/Execution.java b/src/main/java/com/checkmarx/ast/wrapper/Execution.java index 8aec03d5..56aa48ef 100644 --- a/src/main/java/com/checkmarx/ast/wrapper/Execution.java +++ b/src/main/java/com/checkmarx/ast/wrapper/Execution.java @@ -1,5 +1,6 @@ package com.checkmarx.ast.wrapper; +import lombok.NonNull; import org.slf4j.Logger; import java.io.*; @@ -23,11 +24,12 @@ private Execution() { } - private static final String OS_NAME = System.getProperty("os.name").toLowerCase(Locale.ENGLISH); private static final String OS_LINUX = "linux"; private static final String OS_WINDOWS = "windows"; - private static final List OS_MAC = Arrays.asList("mac os x", "darwin", "osx"); + private static final String OS_MAC = "mac"; + private static final List OS_MAC_NAMES = Arrays.asList("mac os x", "darwin", "osx"); private static final String FILE_NAME_LINUX = "cx-linux"; + private static final String FILE_NAME_LINUX_ARM = "cx-linux-arm"; private static final String FILE_NAME_MAC = "cx-mac"; private static final String FILE_NAME_WINDOWS = "cx.exe"; private static final String LINE_SEPARATOR = System.getProperty("line.separator"); @@ -107,9 +109,9 @@ static String executeCommand(List arguments, StandardCharsets.UTF_8); } - static String getTempBinary() throws IOException { + static String getTempBinary(@NonNull Logger logger) throws IOException { if (executable == null) { - String fileName = detectBinaryName(); + String fileName = detectBinaryName(logger); if (fileName == null) { throw new IOException("Unsupported architecture"); } @@ -142,24 +144,41 @@ private static Process buildProcess(List commands) throws IOException { return lmBuilder.start(); } - private static String detectBinaryName() { - String arch = OS_NAME; + private static String detectBinaryName(@NonNull Logger logger) { + String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH); + String osArch = System.getProperty("os.arch").toLowerCase(Locale.ENGLISH); String fileName = null; - if (arch.contains(OS_LINUX)) { - fileName = FILE_NAME_LINUX; - } else if (arch.contains(OS_WINDOWS)) { - fileName = FILE_NAME_WINDOWS; - } else { - for (String macStr : OS_MAC) { - if (arch.contains(macStr)) { - fileName = FILE_NAME_MAC; - break; - } - } + + switch (getOperatingSystemType(osName)) { + case OS_LINUX: + fileName = osArch.contains("arm") || osArch.contains("aarch64") ? FILE_NAME_LINUX_ARM : FILE_NAME_LINUX; + break; + case OS_WINDOWS: + fileName = FILE_NAME_WINDOWS; + break; + case OS_MAC: + fileName = FILE_NAME_MAC; + break; + default: + // Handle unknown OS + logger.error("Unsupported operating system: {} Architecture: {}", osName, osArch); + break; } return fileName; } + private static String getOperatingSystemType(String osName) { + if (osName.contains(OS_LINUX)) { + return OS_LINUX; + } else if (osName.contains(OS_WINDOWS)) { + return OS_WINDOWS; + } else if (OS_MAC_NAMES.stream().anyMatch(osName::contains)) { + return OS_MAC; + } else { + return "UNKNOWN"; // Handle unknown OS + } + } + private static void copyURLToFile(URL source, File destination) throws IOException { final byte[] buf = new byte[8192]; try (InputStream reader = source.openStream(); diff --git a/src/main/resources/cx-linux-arm b/src/main/resources/cx-linux-arm new file mode 100755 index 00000000..8905ac47 Binary files /dev/null and b/src/main/resources/cx-linux-arm differ