Fix Java-based tools when java is installed but there's no runtime.

Review Request #12088 — Created Feb. 25, 2022 and submitted

Information

ReviewBot
release-3.0.x

Reviewers

It's possible to have the java command 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 JavaToolMixin to first run java -version, checking the
error code, and caching a _has_java_runtime class 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 running java directly. This required some changes in
JavaToolMixin to 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, with java but no runtime,
and with a runtime.

Summary ID
Fix Java-based tools when java is installed but there's no runtime.
It's possible to have the `java` command 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 `JavaToolMixin` to first run `java -version`, checking the error code, and caching a `_has_java_runtime` class 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 running `java` directly. This required some changes in `JavaToolMixin` to 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.
91b3319018d73fbaf31d5e5eb8a32b27fc3ba8ec
chipx86
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-3.0.x (15d5d0e)