Skip to content

Commit

Permalink
[fix]修复Unix系统下命令行工具执行失败
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanshengjun committed Jan 7, 2022
1 parent 5e8c352 commit 2b1ffa9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'cn.xmirror.sca'
version '1.0.0'
version '1.0.1'

repositories {
mavenCentral()
Expand All @@ -24,6 +24,11 @@ patchPluginXml {
version = project.version
sinceBuild = '203'
untilBuild = '213.*'
changeNotes = """
<ui>
<li>修复Unix系统下命令行工具执行失败</li>
</ui>
"""
}
test {
useJUnitPlatform()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum ErrorEnum {
ENGINE_UNSUPPORTED_SYSTEM_ERROR(40041, "不支持此操作系统"),
ENGINE_DOWNLOAD_ERROR(40042, "下载引擎失败"),
ENGINE_UNREACHABLE_ERROR(40043, "引擎连接失败"),
ENGINE_SET_EXECUTABLE_ERROR(40044, "引擎设置可执行权限失败,请手动设置后重新检测"),

// 检测相关
CHECK_PARSE_RESULT_ERROR(40081,"结果解析错误"),
Expand Down
23 changes: 14 additions & 9 deletions src/main/java/cn/xmirror/sca/engine/EngineDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,21 @@ public static void checkAndDownload(Project project) {
// 检测引擎是否存在
String engineCliPath = EngineAssistant.getEngineCliPath();
File engineCli = new File(engineCliPath);
if (!HttpService.needUpdateEngine(EngineAssistant.getEngineVersionPath()) && engineCli.isFile()) return;
// 创建目录
String engineCliDirectory = EngineAssistant.getDefaultEngineCliDirectory();
if (!FileUtil.createDirectory(new File(engineCliDirectory))) {
throw new SCAException(ErrorEnum.CREATE_DIR_ERROR, engineCliDirectory);
if (HttpService.needUpdateEngine(EngineAssistant.getEngineVersionPath()) || !engineCli.isFile()) {
// 创建目录
String engineCliDirectory = EngineAssistant.getDefaultEngineCliDirectory();
if (!FileUtil.createDirectory(new File(engineCliDirectory))) {
throw new SCAException(ErrorEnum.CREATE_DIR_ERROR, engineCliDirectory);
}
// 下载引擎
if (engineCli.isDirectory()) {
throw new SCAException(ErrorEnum.ENGINE_DOWNLOAD_ERROR);
}
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> HttpService.downloadEngine(engineCli.getAbsolutePath()), "更新/下载OpenSCA命令行工具", false, project);
}
// 下载引擎
if (engineCli.isDirectory()) {
throw new SCAException(ErrorEnum.ENGINE_DOWNLOAD_ERROR);
// 设置引擎执行权限
if (!engineCli.canExecute() && !engineCli.setExecutable(true)) {
throw new SCAException(ErrorEnum.ENGINE_SET_EXECUTABLE_ERROR, engineCliPath);
}
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> HttpService.downloadEngine(engineCli.getAbsolutePath()), "更新/下载OpenSCA命令行工具", false, project);
}
}
2 changes: 1 addition & 1 deletion src/main/java/cn/xmirror/sca/service/CheckService.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static void run(Project project, CheckListener listener) {
String engineCliPath = EngineAssistant.getEngineCliPath();
String inputPath = project.getBasePath();
String outputPath = EngineAssistant.getCheckResultPath(project);
String[] cmd = {engineCliPath, "-ip", url, "-token", token, "-path", inputPath, "-out", outputPath, "-vuln", "-cache"};
String[] cmd = {engineCliPath, "-url", url, "-token", token, "-path", inputPath, "-out", outputPath, "-vuln", "-cache"};
Runtime.getRuntime().exec(cmd).waitFor();
// 解析结果
overview.setEndTime(new Date());
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/cn/xmirror/sca/service/HttpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import org.apache.http.HttpStatus;
import org.jsoup.Connection;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
Expand Down

0 comments on commit 2b1ffa9

Please sign in to comment.