forked from tdurieux/defects4j-repair-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
detectJavaVersion.py
executable file
·86 lines (81 loc) · 3.45 KB
/
detectJavaVersion.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
#!/usr/bin/env python
import os
import re
import json
from core.Config import conf
rootProjects = conf.projectsRoot
rootProjectsData = os.path.join(conf.defects4jRepairRoot, "src", "python", "data", "projects")
for project in sorted(os.listdir(rootProjects)):
projectPath = os.path.join(rootProjects, project)
projectDataPath = os.path.join(rootProjectsData, project.lower() + ".json")
print(project)
if not os.path.exists(projectDataPath):
continue
if os.path.isfile(projectPath):
continue
data_file = open(projectDataPath, "r+")
data = json.load(data_file)
if "complianceLevel" not in data:
data["complianceLevel"] = {}
for bugId in sorted(os.listdir(projectPath)):
bugPath = os.path.join(projectPath, bugId)
if os.path.isfile(bugPath):
continue
propertiesPath = os.path.join(bugPath, "pom.xml")
if not os.path.exists(propertiesPath):
propertiesPath = os.path.join(bugPath, "project.properties")
if not os.path.exists(propertiesPath):
propertiesPath = os.path.join(bugPath, "default.properties")
if not os.path.exists(propertiesPath):
propertiesPath = os.path.join(bugPath, "ant/build.xml")
if not os.path.exists(propertiesPath):
propertiesPath = os.path.join(bugPath, "build.xml")
if not os.path.exists(propertiesPath):
propertiesPath = None
target = None
source = None
if propertiesPath:
with open(propertiesPath) as file:
for line in file:
m = re.search('compile.target ?= ?1.([0-9])', line)
if m:
target = m.group(1)
else:
m = re.search('target>1.([0-9])', line)
if m:
target = m.group(1)
else:
m = re.search('target="1.([0-9])"', line)
if m:
target = m.group(1)
else:
m = re.search('name="ant.build.javac.target" value="1.([0-9])"', line)
if m:
target = m.group(1)
m = re.search('compile.source ?= ?1.([0-9])', line)
if m:
source = m.group(1)
else:
m = re.search('source>1.([0-9])', line)
if m:
source = m.group(1)
else:
m = re.search('source="1.([0-9])"', line)
if m:
source = m.group(1)
else:
m = re.search('name="ant.build.javac.source" value="1.([0-9])"', line)
if m:
source = m.group(1)
print bugId, source, target
if target is None:
target = "7"
source = "7"
data["complianceLevel"][bugId.split("_")[1]] = {
"target": int(target),
"source": int(source)
}
data_file.seek(0)
data_file.write(json.dumps(data, indent=4, sort_keys=True))
data_file.truncate()
data_file.close()