Maven Central from GNU Make
I had a look at jmh yesterday. It's all driven by maven so that's a bit of a pain but using the ant example I trivially converted it to use GNU make.
As expected, it's somewhat fewer lines of code to just use a generic build tool than either of the other tools which are specifically designed for Java projects. I will integrate it into java.make eventually, although as I don't use any projects that require it I haven't done that yet.
So for this prototyping example you just define a couple of variables. The interesting one just lists the group:artifact:version in a relatively simple/readable format.
CENTRAL=https://repo1.maven.org/maven2 CENTRAL_JARS= \ org.openjdk.jmh:jmh-core:1.18 \ org.openjdk.jmh:jmh-generator-annprocess:1.18 \ net.sf.jopt-simple:jopt-simple:4.6 \ org.apache.commons:commons-math3:3.2
And well that's about it. It hooks into the makefile system at the right place to download the libraries. I don't do any signature checks but I can't imagine that would be very to add either.
It only requires a simple macro to download the packages.
define maven_func= bin/lib/$2-$3.jar: mkdir -p bin/lib wget -O $$@ $(CENTRAL)/$(subst .,/,$1)/$2/$3/$2-$3.jar setup: bin/lib/$2-$3.jar endef .PHONY: setup $(foreach nver, $(CENTRAL_JARS), $(eval $(call maven_func,$(word 1,$(subst :, ,$(nver))),$(word 2,$(subst :, ,$(nver))),$(word 3,$(subst :, ,$(nver))))))
Although calling it is a little clumsy, but that's a hidden detail.
To hook it in you have to add
jmh-generator-annprocess to the class path of
bin/.classes: setup $(SOURCES) javac -d bin/classes \ -cp bin/lib/jmh-core-1.18.jar:bin/lib/jmh-generator-annprocess-1.18.jar \ $(SOURCES) touch bin/.classes
jmh is typically run using a standalone jar file but for simplicity it can just be run in-place from the build directory. Creating a standalone jar wouldn't be that much hard to add, just a few invocations of jar to explode and repack the classes.
bench: bin/.classes java -cp bin/classes:bin/lib/jmh-core-1.18.jar:bin/lib/jopt-simple-4.6.jar:bin/lib/commons-math3-3.2.jar \ org.openjdk.jmh.Main
In the final iteration I will add some code to the macro to create this classpath so it is easier to use.
Regarding a previous post i've discovered that the annotation mechanism i've been using is probably not the approach to use and there is a lower-level interface. I'm still yet to start on supporting that in the code generator but i've nutted out most of the machinery it will require.
I've bugged the panama developers quite a bit about what I see as some shortcomings in the api. Their idea of a 'C api' is very limited, for example they think that Java shouldn't be able to dereference a C-allocated pointer without signifying 'unsafe' code and passing some scary arguments to the compiler and jvm.
Sure, many modern api's want to wrap trivial memory operations in
multiple layers of 'accessor' functions but even those typically
const char * for a string so you
can't even access those without a mess. This seems a little odd
because what you can do without resorting to 'unsafe' api's has no
safety guarantees already, and infact you can trivially implement
an arbitrary whole-memory-access function by just
memcpy. Anyway there is hope it is changed
by release because it's an unecessary restriction that can be
bypassed trivially and just adds more developer work for no good
reason. In my experience such complexity just leads to more of
the type of errors they're trying to safeguard against.