1
1
package com .iast .astbenchmark .analyser .cache ;
2
2
3
- import cn .hutool .core .io .FileUtil ;
4
3
import cn .hutool .core .io .IoUtil ;
5
4
import cn .hutool .core .io .resource .ClassPathResource ;
6
5
import cn .hutool .json .JSONArray ;
7
6
import cn .hutool .json .JSONUtil ;
8
- import com .iast .astbenchmark .analyser .bean .CaseTargetBean ;
9
7
import com .google .common .collect .Maps ;
8
+ import com .iast .astbenchmark .analyser .bean .CaseTargetBean ;
9
+ import com .iast .astbenchmark .cases .AstTaintCase001 ;
10
+ import com .iast .astbenchmark .cases .AstTaintCase002 ;
11
+ import com .iast .astbenchmark .cases .AstTaintCase003 ;
12
+ import com .iast .astbenchmark .cases .AstTaintCase004 ;
13
+ import com .iast .astbenchmark .cli .tree .CaseNode ;
14
+ import com .iast .astbenchmark .cli .tree .CaseNodeTreeUtil ;
10
15
import lombok .extern .slf4j .Slf4j ;
11
16
import org .springframework .stereotype .Component ;
12
17
13
18
import javax .annotation .PostConstruct ;
14
19
import java .nio .charset .Charset ;
20
+ import java .util .Collections ;
21
+ import java .util .HashSet ;
22
+ import java .util .List ;
15
23
import java .util .Map ;
24
+ import java .util .Set ;
25
+ import java .util .stream .Collectors ;
26
+
27
+ import static com .iast .astbenchmark .analyser .cache .AnnotationProcessorUtil .buildCaseMap ;
28
+ import static com .iast .astbenchmark .analyser .cache .CaseStuctCache .leafData ;
16
29
17
30
@ Component
18
31
@ Slf4j
19
32
public class CasetargeCache {
20
- private static Map <String , CaseTargetBean > targetMap = Maps .newLinkedHashMap ();
33
+ protected static Map <String , CaseTargetBean > targetMap = Maps .newLinkedHashMap ();
34
+ protected static Map <String , CaseTargetBean > targetMap2 = Maps .newLinkedHashMap ();
21
35
22
36
@ PostConstruct
23
37
void init () {
@@ -28,33 +42,65 @@ public static void initNow() {
28
42
new CasetargeCache ().goinit ();
29
43
}
30
44
45
+ //public static void main(String[] args) {
46
+ // /**
47
+ // * json转注解,两边结果对比
48
+ // * root2,json解析的root
49
+ // * leafData2,json解析的所有叶子节点数据
50
+ // */
51
+ // CaseNode root2;
52
+ // Map<String, CaseNode> leafData2 ;
53
+ // new CasetargeCache().initNow();
54
+ // String target = IoUtil.read(new ClassPathResource("config/case_target_list.json").getStream(), Charset.forName("utf-8"));
55
+ // JSONArray array = JSONUtil.parseArray(target);
56
+ // array.stream().forEach(e -> {
57
+ // CaseTargetBean bean = JSONUtil.toBean(JSONUtil.toJsonStr(e), CaseTargetBean.class);
58
+ // targetMap2.put(bean.getCaseNo(), bean);
59
+ // });
60
+ // root2=CaseNodeTreeUtil.initRoot2();
61
+ // leafData2=CaseNodeTreeUtil.leafMap(root2);
62
+ // System.out.println(leafData.size()+"/"+ leafData2.size());
63
+ // Set<String> keySet= new HashSet<>();
64
+ // keySet.addAll(leafData2.keySet()) ;
65
+ // keySet.addAll(leafData.keySet());
66
+ // for (String key : keySet) {
67
+ // if(!leafData.containsKey(key)){
68
+ // System.out.println("注解缺少"+key);
69
+ // continue;
70
+ // }
71
+ // if(!leafData2.containsKey(key)){
72
+ // System.out.println("json缺少:"+key);
73
+ // continue;
74
+ // }
75
+ // CaseTargetBean leaf =leafData.get(key).getLeafData();
76
+ // List<String> targetData=leaf.getData().stream().map(e->e.getTag()+e.getResult()).collect(Collectors.toList());
77
+ // CaseTargetBean leaf2 =leafData2.get(key).getLeafData();
78
+ // List<String> targetData2=leaf2.getData().stream().map(e->e.getTag()+e.getResult()).collect(Collectors.toList());
79
+ // Collections.sort(targetData);
80
+ // Collections.sort(targetData2);
81
+ // if(!targetData.equals(targetData2)){
82
+ // System.out.println(key);
83
+ // }
84
+ //
85
+ // }
86
+ //
87
+ //}
31
88
private void goinit () {
32
89
if (targetMap .isEmpty ()) {
33
90
try {
34
- String target = IoUtil .read (new ClassPathResource ("config/case_target_list.json" ).getStream (),Charset .forName ("utf-8" ));
35
- //JSONArray array = JSONUtil.readJSONArray(FileUtil.file("case_target_list.json"), Charset.forName("utf-8"));
36
- JSONArray array =JSONUtil .parseArray (target );
37
- array .stream ().forEach (e -> {
38
- CaseTargetBean bean = JSONUtil .toBean (JSONUtil .toJsonStr (e ), CaseTargetBean .class );
39
- targetMap .put (bean .getCaseNo (), bean );
40
- });
41
-
91
+ buildCaseMap (AstTaintCase001 .class );
92
+ buildCaseMap (AstTaintCase002 .class );
93
+ buildCaseMap (AstTaintCase003 .class );
94
+ buildCaseMap (AstTaintCase004 .class );
95
+ CaseStuctCache .root = CaseNodeTreeUtil .initRoot ();
96
+ CaseStuctCache .leafData =CaseNodeTreeUtil .leafMap (CaseStuctCache .root );
42
97
} catch (Exception e ) {
43
98
log .error ("ERROR : Case加载失败,请检查您的case_target_list.json:{}" , e );
44
99
}
45
100
}
46
101
}
47
102
48
- //public static void main(String[] args) {
49
- // String target = IoUtil.read(new ClassPathResource("config/case_target_list.json").getStream(),Charset.forName("utf-8"));
50
- // //JSONArray array = JSONUtil.readJSONArray(FileUtil.file("case_target_list.json"), Charset.forName("utf-8"));
51
- // JSONArray array =JSONUtil.parseArray(target);
52
- // array.stream().forEach(e -> {
53
- // CaseTargetBean bean = JSONUtil.toBean(JSONUtil.toJsonStr(e), CaseTargetBean.class);
54
- // targetMap.put(bean.getCaseNo(), bean);
55
- // });
56
- // targetMap.forEach((k,v)-> System.out.println(k+"____"+v.getCaseDesc()));
57
- //}
103
+
58
104
59
105
public static CaseTargetBean getTargetByCaseKey (String key ) {
60
106
return targetMap .get (key );
0 commit comments