forked from ashley/EntropyLocalization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSourceCodeAggregation.py
143 lines (132 loc) · 5.75 KB
/
SourceCodeAggregation.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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import subprocess
import sys
import os
import ConfigParser
import re
from filecmp import dircmp
configs = {}
"""
Reads configuration file called parse_defects4j.cfg
"""
def readConfigurations():
try:
config = ConfigParser.ConfigParser()
config.read('parse_defects4j.cfg')
configs["project"] = config.get("Basic","project")
configs["projectNum"] = config.get("Basic","projectNum")
configs["version"] = config.get("Basic","version")
configs["examplesPath"] = config.get("Basic","examplesPath")
configs["srcPath"] = config.get("Basic","srcPath")
configs["copiedFiles"] = config.get("Basic", "copiedFiles")
configs["projectPath"] = config.get("Basic", "projectPath")
configs["genprogPath"] = config.get("Basic", "genprogPath")
configs["jdk7"] = configs.get("Basic", "jdk7")
configs["jdk8"] = configs.get("Basic", "jdk8")
except:
print "Error with Configuration file. Please make sure it meets these specifications: "
print "FileName: parse_defects4j.cfg File Path: same directory as diffBugs.py"
print "---CONFIG SPECIFICATION---"
print "[Basic]"
print "project = <name of projet according to Defects4j>"
print "projectNum = <number of version IDs to iterate>"
print "version = <b or f>"
print "examplesPath = <absolute path to directory with GenProg defects4j projects>"
print "srcPath = <relative path from project directory to source code path>"
print "copiedFiles = <absolute path to resulting directory>"
print "projectPath = <Absolute Path to resulting project directory>"
print "genprogPath = <Absolute Path to GenProg4java>"
print "jdk7 = <Absolute Path to JVM 7>"
print "jdk8 = <Absolute Path to JVM 8>"
print "------"
sys.exit()
"""
Parses defect4j info command
@param {String} bugID; index of bug version
@return {Dictionary} Keys are file names, Values are file paths.
"""
def defects4jInfo(bugID):
bashCommand = "defects4j info -p " + configs["project"] + " -b " + bugID
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
output, error = process.communicate()
#Parsing default defects4j info command
fileStrings = ["%s%s%s" % (configs["srcPath"],i[3:].replace('.','/'), ".java") for i in
output.split("--------------------------------------------------------------------------------")
[-2].strip('\n').split("\n")[1:]
]
fileNames = [i.split('/')[-1] for i in fileStrings]
filePackage = dict(zip(fileNames, fileStrings))
return filePackage
"""
Checkout fixed project into Example directory
@param {String} bugID; index of bug version
"""
def checkoutFixedProject(bugID):
bashCommand = ''.join([
"defects4j checkout -p ", configs["project"],
" -v ", bugID,
"f -w ", configs["examplesPath"],configs["project"], bugID, "F"
])
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
output, error = process.communicate()
configs["fixedPath"] = configs["examplesPath"] + configs["project"] + bugID + "F"
"""
Bash command to checkout Defects4j projects with GenProg configs. Follow GenProg installation before executing
@param {String} bugID; index of bug version
"""
def checkoutGenProgDefects4j(bugID):
bashCommand = ''.join([
"bash ", configs["genprogPath"], "/defects4j-scripts/prepareBug.sh ", configs["project"], " ",
bugID, " humanMade 1 ",
configs["examplesPath"], " " ,
configs["jdk7"] + " " + configs["jdk8"]
])
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
output, error = process.communicate()
"""
Bash copies modified files to Copies directory
@param {String} bugID; index of bug version
@param {List} filePaths: list of relative paths
"""
def copyModifiedFiles(filePaths, bugID):
if not os.path.lexists(configs["projectPath"]):
os.makedirs(configs["projectPath"])
#Multiple files may have been modified in each version, hence this iteration
for name, path in filePaths.items():
buggyCommand = ''.join([
"scp ", configs["examplesPath"],
configs["project"].lower(),
bugID, "Buggy/",
path,
" ",
configs["projectPath"], "/",
bugID, "/",
"b", "/",
name
])
fixedCommand = ''.join([
"scp ", configs["fixedPath"] ,"/",
path,
" ",
configs["projectPath"], "/",
bugID, "/",
"/f/",
name
])
if not os.path.lexists(configs["projectPath"]+"/"+bugID):
os.makedirs(configs["projectPath"]+"/"+bugID)
if not os.path.lexists(configs["projectPath"]+"/"+bugID+"/b"):
os.makedirs(configs["projectPath"]+"/"+bugID+"/b")
if not os.path.lexists(configs["projectPath"]+"/"+bugID+"/f"):
os.makedirs(configs["projectPath"]+"/"+bugID+"/f")
process = subprocess.Popen(buggyCommand.split(), stdout=subprocess.PIPE)
output, error = process.communicate()
process = subprocess.Popen(fixedCommand.split(), stdout=subprocess.PIPE)
output, error = process.communicate()
def main():
readConfigurations()
for i in range(1,int(configs["projectNum"])+1):
i = str(i)
checkoutGenProgDefects4j(i)
checkoutFixedProject(i)
copyModifiedFiles(defects4jInfo(i), i)
main()