diff --git a/pom.xml b/pom.xml
index ed49aef..c08945e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.springframework.boot
spring-boot-starter-parent
- 2.7.1
+ 2.7.0
com.osredm
@@ -14,9 +14,7 @@
osredm-code-scan
osredm-code-scan
- 17
-
- 0.12.1
+ 11
@@ -118,6 +116,7 @@
2.3.2
+
org.springframework.boot
spring-boot-starter-data-redis
@@ -130,6 +129,31 @@
jaxb-api
2.3.1
+
+
+
+
+ org.dom4j
+ dom4j
+ 2.1.3
+
+
+
+
+
+
+
+ org.apache.commons
+ commons-lang3
+
+
+
+
+ com.alibaba
+ fastjson
+ 1.2.79
+
+
@@ -144,96 +168,18 @@
lombok
- ${repackage.classifier}
-
- paketobuildpacks/builder:tiny
-
- true
-
-
- org.springframework.experimental
- spring-aot-maven-plugin
- ${spring-native.version}
-
-
- test-generate
-
- test-generate
-
-
-
- generate
-
- generate
-
-
-
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ true
+
+
-
-
- spring-releases
- Spring Releases
- https://repo.spring.io/release
-
- false
-
-
-
-
-
- spring-releases
- Spring Releases
- https://repo.spring.io/release
-
- false
-
-
-
-
-
-
- native
-
- exec
- 0.9.13
-
-
-
- org.junit.platform
- junit-platform-launcher
- test
-
-
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
-
- org.projectlombok
- lombok
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
- true
-
-
-
-
-
-
diff --git a/src/main/java/com/osredm/codescan/config/SwaggerConfig.java b/src/main/java/com/osredm/codescan/config/SwaggerConfig.java
index 670a4ac..c28d173 100644
--- a/src/main/java/com/osredm/codescan/config/SwaggerConfig.java
+++ b/src/main/java/com/osredm/codescan/config/SwaggerConfig.java
@@ -24,14 +24,14 @@ public class SwaggerConfig {
public Docket docket(Environment environment) {
// 设置要显示的Swagger环境
- Profiles profiles = Profiles.of("dev", "test","lwh","win","desk","lwhWin");
- // 通过environment.acceptsProfiles判断是否在自己设定的环境当中
- boolean flag = environment.acceptsProfiles(profiles);
+// Profiles profiles = Profiles.of("dev", "test","lwh","win","desk","lwhWin");
+// // 通过environment.acceptsProfiles判断是否在自己设定的环境当中
+// boolean flag = environment.acceptsProfiles(profiles);
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
- .enable(flag) // 是否启动
+ .enable(true) // 是否启动
.groupName("developer")
.select()
//RequestHandlerSelectors 配置要扫描接口的方式
@@ -40,7 +40,7 @@ public class SwaggerConfig {
//none() 都不扫描
// withClassAnnotation()扫描类上的注解 需要注解的class
//withMethodAnnotation 扫描方法上的注解
- .apis(RequestHandlerSelectors.basePackage("com.osredm.osredmcompbackend.controller"))
+ .apis(RequestHandlerSelectors.basePackage("com.osredm.codescan.controller"))
// 过滤 什么 路径
// .paths(PathSelectors.ant("/user"))
.build();
diff --git a/src/main/java/com/osredm/codescan/controller/NicadController.java b/src/main/java/com/osredm/codescan/controller/NicadController.java
new file mode 100644
index 0000000..ff8c35c
--- /dev/null
+++ b/src/main/java/com/osredm/codescan/controller/NicadController.java
@@ -0,0 +1,26 @@
+package com.osredm.codescan.controller;
+
+import com.osredm.codescan.entity.NicadInfo;
+import com.osredm.codescan.service.NicadService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.io.IOException;
+import java.util.HashMap;
+
+@RestController
+@RequestMapping("/nicad")
+public class NicadController {
+
+
+ @Autowired
+ NicadService nicadService;
+
+ @PostMapping("/check")
+ public HashMapCheck(@RequestBody NicadInfo nicadInfo) {
+ return nicadService.check(nicadInfo);
+ }
+}
diff --git a/src/main/java/com/osredm/codescan/controller/UploadController.java b/src/main/java/com/osredm/codescan/controller/UploadController.java
index a266f84..9c1a4bb 100644
--- a/src/main/java/com/osredm/codescan/controller/UploadController.java
+++ b/src/main/java/com/osredm/codescan/controller/UploadController.java
@@ -30,7 +30,8 @@ public class UploadController {
boolean result = FileUploadUtil.uploadFileWithName(file, storeConfig.getFilePath(), fileName);
if (result) {
map.put("status",SUCCESS);
- map.put("url","/api/files/"+ fileName);
+// 由于后期接口是脚本运行 所以不需要映射 直接返回文件名称即可
+ map.put("fileName",fileName);
}else {
map.put("status",FAIL);
}
diff --git a/src/main/java/com/osredm/codescan/entity/NicadInfo.java b/src/main/java/com/osredm/codescan/entity/NicadInfo.java
new file mode 100644
index 0000000..171f444
--- /dev/null
+++ b/src/main/java/com/osredm/codescan/entity/NicadInfo.java
@@ -0,0 +1,13 @@
+package com.osredm.codescan.entity;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class NicadInfo {
+ private String fileName;
+ private String language;
+}
diff --git a/src/main/java/com/osredm/codescan/service/NicadService.java b/src/main/java/com/osredm/codescan/service/NicadService.java
new file mode 100644
index 0000000..90a1d23
--- /dev/null
+++ b/src/main/java/com/osredm/codescan/service/NicadService.java
@@ -0,0 +1,11 @@
+package com.osredm.codescan.service;
+
+import com.osredm.codescan.entity.NicadInfo;
+
+import java.io.IOException;
+import java.util.HashMap;
+
+public interface NicadService {
+
+ HashMapcheck(NicadInfo nicadInfo);
+}
diff --git a/src/main/java/com/osredm/codescan/service/impl/NicadServiceImpl.java b/src/main/java/com/osredm/codescan/service/impl/NicadServiceImpl.java
new file mode 100644
index 0000000..ed3b510
--- /dev/null
+++ b/src/main/java/com/osredm/codescan/service/impl/NicadServiceImpl.java
@@ -0,0 +1,110 @@
+package com.osredm.codescan.service.impl;
+
+import com.osredm.codescan.config.StoreConfig;
+import com.osredm.codescan.entity.NicadInfo;
+import com.osredm.codescan.service.NicadService;
+import com.osredm.codescan.utils.FileUploadUtil;
+import com.osredm.codescan.utils.XmlJsonUtils;
+import org.springframework.stereotype.Service;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Arrays;
+import java.util.HashMap;
+
+import static com.osredm.codescan.utils.Constants.FAIL;
+import static com.osredm.codescan.utils.Constants.SUCCESS;
+
+@Service
+public class NicadServiceImpl implements NicadService {
+
+ private final StoreConfig storeConfig;
+
+ public NicadServiceImpl(StoreConfig storeConfig) {
+ this.storeConfig = storeConfig;
+ }
+
+ @Override
+ public HashMap check(NicadInfo nicadInfo){
+ HashMap map = new HashMap<>();
+ String language = nicadInfo.getLanguage();
+ switch (language) {
+ case "Java":
+ String filePath = storeConfig.getFilePath() + nicadInfo.getFileName();
+ String time = String.valueOf(System.currentTimeMillis());
+ String flag = storeConfig.getFilePath() + time;
+ // 解压文件
+ String[] arguments = new String[] {"unzip" , filePath, "-d", flag};
+ Process proc;
+ try {
+ proc = Runtime.getRuntime().exec(arguments);// 执行解压文件
+ //用输入输出流来截取结果
+ BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+// InputStreamReader(proc.getInputStream());
+ String line = null;
+ String line1 = null;
+ while ((line = in.readLine()) != null) {
+ System.out.println(line);
+ line1 = line;
+ }
+ in.close();
+ int re = proc.waitFor(); //waitFor是用来显示脚本是否运行成功,1表示失败,0表示成功,还有其他的表示其他错误
+
+ if (re == 0) {
+ //成功
+
+ Process proc1;
+ String[] arguments1 = new String[] {"nicad6" ,"functions","java", flag, "default-report"};
+ proc1 = Runtime.getRuntime().exec(arguments1);// 执行解压文件
+ //用输入输出流来截取结果
+ BufferedReader in1 = new BufferedReader(new InputStreamReader(proc1.getInputStream()));
+
+ String line2 = null;
+ String line22 = null;
+ while ((line2 = in1.readLine()) != null) {
+ System.out.println(line2);
+ line22 = line2;
+ }
+ in1.close();
+ int re1 = proc1.waitFor(); //waitFor是用来显示脚本是否运行成功,1表示失败,0表示成功,还有其他的表示其他错误
+ if (re1 == 0) {
+ //成功 读取文件
+ String xml = FileUploadUtil.readFile(storeConfig.getFilePath() + time+"_functions-blind-clones/"+time+"_functions-blind-clones-0.30-classes-withsource.xml");
+
+ String s = XmlJsonUtils.xml2Json(xml);
+ map.put("status",SUCCESS);
+ map.put("xml",xml);
+ map.put("json",s);
+ return map;
+ }else {
+ //失败
+ map.put("status",FAIL);
+ return map;
+ }
+ }else {
+ //失败
+ map.put("status",FAIL);
+ return map;
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+
+ case "C":
+
+ case "C#":
+
+ case "Ruby":
+
+ case "JavaScript":
+
+ default:
+ map.put("status",FAIL);
+ map.put("msg","您选择的语言暂不支持检测!或遇到预期以外的错误");
+ return map;
+ }
+ }
+}
diff --git a/src/main/java/com/osredm/codescan/utils/FileUploadUtil.java b/src/main/java/com/osredm/codescan/utils/FileUploadUtil.java
index eac5fad..5548803 100644
--- a/src/main/java/com/osredm/codescan/utils/FileUploadUtil.java
+++ b/src/main/java/com/osredm/codescan/utils/FileUploadUtil.java
@@ -120,7 +120,7 @@ public class FileUploadUtil {
String line = "";
String line1;
while ((line1 = br.readLine()) != null) {
- line = line + line1 + '\n' ;
+ line = line + line1 ;
}
return line;
} catch (IOException e) {
diff --git a/src/main/java/com/osredm/codescan/utils/XmlJsonUtils.java b/src/main/java/com/osredm/codescan/utils/XmlJsonUtils.java
new file mode 100644
index 0000000..7bc5ef1
--- /dev/null
+++ b/src/main/java/com/osredm/codescan/utils/XmlJsonUtils.java
@@ -0,0 +1,89 @@
+package com.osredm.codescan.utils;
+
+
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.commons.lang.StringUtils;
+import org.dom4j.*;
+
+import java.util.List;
+import java.util.Map;
+public class XmlJsonUtils {
+
+ /**
+ * xml转json
+ * @param xmlStr xml字符串
+ * @return
+ */
+ public static String xml2Json(String xmlStr) {
+ try {
+ Document doc = DocumentHelper.parseText(xmlStr);
+ JSONObject json = new JSONObject();
+ dom4j2Json(doc.getRootElement(), json);
+ return JSONObject.toJSONString(json);
+ } catch (DocumentException e) {
+ System.out.println(e);
+ return null;
+ }
+ }
+
+ /**
+ * xml转json
+ *
+ * @param element
+ * @param json
+ */
+ private static void dom4j2Json(Element element, JSONObject json) {
+ //如果是属性
+ for (Object o : element.attributes()) {
+ Attribute attr = (Attribute) o;
+ if (!StringUtils.isBlank(attr.getValue())) {
+ json.put("@" + attr.getName(), attr.getValue());
+ }
+ }
+ List chdEl = element.elements();
+ if (chdEl.isEmpty() && !StringUtils.isBlank(element.getText())) {//如果没有子元素,只有一个值
+ json.put(element.getName(), element.getText());
+ }
+
+ for (Element e : chdEl) {//有子元素
+ if (!e.elements().isEmpty()) {//子元素也有子元素
+ JSONObject chdjson = new JSONObject();
+ dom4j2Json(e, chdjson);
+ Object o = json.get(e.getName());
+ if (o != null) {
+ JSONArray jsona = null;
+ if (o instanceof JSONObject) {//如果此元素已存在,则转为jsonArray
+ JSONObject jsono = (JSONObject) o;
+ json.remove(e.getName());
+ jsona = new JSONArray();
+ jsona.add(jsono);
+ jsona.add(chdjson);
+ }
+ if (o instanceof JSONArray) {
+ jsona = (JSONArray) o;
+ jsona.add(chdjson);
+ }
+ json.put(e.getName(), jsona);
+ } else {
+ if (!chdjson.isEmpty()) {
+ json.put(e.getName(), chdjson);
+ }
+ }
+
+
+ } else {//子元素没有子元素
+ for (Object o : element.attributes()) {
+ Attribute attr = (Attribute) o;
+ if (!StringUtils.isBlank(attr.getValue())) {
+ json.put("@" + attr.getName(), attr.getValue());
+ }
+ }
+ if (!e.getText().isEmpty()) {
+ json.put(e.getName(), e.getText());
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 8b13789..38a09f0 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1 +1,29 @@
+
+server.port=8011
+#MyBatis
+mybatis_config_file=mybatis-config.xml
+mapper_path=/mapper/**.xml
+entity_package=com.osredm.osredmcompbackend.entity,com.osredm.osredmcompbackend.vo
+
+#MySQL
+spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
+spring.datasource.url=jdbc:mysql://114.116.228.69:8006/osredm_comp?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&allowMultiQueries=true
+spring.datasource.username=root
+spring.datasource.password=HskyOsredm@163.com
+
+#swagger
+spring.mvc.pathmatch.matching-strategy=ant_path_matcher
+
+localPath=file:/root/code-scan/nicad/user-code/
+file.filePath=/root/code-scan/nicad/user-code/
+
+fileUploadPath=/root/code-scan/nicad/user-code/
+
+domain=http://localhost:8011/
+
+spring.servlet.multipart.max-file-size = 1000MB
+spring.servlet.multipart.max-request-size=10000MB
+
+
+