Skip to content

Instantly share code, notes, and snippets.

@samsartor
Last active August 29, 2015 14:15
Show Gist options
  • Save samsartor/d859f251dc7a6e4b56d9 to your computer and use it in GitHub Desktop.
Save samsartor/d859f251dc7a6e4b56d9 to your computer and use it in GitHub Desktop.
A Program to Quickly Test Java
#!/bin/bash
function error
{
echo "Invalid Jive Command!"
usage
exit
}
function usage
{
echo "Usage Comming Soon!"
}
cd ~
if [ "$1" = "" ]
then
usage
exit
fi
IMPORTS=""
FUNCS=""
CLASS="JiveTempClass"
MAINCODE=""
KEEP=0
N=$'\n'
T=$'\t'
while [ "$1" != "" ]
do
if [ "$1" = "-m" ] || [ "$1" = "-main" ]
then
MAINCODE="${MAINCODE}$2${N}"
shift 1
elif [ "$1" = "-f" ] || [ "$1" = "-func" ] || [ "$1" = "-function" ] || [ "$1" = "-method" ]
then
PAR="${4}... pars"
if [ "$4" = "void" ]
then
PAR=""
fi
FUNCS="${FUNCS}${N}${N}${T}public static $2 ${3}(${PAR})${N}${T}{${N}${T}${T}${5}${N}${T}}"
shift 4
elif [ "$1" = "-i" ] || [ "$1" = "-import" ]
then
IMPORTS="${IMPORTS}import ${2};${N}"
shift 1
elif [ "$1" = "-x" ] || [ "$1" = "-keep" ]
then
KEEP=$2
declare -i KEEP
CLASS="$3"
shift 2
else
error
fi
shift
done
echo "$IMPORTS" > "${CLASS}.java"
echo "class ${CLASS}${N}{" >> "${CLASS}.java"
echo "${T}public static void main(String[] args)${N}${T}{${N}${T}${T}${MAINCODE}${T}}${FUNCS}" >> "${CLASS}.java"
echo "}" >> "${CLASS}.java"
javac "${CLASS}.java"
java "${CLASS}"
if [ $(($KEEP % 2)) -eq 0 ]
then
rm "${CLASS}.java"
fi
if [ $(($KEEP % 4)) -lt 2 ]
then
rm "${CLASS}.class"
fi
exit
@samsartor
Copy link
Author

jive -m "firstTalk(); secondTalk(0, 1, 2);" -i 'java.util.*' -f "void" "firstTalk" "void" "for(int i = 0; i < 10; i++) { System.out.println(i); }" -f "Object" "secondTalk" "int" 'for(int i : pars) { System.out.println("I was passed the number " + i + "!"); } return null;' -x 3 TestClass
Gives:

0
1
2
3
4
5
6
7
8
9
I was passed the number 0!
I was passed the number 1!
I was passed the number 2!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment