Fix Java-based tools when java is installed but there's no runtime.
Review Request #12088 — Created Feb. 25, 2022 and submitted — Latest diff uploaded
It's possible to have the
javacommand line tool without a runtime
installed, which prevents anything from executing. The Java support
wasn't built for this, incorrectly thinking that dependencies were met,
but failing to run.This enhances
JavaToolMixinto first runjava -version, checking the
error code, and caching a_has_java_runtimeclass attribute, for
sharing across tools. Helper methods are available for unit tests to set
or clear this state, for testing.The PMD tool now uses
JavaToolMixin, in order to take advantage of
this. Unlike other Java-based tools, PMD runs a wrapper script, rather
than runningjavadirectly. This required some changes in
JavaToolMixinto make fewer assumptions about its use.And finally, the PMD tool had some code that assumed Unicode strings,
but broke with byte strings. The simulation tests gave it Unicode
strings, but it didn't instrument correctly with byte strings. The tests
have now been updated.
All relevant unit tests pass without
java, withjavabut no runtime,
and with a runtime.