Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions .github/scripts/update_cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/update-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/checkmarx/ast/wrapper/CxConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ List<String> toArguments() {
commands.add(CxConstants.BASE_AUTH_URI);
commands.add(getBaseAuthUri());
}

commands.addAll(getAdditionalParameters());
if (getAdditionalParameters() != null)
commands.addAll(getAdditionalParameters());

return commands;
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/checkmarx/ast/wrapper/CxThinWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class CxThinWrapper {
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/checkmarx/ast/wrapper/CxWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
53 changes: 36 additions & 17 deletions src/main/java/com/checkmarx/ast/wrapper/Execution.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.checkmarx.ast.wrapper;

import lombok.NonNull;
import org.slf4j.Logger;

import java.io.*;
Expand All @@ -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<String> OS_MAC = Arrays.asList("mac os x", "darwin", "osx");
private static final String OS_MAC = "mac";
private static final List<String> 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");
Expand Down Expand Up @@ -107,9 +109,9 @@ static String executeCommand(List<String> 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");
}
Expand Down Expand Up @@ -142,24 +144,41 @@ private static Process buildProcess(List<String> 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();
Expand Down
Binary file added src/main/resources/cx-linux-arm
Binary file not shown.
Loading