JavaTXCompilerInJavaTX/compile.sh

78 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
SRCDIR="javatx-src/main/java"
DESTDIR="out"
JAVAC_FLAGS="-g:none -nowarn"
JAVATX_COMPILER_PATH="JavaTXcompiler-2.4-jar-with-dependencies.jar"
#remove all files, if the script is called with parameter "clear"
if [ "$1" = "clean" ]; then
rm -r "$DESTDIR"
exit 0
fi
if [ "$1" != "" ]; then
echo "invalid argument: $1"
exit 1
fi
#find all .java/.jav files recursively and store them in an array
JAVA_FILES=($(find "$SRCDIR" -name "*.java"))
JAV_FILES=($(find "$SRCDIR" -name "*.jav"))
#create empty arrays for .class file paths
JAVA_CLASSES=()
JAV_CLASSES=()
JAVA_CHANGED=()
JAV_CHANGED=()
mkdir -p $DESTDIR
#fill class files arrays by subsituting .java/.jav -> .class for each file
for file in "${JAVA_FILES[@]}"; do
#substitute destination dir with source dir
class_name="$DESTDIR${file#$SRCDIR}"
#substitute *.java -> *.class
class_name="${class_name%.java}.class"
#if .class file does not exists or .class file older than .java file
if [ ! -f "$class_name" ] || [ "$(find "$file" -prune -newer "$class_name")" ]; then
JAVA_CHANGED+=("$file")
JAVA_CLASSES+=("$class_name")
fi
done
for file in "${JAV_FILES[@]}"; do
#substitute destination dir with source dir
class_name="$DESTDIR${file#$SRCDIR}"
#substitute *.jav -> *.class
class_name="${class_name%.jav}.class"
#if .class file does not exists or .class file older than .jav file
if [ ! -f "$class_name" ] || [ "$(find "$file" -prune -newer "$class_name")" ]; then
JAV_CHANGED+=("$file")
JAV_CLASSES+=("$class_name")
fi
done
if [ "${#JAV_CHANGED[@]}" -ne 0 ]; then
echo "java -jar $JAVATX_COMPILER_PATH -d $DESTDIR -cp "$SRCDIR:$DESTDIR:target/dependencies/" ${JAV_CHANGED[@]}"
java -jar $JAVATX_COMPILER_PATH -d $DESTDIR -cp "$SRCDIR:$DESTDIR:target/dependencies/" "${JAV_CHANGED[@]}"
fi
#if [ "${#JAV_CHANGED[@]}" -ne 0 ]; then
# for ((i = 0; i < "${#JAV_CHANGED[@]}"; i++)); do
# echo "java -jar $JAVATX_COMPILER_PATH -d "$DESTDIR" -cp "$SRCDIR:$DESTDIR:target/dependencies/" ${JAV_CHANGED[i]}"
# java -jar $JAVATX_COMPILER_PATH -d "$DESTDIR" -cp "$SRCDIR:$DESTDIR:target/dependencies/" "${JAV_CHANGED[i]}"
# if [ $? -eq 1 ]; then
# exit 1;
# fi
# done
#fi
#if [ "${#JAVA_CHANGED[@]}" -ne 0 ]; then
# echo "javac -d $DESTDIR -cp "$SRCDIR:$DESTDIR:target/dependencies/*" $JAVAC_FLAGS ${JAVA_CHANGED[@]}"
# javac -d $DESTDIR -cp "$SRCDIR:$DESTDIR:target/dependencies/*" $JAVAC_FLAGS "${JAVA_CHANGED[@]}"
#fi