Skip to content

Commit eada656

Browse files
committed
Add_Scripts
1 parent c0c117c commit eada656

File tree

4 files changed

+145
-1
lines changed

4 files changed

+145
-1
lines changed

Scripts_Data/Build/BuildProjects.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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(dir):
27+
os.chdir(dir)
28+
process = subprocess.Popen(
29+
#"mvn clean install -DskipTests=true"
30+
"mvn clean install",
31+
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
32+
)
33+
out, err = process.communicate()
34+
#log(out, dir)
35+
#print(out)
36+
errcode = process.returncode
37+
return (out, err, errcode)
38+
39+
40+
try:
41+
clonedprojectfolder= sys.argv[1]
42+
#mavenargumenr=sys.argv[2]
43+
except:
44+
print(" Plese provide proper arguments in the form python BuildProjects <FOLDE PATH where projects are cloned <MAVEN command to run>")
45+
46+
47+
projectstobuild=os.listdir(clonedprojectfolder)
48+
logfile=open('Build_log_'+str(datetime.datetime.now()),'a')
49+
50+
print("Processing projects in folder ::" + clonedprojectfolder)
51+
projcount=len(projectstobuild)
52+
failedprojcount=0
53+
processedprojcount=0
54+
#print("Total projects to build "+ str(projcount))
55+
#logfile.write("Total projects to build "+ str(projcount)+"\n")
56+
57+
58+
for dir in projectstobuild:
59+
path=dir
60+
fullpath=os.path.join(clonedprojectfolder+path)
61+
#print(fullpath)
62+
if(os.path.isdir(fullpath)):
63+
currfilelog=open('path.log','a')
64+
try:
65+
#https://stackoverflow.com/questions/21377520/do-a-maven-build-in-a-python-script
66+
if(not(dir.startswith('.'))):
67+
print("Procesiing " + path)
68+
opofbuild=mvnbuild(fullpath)
69+
if("BUILD SUCCESS" in opofbuild[0]):
70+
print("Build done for project " + path+"\n")
71+
logfile.write("Build done for project " + path+"\n")
72+
else:
73+
print("Build failed for project " + path+"\n")
74+
logfile.write("Build failed for project " + path+"\n")
75+
'''
76+
with changeDir(fullpath):
77+
# ****** NOTE ******: using shell=True is strongly discouraged since it possesses security risks
78+
#subprocess.call(["mvn", "clean", "install"], shell=True)
79+
#opofbuild=build("clean", "install")
80+
#opofbuild=build("Compile")
81+
82+
#build("Compile")
83+
#logfile.write("Compiled project " + path+"\n")
84+
'''
85+
86+
except:
87+
print("Exception durin build or compile for project " + path+"\n")
88+
logfile.write("Exception durin build or compile for project " + path+"\n")
89+
90+
91+
92+
93+
logfile.close( )

Scripts_Data/Clone/CloneProjects.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
except:
14+
print(" Plese provide proper arguments in the form python CloneProjecs <FileContainingRepoURLS> <FOLDE PATH in which to be cloned>")
15+
16+
logfile=open(repourlfilename+'_log_'+str(datetime.datetime.now()),'a')
17+
18+
print("Processing file with urls ::" + repourlfilename)
19+
repofiledata=open(repourlfilename,'r')
20+
allurls=repofiledata.readlines()
21+
filecount=len(allurls)
22+
failedfilecount=0
23+
processedfilecunt=0
24+
print("Total Files to process "+ str(filecount))
25+
logfile.write("Total Files to process "+ str(filecount)+"\n")
26+
27+
28+
for repo in allurls:
29+
repourl=repo.strip()
30+
repofolder=repo.split('/')[-1].strip()
31+
print(repofolder)
32+
print("Processing "+ repourl)
33+
try:
34+
print
35+
git('clone',repourl,folder_to_clonein+repofolder)
36+
logfile.write("Successfully processed " + repourl)
37+
processedfilecunt+=1
38+
except:
39+
print(" Failed to Clone " + repourl)
40+
logfile.write("Processein failed for " + repourl+"\n")
41+
failedfilecount+=1
42+
43+
44+
print("Files Suceessfuly procesed "+ str(processedfilecunt))
45+
logfile.write("Files Suceessfuly procesed "+ str(filecount-failedfilecount)+"\n")
46+
print("Files Failed "+ str(failedfilecount))
47+
logfile.write("Files Failed "+ str(failedfilecount)+"\n")
48+
49+
50+
logfile.close()

javacodeanalyzer/src/Client/AnalyzeFilesClient.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public static void main(String args[])
5757
String ClonedProjectsFolder=args[4];
5858
AnalyzeFilesClient.clonedprojectsfolder=ClonedProjectsFolder+"/";
5959
//AnalyzeFilesClient.clonedprojectsfolder=rootd+"/";
60+
//ASUMMPTION
6061
AnalyzeFilesClient.sourcepathfinder="/src/main/java/";
6162

6263
//PARSE FILES

javacodeanalyzer/src/astparsing/BaselineBugramVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void setTrace(String trace_elemt)
3636

3737
public void addTOTrace(String trace_elemt)
3838
{
39-
System.out.println(trace_elemt);
39+
//System.out.println(trace_elemt);
4040
if(trace_elemt.contains("::UNRESOLVEBLK::"))
4141
{
4242
this.unresolvedelmt=true;

0 commit comments

Comments
 (0)