forked from Mondego/SourcererJBF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjbf-config-compile.py
executable file
·93 lines (76 loc) · 3.2 KB
/
jbf-config-compile.py
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
#!/usr/bin/env python
import configparser
import os
from subprocess import run, CalledProcessError, PIPE
import simplejson as json
import sourcererjbf.compile_checker as cc
import sourcererjbf.dependency_matcher as dm
import sourcererjbf.fqn_to_jar_map_generator as ftjmg
def save_to_json(output_file, projects_build_json):
json_string = json.dumps(projects_build_json, sort_keys=True, indent=4, separators=(',', ': '))
with open(output_file, "w") as file:
file.write(json_string)
print("Saving Done")
def clean_up_all():
print("Cleaning Up All")
clean_up_directories()
clean_up_files()
print("Cleaning Done")
def clean_up_directories():
try:
output = run(["rm", "-rf", "TBUILD", "Uncompress", "builds"],
encoding='utf8',
check=True, stdout=PIPE).stdout.strip()
except CalledProcessError:
print("Cleaning Directories Interrupted")
def clean_up_files():
try:
output = run(["rm", "-rf", "badjars.txt", "badjars_*", "save_*", "fqn_to_jar.log"], encoding='utf8',
check=True, stdout=PIPE).stdout.strip()
except CalledProcessError:
print("Cleaning Files Interrupted")
if __name__ == "__main__":
config = configparser.ConfigParser()
config.read('jbf.config')
root = config.get('DEFAULT', 'root')
rebuild_from_scratch = config.getboolean('DEFAULT', 'rebuild_from_scratch')
file = config.get('DEFAULT', 'file')
output_folder = config.get('DEFAULT', 'output_folder')
output = config.get('DEFAULT', 'output')
jars = config.get('DEFAULT', 'jars')
fqn_to_jar = config.get('DEFAULT', 'fqn_to_jar')
threads = config.getint('DEFAULT', 'threads')
try_project_build = config.getboolean('DEFAULT', 'try_project_build')
verbose = config.getboolean('DEFAULT', 'verbose')
only_project_build = config.getboolean('DEFAULT', 'only_project_build')
root, infile, outdir, outfile, cc.THREADCOUNT = root, file, output_folder, output, threads
cc.JAR_REPO = jars
cc.VERBOSE = verbose
if rebuild_from_scratch and not only_project_build:
ftjmg.ROOT = jars
dm.load_fqns(jars, fqn_to_jar, threads)
if not os.path.exists("TBUILD"):
os.makedirs("TBUILD")
if rebuild_from_scratch:
projects = cc.getProjects(root, infile)
else:
projects = list()
for item in json.load(open(outfile)).values():
item["file"] = str(item["file"])
projects.append(item)
cc.make_dir(outdir, keep_old=True)
if rebuild_from_scratch:
if only_project_build:
methods = [cc.OwnBuild]
else:
methods = [cc.OwnBuild, cc.TryNewBuild, cc.EncodeFix, cc.FixMissingDeps] if try_project_build else [
cc.TryNewBuild, cc.EncodeFix, cc.FixMissingDepsWithOwnJars]
project_json = cc.main(root, projects, outdir, methods)
save_to_json(outfile, project_json)
clean_up_all()
else:
methods = [cc.build_as_is]
success_map = cc.main(root, projects, outdir, methods)
print(len([id for id in success_map if success_map[id]["success"]]), "built successfully from",
len(success_map), "projects")
clean_up_all()