JavaTXCompilerInJavaTXNoMaven/compile.sh

92 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
SRCDIR="javatx-src/main/java"
DESTDIR="out/src"
TESTDESTDIR="out/tests"
DEPENDENCIES="dependencies"
JAVAC_FLAGS="-g:none -nowarn"
JAVATX_COMPILER_PATH="JavaTXCompiler.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 and store paths in an array
#note: somehow absolute paths don't work correctly with find -newer
#JAVA_FILES=($(find "$SRCDIR" -name "*.java" -exec realpath {} \;))
#JAV_FILES=($(find "$SRCDIR" -name "*.jav" -exec realpath {} \;))
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:dependencies/" ${JAV_CHANGED[@]}"
java -jar $JAVATX_COMPILER_PATH -d $DESTDIR -cp "$SRCDIR:dependencies/" "${JAV_CHANGED[@]}"
if [ $? -ne 0 ]; then
echo "Fehler beim Kompilieren der Jav-Dateien. Beende das Skript."
exit 1
fi
fi
#if [ "${#JAV_CHANGED[@]}" -ne 0 ]; then
# for ((i = 0; i < "${#JAV_CHANGED[@]}"; i++)); do
# echo "java -jar $(realpath $JAVATX_COMPILER_PATH) -d $(realpath "$DESTDIR") -cp "$(realpath $SRCDIR):$(realpath $DESTDIR):$(realpath "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:dependencies/*" $JAVAC_FLAGS ${JAVA_CHANGED[@]}"
javac -d $DESTDIR -cp "$SRCDIR:$DESTDIR:dependencies/*" $JAVAC_FLAGS "${JAVA_CHANGED[@]}"
fi
# if [ $? -eq 0 ]; then
# ./test.sh
# fi