# Work in progress idea for java.make extension to create execution templates
notzed.zcl.demo_DEMOS=au.notzed.zcl.tools.clinfo
-notzed.zcl.fxdemo_DEMOS=fxdemo.fract.Mandelbrot
+notzed.zcl.fxdemo_DEMOS=fxdemo.fract.Mandelbrot fxdemo.fract.Test
DEMOFLAGS=--add-exports jdk.incubator.foreign/jdk.incubator.foreign.unsafe=notzed.zcl
-m $1/$2 $(ARGV)
endef
$(foreach module,$(java_MODULES),$(foreach demo,$($(module)_DEMOS),$(eval $(call java_demo,$(module),$(demo),$(lastword $(subst ., ,$(demo)))))))
+
+# ######################################################################
+# Work in progress idea for java.make extension to download maven jars
+
+# server=url, then define server_JARS=publisher:artifact:version
+maven_HOSTS=central=https://repo1.maven.org/maven2
+
+central_JARS=junit:junit:4.12 \
+ org.hamcrest:hamcrest-core:1.3
+
+# owner package version host
+define maven_func=
+.lib/$2-$3.jar:
+ mkdir -p .lib
+ wget -O $$@ $(4)/$(subst .,/,$1)/$2/$3/$2-$3.jar
+.lib/$2-$3.jar.asc: .lib/$2-$3.jar
+ wget -O $$@ $(4)/$(subst .,/,$1)/$2/$3/$2-$3.jar.asc
+ gpg --batch --verify $$@ $$< || ( rm $$@ ; echo "GPG verification failed, you may need to import the public key." ; exit 1 )
+setup: .lib/$2-$3.jar.asc
+endef
+
+$(foreach host,$(maven_HOSTS),\
+ $(foreach nver,$($(firstword $(subst =, ,$(host)))_JARS),\
+ $(eval $(call maven_func,$(word 1,$(subst :, ,$(nver))),$(word 2,$(subst :, ,$(nver))),$(word 3,$(subst :, ,$(nver))),$(lastword $(subst =, ,$(host)))))))
+
+# ######################################################################
+# Work in progress idea for java.make extension to run junit
+
+# TODO: module deps?
+# TODO: JAVAFLAGS / DEMOFLAGS / TESTFLAGS?
+
+TESTFLAGS=--add-exports jdk.incubator.foreign/jdk.incubator.foreign.unsafe=notzed.zcl
+
+#central_JARS+=junit:junit:4.12 \
+# org.hamcrest:hamcrest-core:1.3
+
+junit_JARS=.lib/junit-4.12.jar .lib/hamcrest-core-1.3.jar
+
+define java_tests=
+ifndef $(1)_TEST_JAVA
+$(1)_TEST_JAVA := $$(shell find src/$(1)/tests -type f -name '*.java')
+$(1)_TEST := $$(subst /,.,$$(basename $$(shell find src/$(1)/tests -type f -name '*Test.java' -printf '%P\n')))
+$(1)_TESTIT := $$(subst /,.,$$(basename $$(shell find src/$(1)/tests -type f -name '*IT.java' -printf '%P\n')))
+endif
+
+test: $(1)-test
+test-it: $(1)-it
+check: $(1)-test $(1)-it
+bin/status/$(1).tests: $$($(1)_TEST_JAVA)
+bin/status/$(1).tests: bin/status/$(1).classes
+endef
+
+.PHONY: test test-it check
+
+$(foreach module,$(java_MODULES),$(if $(wildcard src/$(module)/tests),$(eval $(call java_tests,$(module)))))
+#$(foreach module,$(java_MODULES),$(if $(wildcard src/$(module)/tests),$(info $(call java_tests,$(module)))))
+
+# ######################################################################
+
+# maven format: $(foreach u,$(junit_JARS),.lib/$(word 2,$(subst :, ,$(u)))-$(word 3,$(subst :, ,$(u))).jar)
+bin/status/%.tests: $(junit_JARS)
+ @install -d $(@D)
+ $(JAVAC) \
+ --patch-module $*=src/$*/tests \
+ --add-modules junit \
+ --add-reads $*=ALL-UNNAMED \
+ $(JAVACFLAGS) $($*_JAVACFLAGS) \
+ --module-source-path 'src/*/tests' \
+ --module-path $(subst $(S),:,.lib bin/modules $(JAVAMODPATH) $($*_JAVAMODPATH)) \
+ -d bin/tests \
+ $($*_TEST_JAVA)
+ touch $@
+
+%-test: bin/status/%.tests
+ $(JAVA) \
+ --patch-module $*=bin/tests/$* \
+ --add-modules $* \
+ --add-modules junit \
+ --add-reads $*=junit \
+ --add-reads $*=ALL-UNNAMED \
+ $(TESTFLAGS) $($*_TESTLAGS) \
+ --module-path $(subst $(S),:,.lib bin/modules bin/tests $(JAVAMODPATH) $($*_JAVAMODPATH)) \
+ org.junit.runner.JUnitCore \
+ $($*_TEST)
+
+%-it: bin/status/%.tests
+ $(JAVA) \
+ --patch-module $*=bin/tests/$* \
+ --add-modules $* \
+ --add-modules junit \
+ --add-reads $*=junit \
+ --add-reads $*=ALL-UNNAMED \
+ $(TESTFLAGS) $($*_TESTFLAGS) \
+ --module-path $(subst $(S),:,.lib bin/modules bin/tests $(JAVAMODPATH) $($*_JAVAMODPATH)) \
+ org.junit.runner.JUnitCore \
+ $($*_TESTIT)