#!/bin/bash SRCDIR="javatx-src/main/java" DESTDIR="out" JAVAC_FLAGS="-g:none -nowarn" JAVATX_COMPILER_PATH="JavaTXcompiler-1.1-jar-with-dependencies.jar" #remove all files, if the script is called with parameter "clear" if [ "$1" = "clear" ]; then rm -r "$DESTDIR" exit 0 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" ] || [ "$(stat -c "%Y" "$file")" -gt "$(stat -c "%Y" "$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" ] || [ "$(stat -c "%Y" "$file")" -gt "$(stat -c "%Y" "$class_name")" ]; then JAV_CHANGED+=("$file") JAV_CLASSES+=("$class_name") fi done if [ "${#JAV_CHANGED[@]}" -ne 0 ]; then for ((i = 0; i < "${#JAV_CHANGED[@]}"; i++)); do java -jar $JAVATX_COMPILER_PATH -d "${JAV_CLASSES[i]%/*}" -cp "$SRCDIR:$DESTDIR:target/dependencies/" "${JAV_CHANGED[i]}" done fi if [ "${#JAVA_CHANGED[@]}" -ne 0 ]; then javac -d $DESTDIR -cp "$SRCDIR:$DESTDIR:target/dependencies/*" $JFLAGS "${JAVA_CHANGED[@]}" fi