-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grader2.0.sh
executable file
·142 lines (115 loc) · 4.48 KB
/
Grader2.0.sh
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
set x
# You may need to make this file executable (chmod 775 Grader2.0.sh)
# To run just do (./Grader2.0.sh or sh Grader2.0.sh)
#Path for jUnits test cases for grading (U need to change this)
graderFiles="../hw03_grading/src/edu/iastate/cs228/hw03/grading/*.java"
#Path for provided solution (U need to change this)
solutionFiles="../hw03_grading/src/edu/iastate/cs228/hw03/solution/*.java"
#class which will run the test cases (Do NOT change this, except hw02 part)
graderClass="edu.iastate.cs228.hw03.grading.AutomatedJUnitRunner"
#Submission package files (Do NOT change this, except hw02 part)
subPkgFiles="edu/iastate/cs228/hw03/*.java"
#Do not change this
junitPath="junit-platform-console-standalone-1.3.0.jar"
#This is temp folder: Do not change this
tmpFolder="tmp"
#This is location of students "zip" submissions. (U need to change this)
subPath="../submissions"
#Output will be created in this folder. Do not change this.
grades="grades"
#Do NOT change this, except hw02 part
package="edu/iastate/cs228/hw03/"
#Splited into two parts as output is multiline which is non-trivial to handle with sed
#PLEASE Change contents inside Header (change it to your name)
templateFileFooter="CommentTemplateFooter.txt"
templateFileHeader="CommentTemplateHeader.txt"
#If tmp folder is not there it will create it.
if [ ! -d "$tmpFolder" ]
then
mkdir $tmpFolder
fi
if [ ! -d "$grades" ]
then
mkdir $grades
fi
echo "Compiling class to check author tags"
javac -d . extractStuff.java
counter=1
for subZip in "$subPath"/*.zip
do
echo ".................................................."
echo $counter". Starting with $subZip. Copying to tmp"
counter=$((counter+1))
#This if loop is only there if we need to restart the script.
#Also it assumes each time files will be picked in same order.
# if [ $counter -lt 33 ]; then
# echo "Already checked so continuing."
# continue
# fi
cp "$subZip" "$tmpFolder"/
sName=$(basename "$subZip" ".zip")
unzip "$tmpFolder"/"$sName" -d "$tmpFolder"/
mkdir -p "$tmpFolder/$package"
find $tmpFolder -type f -name '*.java' -exec cp {} "$tmpFolder/$package" \;
echo "Now ensuring that BagInterface.java exist" #TODO: In future take it from =ignorefiles list
if [ ! -f "$tmpFolder/$package/BagInterface.java" ]
then
echo "Copying BagInterface as it didn't exist."
cp "BagInterface.java" "$tmpFolder/$package/"
fi
echo "#Compile the submission files into tmp" #Including junit as well for future cases.
javac -d "$tmpFolder"/ -cp "$junitPath:$tmpFolder"/ "$tmpFolder"/$subPkgFiles
echo "#Now Compile the solution files into tmp"
javac -d "$tmpFolder"/ -cp "$junitPath:$tmpFolder"/ $solutionFiles
echo "#Now Compile the grading files into tmp"
javac -d "$tmpFolder"/ -cp "$junitPath:$tmpFolder"/ $graderFiles
echo "#Now actually running the test script"
outpt="$(java -cp $junitPath:$tmpFolder/ $graderClass)"
scoreW=${outpt##* }
#https://stackoverflow.com/questions/3162385/how-to-split-a-string-in-shell-and-get-the-last-field
score=$(cut -d'.' -f1 <<<$scoreW)
#integer expression expected
echo "Score is: "$score
cp $templateFileHeader "$grades/$sName".txt
echo "Template copied to $grades/$sName".txt
echo "$outpt" >> "$grades/$sName".txt
cat $templateFileFooter >> "$grades/$sName".txt
sed -i "s/PLACEHOLDER02/$score/g" "$grades/$sName".txt
autoComment="Need to focus a bit more on testing."
if [ $score -lt 50 ]
then
autoComment="Put in more effort please."
fi
if [ $score -gt 70 ]
then
autoComment="Nice! Could be better with more testing."
fi
if [ $score -gt 80 ]
then
autoComment="Good work. Could have been perfect with little more testing."
fi
if [ $score -gt 85 ]
then
autoComment="Good work!"
fi
if [ $score -gt 89 ]
then
autoComment="Awesome!"
fi
#Adding a score of 10 by default as most students will do it correctly.
#But please note u need to change this as per what students have really done.
score=$((score+0))
sed -i "s/PLACEHOLDER03/$score/g" "$grades/$sName".txt
sed -i "s/PLACEHOLDER04/$autoComment/g" "$grades/$sName".txt
echo "$score $sName "$((counter-1)) >> "$grades"/scores.txt
echo "Output added. Now checking for tags"
echo "#Checking the author tag here."
authorImports="$(java extractStuff $tmpFolder/$package $sName)"
echo "Op is: $authorImports"
echo "$authorImports" >> "$grades/$sName".txt
echo "Output added. Now cleaning the tmp folder"
rm -rf $tmpFolder/*
rm -rf $tmpFolder/.*
#To delete hidden files.
#break
done