Skip to content

Commit d438197

Browse files
committed
java compilation support reworked: added env EJUDGE_MAIN_CLASS, EJUDGE_CLASSPATH
1 parent 8353466 commit d438197

File tree

1 file changed

+55
-4
lines changed

1 file changed

+55
-4
lines changed

scripts/javac.in

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#!/bin/bash
2-
# $Id$
3-
# Copyright (c) 2004-2008 Alexander Chernov <[email protected]>
2+
# Copyright (c) 2004-2023 Alexander Chernov <[email protected]>
43

54
# Usage: javac in-file out-file
6-
# The working dir must not contain any .class files.
75

86
# using EJUDGE_FLAGS we may pass additional flags
97

@@ -45,4 +43,57 @@ then
4543
fi
4644

4745
rm -f *.class
48-
exec "${libexecdir}/ejudge/lang/ej-javac" "${infile}" "${outfile}" "${JAVACRUN}" "${JAVAVER}" "${MY_JAVA_HOME}"
46+
47+
JAVA_CLASSNAME="${libexecdir}/ejudge/lang/java-classname.jar"
48+
49+
# Extract the class name from the source file
50+
USER_CLASS=`"${JAVARUN}" -jar "${JAVA_CLASSNAME}" "${infile}"`
51+
if [ "${USER_CLASS}" = "" ]
52+
then
53+
echo "failed to detect java class name" >&2
54+
exit 1
55+
fi
56+
57+
USER_SOURCE="${USER_CLASS}.java"
58+
59+
if ! mv "${infile}" "${USER_SOURCE}"
60+
then
61+
echo "failed to rename source file" >&2
62+
exit 1
63+
fi
64+
65+
if [ "${EJUDGE_MAIN_CLASS}" != "" ]
66+
then
67+
MAIN_CLASS="${EJUDGE_MAIN_CLASS}"
68+
else
69+
MAIN_CLASS="${USER_CLASS}"
70+
fi
71+
72+
CPOPT=
73+
if [ "${EJUDGE_CLASSPATH}" != "" ]
74+
then
75+
CPOPT=" -cp ${EJUDGE_CLASSPATH} "
76+
fi
77+
78+
"${JAVACRUN}" --target "${JAVAVER}" ${CPOPT} *.java || exit 1
79+
80+
D=`dirname "${JAVARUN}"`
81+
if [ "$D" = "." ]
82+
then
83+
JARRUN=jar
84+
else
85+
JARRUN="${D}/jar"
86+
fi
87+
88+
MOPT=
89+
if [ "${EJUDGE_CLASSPATH}" != "" ]
90+
then
91+
echo "Class-Path: ${EJUDGE_CLASSPATH}" > manifest.txt
92+
MOPT=" -m manifest.txt "
93+
fi
94+
95+
"${JARRUN}" -c -f "${outfile}" ${MOPT} -e "${MAIN_CLASS}" *.class || exit 1
96+
97+
exit 0
98+
99+
#exec "${libexecdir}/ejudge/lang/ej-javac" "${infile}" "${outfile}" "${JAVACRUN}" "${JAVAVER}" "${MY_JAVA_HOME}"

0 commit comments

Comments
 (0)