-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCloseInjector.py
More file actions
36 lines (31 loc) · 1.68 KB
/
CloseInjector.py
File metadata and controls
36 lines (31 loc) · 1.68 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
import os
from Constants import CLOSE_INJECTOR_JAR
import logging
from utils import compute_p_flag
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s %(levelname)s: %(message)s",
datefmt="%Y-%m-%d %H:%M:%S"
)
class CloseInjector:
@staticmethod
def check_for_close_injector_patch(source_project_path):
"""Check if a patch was generated by the Close Injector."""
patch_file = f"{source_project_path}/src/java-parser-AutoCloseInjector.patch"
return os.path.exists(patch_file) and os.path.getsize(patch_file) > 0
@staticmethod
def run_close_injector(project_name, source_project_path, results_folder):
"""Run close injector if applicable."""
logging.info(f"Running Close Method Injector for {project_name}...")
# DEBUG
print(f"Running Close Injector for {project_name} at {source_project_path} with results folder {results_folder}")
CloseInjector.run_close_injector_plugin(project_name, source_project_path, results_folder)
@staticmethod
def run_close_injector_plugin(benchmark, benchmark_path, results_folder):
command = f"java -jar {CLOSE_INJECTOR_JAR} {results_folder}/{benchmark}.txt {benchmark_path}"
os.system(command)
if not os.path.exists(f"{benchmark_path}/src/java-parser-AutoCloseInjector.patch"):
return
os.system(f"cd {benchmark_path}/src && dos2unix java-parser-AutoCloseInjector.patch > /dev/null 2>&1")
patch_command = f"cd {benchmark_path}/src/ && patch --forward -p{compute_p_flag(benchmark_path + '/src/java-parser-AutoCloseInjector.patch')} -u --ignore-whitespace -i java-parser-AutoCloseInjector.patch"
os.system(patch_command)