98 lines
3.1 KiB
Bash
Executable File
98 lines
3.1 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-2.5-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 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:$DESTDIR:dependencies/" ${JAV_CHANGED[@]}"
|
|
java -jar $JAVATX_COMPILER_PATH -d $DESTDIR -cp "$SRCDIR:$DESTDIR:dependencies/" "${JAV_CHANGED[@]}"
|
|
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
|
|
|
|
##TEST ENVIRONMENT##
|
|
|
|
#compile all necessary test files
|
|
javac -cp "$DESTDIR:$DEPENDENCIES/*" -d "out/tests" tests/targetast/*
|
|
javac -cp "$TESTDESTDIR:$DESTDIR:$DEPENDENCIES/*" -d "out/tests" tests/TestComplete.java
|
|
|
|
cp -r resources out/tests/resources/
|
|
|
|
cd "$TESTDESTDIR"
|
|
|
|
#run tests with junit
|
|
java -cp "../src:.:../../dependencies/*" org.junit.runner.JUnitCore TestComplete
|
|
|