-
Notifications
You must be signed in to change notification settings - Fork 7
/
1_perturb_projects.py
49 lines (34 loc) · 1.59 KB
/
1_perturb_projects.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
#!/usr/bin/python
import sys, os, time, subprocess,fnmatch, shutil, csv,re, datetime
def perturb(bugId,repodir,rootdir):
project=bugId.split('-')[0]
bug=bugId.split('-')[1]
projectPath=repodir+'/'+bugId
checkoutCorrectVersion = 'defects4j checkout -p '+project + ' -v '+bug+'f -w '+projectPath
print(checkoutCorrectVersion)
os.system(checkoutCorrectVersion)
traveProject(projectPath)
def traveProject(projectPath):
listdirs = os.listdir(projectPath)
for f in listdirs:
if 'test' not in projectPath and 'Test' not in projectPath:
pattern = '*.java'
p = os.path.join(projectPath, f)
if os.path.isfile(p):
if 'test' not in p and fnmatch.fnmatch(f, pattern):
print(p)
#call spoon based Java pertubation programs.
callstr = 'timeout 600 java -jar ./perturbation_model/target/perturbation-0.0.1-SNAPSHOT-jar-with-dependencies.jar '
callstr+=p+' BugLab '
os.system(callstr)
print(p)
else:
traveProject(p)
if __name__ == '__main__':
bugIds = ['Lang-65','Chart-26','Math-106','Mockito-38','Time-26','Closure-134','Cli-1','Collections-25','Codec-1','Compress-1','Csv-1','Gson-1','JacksonCore-1','JacksonDatabind-1','JacksonXml-1','Jsoup-1','JxPath-1']
rootdir= '/path/to/root/SelfAPR'
repodir = rootdir+'/PerturbedSamples'
if not os.path.exists(repodir):
os.system('mkdir -p '+repodir)
for bugId in bugIds:
perturb(bugId,repodir,rootdir)