java nicad 自动检测脚本接口完成
This commit is contained in:
parent
50c3e4d3fc
commit
b467d03a7d
|
@ -1,6 +1,6 @@
|
|||
package com.osredm.codescan.controller;
|
||||
|
||||
import com.osredm.codescan.entity.NicadInfo;
|
||||
import com.osredm.codescan.entity.Nicad.NicadInfo;
|
||||
import com.osredm.codescan.service.NicadService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
@ -8,7 +8,6 @@ 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
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.osredm.codescan.entity.Nicad;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class ClassAttr {
|
||||
private String classid;
|
||||
private String nclones;
|
||||
private String nlines;
|
||||
private String similarity;
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.osredm.codescan.entity.Nicad;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ClassInfoAttr {
|
||||
private String nclasses;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.osredm.codescan.entity.Nicad;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ClassSource {
|
||||
private ClassSourceAttr _attributes;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.osredm.codescan.entity.Nicad;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ClassSourceAttr {
|
||||
private String file;
|
||||
private String startline;
|
||||
private String endline;
|
||||
private String pcid;
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.osredm.codescan.entity.Nicad;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CloneInfoAttr {
|
||||
private String npcs;
|
||||
private String npairs;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.osredm.codescan.entity.Nicad;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class NicadClass {
|
||||
private ClassAttr _attributes;
|
||||
private List<ClassSource> source;
|
||||
private List<String> _values;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.osredm.codescan.entity.Nicad;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class NicadClassInfo {
|
||||
private ClassInfoAttr _attributes;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.osredm.codescan.entity.Nicad;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class NicadCloneInfo {
|
||||
private CloneInfoAttr _attributes;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.osredm.codescan.entity.Nicad;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class NicadClones {
|
||||
|
||||
private List<NicadSystemInfo> systeminfo;
|
||||
private List<NicadCloneInfo> cloneinfo;
|
||||
private List<NicadRunInfo> runinfo;
|
||||
private List<NicadClassInfo> classinfo;
|
||||
@JSONField(name ="class")
|
||||
private List<NicadClass> nicadClass;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.osredm.codescan.entity;
|
||||
package com.osredm.codescan.entity.Nicad;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.osredm.codescan.entity.Nicad;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class NicadJson {
|
||||
|
||||
private List<NicadClones> clones;
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.osredm.codescan.entity.Nicad;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class NicadRunInfo {
|
||||
private RunInfoAttr _attributes;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.osredm.codescan.entity.Nicad;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class NicadSystemInfo {
|
||||
|
||||
private SystemInfoAttributes _attributes;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.osredm.codescan.entity.Nicad;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class RunInfoAttr {
|
||||
private String ncompares;
|
||||
private String cputime;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.osredm.codescan.entity.Nicad;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class SystemInfoAttributes {
|
||||
private String processor;
|
||||
private String system;
|
||||
private String granularity;
|
||||
private String threshold;
|
||||
private String minlines;
|
||||
private String maxlines;
|
||||
|
||||
|
||||
}
|
|
@ -1,8 +1,7 @@
|
|||
package com.osredm.codescan.service;
|
||||
|
||||
import com.osredm.codescan.entity.NicadInfo;
|
||||
import com.osredm.codescan.entity.Nicad.NicadInfo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public interface NicadService {
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
package com.osredm.codescan.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.osredm.codescan.config.StoreConfig;
|
||||
import com.osredm.codescan.entity.NicadInfo;
|
||||
import com.osredm.codescan.entity.Nicad.NicadClones;
|
||||
import com.osredm.codescan.entity.Nicad.NicadInfo;
|
||||
import com.osredm.codescan.entity.Nicad.NicadJson;
|
||||
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;
|
||||
|
@ -41,7 +43,6 @@ public class NicadServiceImpl implements NicadService {
|
|||
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) {
|
||||
|
@ -49,7 +50,7 @@ public class NicadServiceImpl implements NicadService {
|
|||
line1 = line;
|
||||
}
|
||||
in.close();
|
||||
int re = proc.waitFor(); //waitFor是用来显示脚本是否运行成功,1表示失败,0表示成功,还有其他的表示其他错误
|
||||
int re = proc.waitFor(); //waitFor是用来显示脚本是否运行成功,1表示失败,0表示成功,还有其他的表示其他错误
|
||||
|
||||
if (re == 0) {
|
||||
//成功
|
||||
|
@ -70,12 +71,32 @@ public class NicadServiceImpl implements NicadService {
|
|||
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");
|
||||
Process proc2;
|
||||
String[] arguments2 = new String[] {"/usr/bin/python3.6", "/root/code-scan/nicad/main.py", storeConfig.getFilePath() + time+"_functions-blind-clones/"+time+"_functions-blind-clones-0.30-classes-withsource.xml"};
|
||||
proc2 = Runtime.getRuntime().exec(arguments2);// 执行解压文件
|
||||
//用输入输出流来截取结果
|
||||
BufferedReader in2 = new BufferedReader(new InputStreamReader(proc2.getInputStream()));
|
||||
|
||||
String line3 = null;
|
||||
String line33 = null;
|
||||
while ((line3 = in2.readLine()) != null) {
|
||||
System.out.println(line3);
|
||||
line33 = line3;
|
||||
}
|
||||
in2.close();
|
||||
int re2 = proc2.waitFor();
|
||||
if (re2 == 0) {
|
||||
//转换为实体类
|
||||
JSONObject jsonObject = JSONObject.parseObject(line33);
|
||||
System.out.println(jsonObject);
|
||||
NicadJson nicadJson = JSON.toJavaObject(jsonObject,NicadJson.class);
|
||||
map.put("status",SUCCESS);
|
||||
|
||||
map.put("json",nicadJson);
|
||||
}else {
|
||||
map.put("status",FAIL);
|
||||
}
|
||||
|
||||
String s = XmlJsonUtils.xml2Json(xml);
|
||||
map.put("status",SUCCESS);
|
||||
map.put("xml",xml);
|
||||
map.put("json",s);
|
||||
return map;
|
||||
}else {
|
||||
//失败
|
||||
|
|
Loading…
Reference in New Issue