forked from tuhh-softsec/vul4j
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmetadata_generator.py
More file actions
128 lines (114 loc) · 4.79 KB
/
metadata_generator.py
File metadata and controls
128 lines (114 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import csv
import json
import os
import shutil
DATASET_PATH = os.path.join(os.getcwd(), "dataset", "vul4j_dataset.csv")
result = []
id = 0
with open(DATASET_PATH) as f:
reader = csv.DictReader(
f,
delimiter=",",
)
for row in reader:
vul_id = row["vul_id"].strip()
cve_id = row["cve_id"].strip()
repo_slug = row["repo_slug"].strip().split("/")[0]
build_system = row["build_system"].strip()
compliance_level = int(row["compliance_level"].strip())
compile_cmd = row["compile_cmd"].strip()
test_all_cmd = row["test_all_cmd"].strip()
test_cmd = row["test_cmd"].strip()
cmd_options = row["cmd_options"].strip()
failing_module = row["failing_module"].strip()
src_java_dir = row["src"].strip()
src_classes_dir = row["src_classes"].strip()
test_java_dir = row["test"].strip()
test_classes_dir = row["test_classes"].strip()
human_patch_url = row["human_patch"].strip()
all_dependencies_jar_path = os.path.join(
"src", "target", "all-dependencies.jar"
)
if failing_module != "root" and failing_module != "":
src_java_dir = os.path.join(failing_module, src_java_dir)
src_classes_dir = os.path.join(failing_module, src_classes_dir)
test_java_dir = os.path.join(failing_module, test_java_dir)
test_classes_dir = failing_module + "/" + test_classes_dir
all_dependencies_jar_path = os.path.join(
"src", failing_module, "target", "all-dependencies.jar"
)
else:
failing_module = ""
failing_tests = set()
for failing_test in row["failing_tests"].strip().split(","):
failing_tests.add(failing_test.split("#")[0])
if row["build_system"].strip().lower() == "maven":
all_dependencies_jar_path_lst = [all_dependencies_jar_path]
else:
all_dependencies_jar_path_lst = []
# create dep.sh script
# script_content = "#!/bin/bash\n"
# if compliance_level == '7':
# script_content += "export JAVA_HOME=$(echo $JAVA7_HOME)\n"
# else:
# script_content += "export JAVA_HOME=$(echo $JAVA8_HOME)\n"
# path_to_create = os.path.join(os.getcwd(), row['cve_id'].strip(), row['vul_id'].strip())
# os.makedirs(path_to_create, 0o775, exist_ok=True)
# with open(os.path.join(path_to_create, "deps.sh"), "w") as fd:
# fd.write(script_content)
# os.remove(os.path.join(path_to_create, "deps.sh"))
id += 1
result.append(
{
"id": id,
"subject": repo_slug,
"bug_id": cve_id,
"vul4j_id": vul_id,
"failing_module": failing_module,
"source_directory": src_java_dir,
"class_directory": src_classes_dir,
"test_directory": test_java_dir,
"test_class_directory": test_classes_dir,
"java_version": compliance_level,
"build_system": row["build_system"].strip().lower(),
"dependencies": all_dependencies_jar_path_lst,
"compile_cmd": f"{compile_cmd} {cmd_options}",
"test_all_cmd": test_all_cmd,
"line_numbers": [],
"failing_test_identifiers": list(failing_tests),
"passing_test_identifiers": [],
"count_neg": len(failing_tests),
"count_pos": 0,
"test_timeout": 5,
"build_script": "build_subject",
"clean_script": "clean_subject",
"config_script": "config_subject",
"test_script": "test_subject",
"lanuage": "java",
"src": {
"root_abspath": "/experiment/{subject}/{bug_id}/src".format(
subject=repo_slug, bug_id=cve_id
),
"entrypoint": {
# "file": entry["source_file"]
# if entry.get("language", "_") != "java"
# else (
# (
# "src/main/java/"
# if "src/main/java/" not in entry["source_file"]
# else ""
# )
# + entry["source_file"][:-5].replace(".", "/")
# + ".java"
# ),
# "function": "main",
},
},
"output_dir_abspath": "/output",
}
)
root_project = os.getcwd()
os.chdir(root_project)
x = open("meta-data.json", "w")
x.write(json.dumps(result, indent=4))
x.close()