Skip to content

Commit 6b48bff

Browse files
committed
bug fix: executing the class file containing main method only everytime with full precission
1 parent 1483e3e commit 6b48bff

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

run

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,18 @@ run() {
164164

165165
elif [[ ${FILE#*.} == java ]]; then
166166
javac "$FILE"
167-
JCF=$(find . -type f -name "*.class" -mmin -1)
168-
JCF=${JCF:2}
167+
JCF=$(find . -type f -name "*.class" -mmin -1 | cut -c 3-)
169168
if [[ $COMPILE != true ]]; then
170-
java "${JCF%%.*}"
169+
while IFS= read -r classFile
170+
do
171+
mainMethodCheck=$(grep -q "main" "$classFile" && echo "mainMethod")
172+
if [[ $mainMethodCheck == "mainMethod" ]]; then
173+
java "${classFile%%.*}"
174+
break
175+
fi
176+
done < <(printf '%s\n' "$JCF")
171177
fi
172178
if [[ $PERSISTENT != true ]]; then
173-
rm -rf ./"$JCF"
174179
find . -type f -name "*.class" -mmin -2 -exec rm -rf {} \; 2>/dev/null
175180
fi
176181

0 commit comments

Comments
 (0)