Compile Java during make, not during tests

Re-organised all Java source code under the java-api subdirectory, which
also contains a Makefile.in that performs the Java compilation.  This
makefile is only invoked if ./configure finds a working Java compiler.
This commit is contained in:
Andrew Bettison 2016-11-08 14:51:15 +10:30
parent a8867df1b0
commit e769af0067
91 changed files with 80 additions and 15 deletions

3
.gitignore vendored
View File

@ -35,3 +35,6 @@ test.*.log
/testlog/
/coverage_html/
*.info
/java-api/Makefile
/java-api/classes/
/java-api/testclasses/

View File

@ -85,6 +85,8 @@ CFLAGS+=-DSHA2_USE_INTTYPES_H -D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=1 -D_
CFLAGS+=-D_DARWIN_C_SOURCE
CFLAGS_SQLITE= @CFLAGS_SQLITE@
JAVAC= @JAVAC@
INSTALL= install
INSTALL_PROGRAM=$(INSTALL)
INSTALL_DATA= $(INSTALL) -m 644
@ -124,6 +126,30 @@ clean:
libmonitorclient.so libmonitorclient.a \
tfw_createfile directory_service fakeradio simulator serval-tests
# Only provide Java targets if the Java compiler is available.
ifneq ($(JAVAC),)
all: java-api
clean: java-api-clean
.PHONY: java-api java-api-clean
ifneq ($(SOURCE_PREFIX:/%=),)
SOURCE_PREFIX_JAVA_API= $(SOURCE_PREFIX)../java-api/
else
SOURCE_PREFIX_JAVA_API= $(SOURCE_PREFIX)
endif
java-api:
@mkdir -p java-api
cd java-api && $(MAKE) SOURCE_PREFIX=$(SOURCE_PREFIX_JAVA_API) all
java-api-clean:
cd java-api 2>/dev/null && $(MAKE) SOURCE_PREFIX=$(SOURCE_PREFIX_JAVA_API) clean
endif # $(JAVAC)
# Source code test coverage support -- see doc/Testing.md
.PHONY: covzero covinit covhtml is_built_with_coverage has_coverage_data

View File

@ -247,4 +247,5 @@ AC_SUBST([CONFIG_H], [config.h])
AC_OUTPUT([
Makefile
testconfig.sh
java-api/Makefile
])

31
java-api/Makefile.in Normal file
View File

@ -0,0 +1,31 @@
# Makefile.in for Serval DNA Java API
# vim: noet ts=8 sts=0 sw=8
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
sbindir=@sbindir@
sysconfdir=@sysconfdir@
localstatedir=@localstatedir@
JAVAC = @JAVAC@
CLASSDIR = classes
TESTCLASSDIR = testclasses
.PHONY: all check clean classes testclasses
all: check classes testclasses
check:
@if [ -z "$(JAVAC)" ]; then echo "No java compiler configured" >&2; exit 1; fi
@if ! $(JAVAC) -version >/dev/null; then echo "Java compiler not executable" >&2; exit 1; fi
classes:
@mkdir -p $(CLASSDIR)
find $(SOURCE_PREFIX)src -name '*.java' | xargs $(JAVAC) -Xlint:unchecked -d $(CLASSDIR)
testclasses: classes
@mkdir -p $(TESTCLASSDIR)
find $(SOURCE_PREFIX)test -name '*.java' | xargs $(JAVAC) -Xlint:unchecked -d $(TESTCLASSDIR) -classpath $(CLASSDIR)
clean:
@$(RM) -r $(CLASSDIR) $(TESTCLASSDIR)

View File

@ -1,5 +1,6 @@
# Definitions for test suites using Java.
# Copyright 2014 Serval Project Inc.
# Copyright 2014-2015 Serval Project Inc.
# Copyright 2016 Flinders University
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -15,7 +16,13 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
source "${0%/*}/../testconfig.sh"
testdefs_java_sh=$(abspath "${BASH_SOURCE[0]}")
java_source_root="${testdefs_java_sh%/*}"
java_build_root="$java_source_root"
java_classdir="$java_build_root/java-api/classes"
java_testclassdir="$java_build_root/java-api/testclasses"
source "$java_build_root/testconfig.sh"
# Utility function for setting up servald JNI fixtures:
# - check that libservaldaemon.so is present
@ -25,13 +32,10 @@ setup_servald_so() {
export LD_LIBRARY_PATH="$servald_build_root"
}
compile_java_classes() {
assert --message='Java compiler was detected by ./configure' type -p "$JAVAC" >/dev/null
mkdir classes
assert find "$servald_source_root"/java* -name *.java | xargs $JAVAC -Xlint:unchecked -d classes
assert [ -r classes/org/servalproject/servaldna/ServalDCommand.class ]
assert [ -r classes/org/servalproject/servaldna/IJniResults.class ]
assert [ -r classes/org/servalproject/test/ServalDTests.class ]
assert_java_classes_exist() {
assert [ -r "$java_classdir/org/servalproject/servaldna/ServalDCommand.class" ]
assert [ -r "$java_classdir/org/servalproject/servaldna/IJniResults.class" ]
assert [ -r "$java_testclassdir/org/servalproject/test/ServalDTests.class" ]
}
_executeJava() {
@ -45,7 +49,7 @@ _executeJava() {
*) break;;
esac
done
"$func" "${opts[@]}" java "-Djava.library.path=$LD_LIBRARY_PATH" -classpath "$PWD/classes" "$@"
"$func" "${opts[@]}" java "-Djava.library.path=$LD_LIBRARY_PATH" -classpath "$java_classdir:$java_testclassdir" "$@"
}
_run() {
@ -79,7 +83,7 @@ unset_vars_with_prefix() {
}
# Utility function:
#
#
# unpack_vars PREFIX TEXT
#
# parses the given TEXT which must have the form:

View File

@ -29,7 +29,7 @@ setup() {
set debug.verbose 1 \
set log.console.level debug
assert_echo_works
compile_java_classes
assert_java_classes_exist
setup_servald_so
}

View File

@ -25,7 +25,7 @@ source "${0%/*}/../testdefs_java.sh"
setup() {
setup_servald
setup_servald_so
compile_java_classes
assert_java_classes_exist
set_instance +A
set_keyring_config
set_extra_config

View File

@ -26,7 +26,7 @@ source "${0%/*}/../testdefs_meshms.sh"
setup() {
setup_servald
setup_servald_so
compile_java_classes
assert_java_classes_exist
set_instance +A
executeOk_servald config \
set log.console.level debug \

View File

@ -26,7 +26,7 @@ source "${0%/*}/../testdefs_rhizome.sh"
setup() {
setup_servald
setup_servald_so
compile_java_classes
assert_java_classes_exist
set_instance +A
executeOk_servald config \
set log.console.level debug \