Skip to content

Commit b24c44a

Browse files
committed
Addes Instructions for Cloning and Building projects whose ASTs are to be parsed
1 parent 86ce6ab commit b24c44a

18 files changed

+1245
-0
lines changed

ProjectsToParse/BuildProjects.py

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import sys
2+
import os
3+
import datetime
4+
import subprocess
5+
6+
#https://stackoverflow.com/questions/21377520/do-a-maven-build-in-a-python-script
7+
class changeDir:
8+
def __init__(self, newPath):
9+
self.newPath = os.path.expanduser(newPath)
10+
11+
# Change directory with the new path
12+
def __enter__(self):
13+
self.savedPath = os.getcwd()
14+
os.chdir(self.newPath)
15+
16+
# Return back to previous directory
17+
def __exit__(self, etype, value, traceback):
18+
os.chdir(self.savedPath)
19+
20+
21+
def build(*args):
22+
return subprocess.check_call(['mvn'] + list(args),shell=True)
23+
#return subprocess.check_output(['mvn'] + list(args),shell=True)
24+
25+
#https://coderwall.com/p/tjc9oa/for-those-who-build-multiple-maven-projects-at-once
26+
def mvnbuild(cdir):
27+
cwd=os.getcwd()
28+
os.chdir(cdir)
29+
process = subprocess.Popen(
30+
#"mvn clean install -DskipTests=true"
31+
"mvn clean install",
32+
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
33+
)
34+
out, err = process.communicate()
35+
#log(out, dir)
36+
#print(out)
37+
errcode = process.returncode
38+
os.chdir(cwd)
39+
return (out, err, errcode)
40+
41+
42+
try:
43+
clonedprojectfolder= sys.argv[1]
44+
#mavenargumenr=sys.argv[2]
45+
projectstobuild=[ i for i in os.listdir(clonedprojectfolder) if(os.path.isdir(os.path.join(clonedprojectfolder+i)))]
46+
logfile=open('Build_log_'+str(datetime.datetime.now()),'a')
47+
48+
print("Processing projects in folder ::" + clonedprojectfolder)
49+
projcount=len(projectstobuild)
50+
failedprojcount=0
51+
processedprojcount=0
52+
print("Total projects to build "+ str(projcount))
53+
#logfile.write("Total projects to build "+ str(projcount)+"\n")
54+
55+
56+
for p in projectstobuild:
57+
path=p
58+
fullpath=os.path.join(clonedprojectfolder+path)
59+
#print(fullpath)
60+
if(os.path.isdir(fullpath)):
61+
currfilelog=open('path.log','a')
62+
try:
63+
#https://stackoverflow.com/questions/21377520/do-a-maven-build-in-a-python-script
64+
if(not(p.startswith('.'))):
65+
print("Procesiing " + path)
66+
opofbuild=mvnbuild(fullpath)
67+
if("BUILD SUCCESS" in opofbuild[0]):
68+
print("Build done for project " + path+"\n")
69+
logfile.write("Build done for project " + path+"\n")
70+
else:
71+
print("Build failed for project " + path+"\n")
72+
logfile.write("Build failed for project " + path+"\n")
73+
#logfile..write(op)
74+
'''
75+
with changeDir(fullpath):
76+
# ****** NOTE ******: using shell=True is strongly discouraged since it possesses security risks
77+
#subprocess.call(["mvn", "clean", "install"], shell=True)
78+
#opofbuild=build("clean", "install")
79+
#opofbuild=build("Compile")
80+
81+
#build("Compile")
82+
#logfile.write("Compiled project " + path+"\n")
83+
'''
84+
85+
except:
86+
print("Exception durin build or compile for project " + path+"\n")
87+
logfile.write("Exception durin build or compile for project " + path+"\n")
88+
89+
90+
91+
92+
logfile.close( )
93+
except:
94+
print(" Plese provide proper arguments in the form python BuildProjects <FOLDER PATH where projects are cloned <MAVEN command to run>")
95+
96+

ProjectsToParse/CloneProjects.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import sys
2+
import git
3+
import datetime
4+
5+
import subprocess
6+
7+
def git(*args):
8+
return subprocess.check_call(['git'] + list(args))
9+
10+
try:
11+
repourlfilename= sys.argv[1]
12+
folder_to_clonein=sys.argv[2]
13+
14+
logfile=open(repourlfilename+'_log_'+str(datetime.datetime.now()),'a')
15+
16+
print("Processing file with urls ::" + repourlfilename)
17+
repofiledata=open(repourlfilename,'r')
18+
allurls=repofiledata.readlines()
19+
filecount=len(allurls)
20+
failedfilecount=0
21+
processedfilecunt=0
22+
print("Total Files to process "+ str(filecount))
23+
logfile.write("Total Files to process "+ str(filecount)+"\n")
24+
25+
26+
for repo in allurls:
27+
repourl=repo.strip()
28+
repofolder=repo.split('/')[-1].strip()
29+
print(repofolder)
30+
print("Processing "+ repourl)
31+
try:
32+
print
33+
git('clone',repourl,folder_to_clonein+repofolder)
34+
logfile.write("Successfully processed " + repourl)
35+
processedfilecunt+=1
36+
except:
37+
print(" Failed to Clone " + repourl)
38+
logfile.write("Processein failed for " + repourl+"\n")
39+
failedfilecount+=1
40+
41+
42+
print("Files Suceessfuly procesed "+ str(processedfilecunt))
43+
logfile.write("Files Suceessfuly procesed "+ str(filecount-failedfilecount)+"\n")
44+
print("Files Failed "+ str(failedfilecount))
45+
logfile.write("Files Failed "+ str(failedfilecount)+"\n")
46+
47+
48+
logfile.close()
49+
except:
50+
print(" Plese provide proper arguments in the form python CloneProjects <FileContainingRepoURLS> <FOLDER PATH in which to be cloned>")
51+

0 commit comments

Comments
 (0)