LegacyJavaAgent: Add code to write out a minimal .jar file

When debugging ij-legacy itself, we need a minimal .jar file that
does not hide the classes we try to debug.

The newly introduced main() method does exactly that, copying the
LegacyJavaAgent .class file into a new .jar file.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Add a Premain-Class: entry so that the ij-legacy agent can be started

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
LegacyJavaAgent: Offer an API to switch the agent off

When the legacy patching is done, we should not warn any longer.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
ij-legacy: shut up the LegacyJavaAgent just before patching

The legacy java agent is supposed to warn when ImageJ 1.x classes
were used before patching, but it should no longer warn when that
patching starts (or afterwards).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
fixup! ij-legacy tests: make sure that a main class is found
Add the preinit() method to DefaultLegacyService

This method is supposed to perform the ImageJ 1.x class patching
required for the LegacyService to work correctly.

Previously, we tried to patch the classes when the legacy service
is initialized, but that is too late if the ImageJ 1.x classes are
used before.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Use DefaultLegacyService's preinit() method to force IJ1 patching

We used to abuse the getInstance() method for that task, but that is
inappropriate: we do actually not want an instance here. We want the
legacy service to run the things necessary before loading ImageJ 1.x
classes so that the LegacyService can be initialized properly later,
if at all.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
CodeHacker: provide better help when patching failed

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
CodeHacker: do not hide warning on stderr

When code patching failed, we should have a proper exception, not a
warning issued on stderr and a linkage error.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
LegacyJavaAgent: optionally overwrite the minimal agent .jar

When the main method runs with --force, it will overwrite the
specified target file.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
LegacyJavaAgent: add a usage

When specifying -javaagent:/path/to/agent.jar=help, it will show a
description of the agent and the options offered by it.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
LegacyJavaAgent: add the 'init' option

In the mode triggered by the 'init' option, the agent will simply force
the code patching of the ImageJ 1.x classes no matter what. This is the
safest and easiest method to fix issues when the CodeHacker complains
that the ImageJ 1.x classes were loaded before they could be patched.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
CodeHacker: mention the agent option 'init'

This is by far the easiest (if not the cleanest) way to solve the
problems...

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
LegacyJavaAgent: add the 'noop' option

This option is only there for easier testing (allowing to switch off
the agent easily in Eclipse's run configurations).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
LegacyJavaAgent: describe the default mode in the usage

This also adds the synonym 'debug' and warns about unhandled agent
options.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
ij-legacy: add configuration to run integration tests

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
ij-legacy (integration test): let the ij-legacy.jar artifact be found

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
fixup! ij-legacy: add configuration to run integration tests
LegacyJavaAgent: start writing the integration tests

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
wip