Move some of the former LegacyExtensions into the ImageJ2-specific hooks

Our ultimate goal is to separate concerns; that means that patches for
ImageJ 1.x that are independent of ImageJ2 should go to the essential
legacy hooks while extensions that actually require ImageJ2 go to the
DefaultLegacyHooks class (so that we can factor out the patcher itself
into a separate project).

In this vein, let's move certain extension points we just moved out of
LegacyExtensions further into DefaultLegacyHooks, e.g. the editor hooks.

Basically everything we will want to implement via the SciJava-common
plugin framework needs to be handled by DefaultLegacyHooks.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
CodeHacker: remove obsolete code

In our endeavor to separate better between ImageJ 1.x and ImageJ2
classes, we no longer use ImageJ2 classes directly in the patched
ImageJ 1.x.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
IJ1Helper: remove no longer needed functions

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Script editor: defensive programming

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Attach/detach the event delegator when installing the legacy hooks

It is more logical to do it that way because it guarantees that the
event delegator is detached even if hooks are installed into ImageJ 1.x
that are *not* based on an ImageJ2 legacy service.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Add a default implementation of the text editor

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Refactor out headless GenericDialog

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Add rudimentary Javadoc for the headless GenericDialog

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Remove no longer needed @SupressWarnings

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Move installHooks(LegacyHooks) from CodeHacker to LegacyInjector

The installHooks() method is really meant to run long, long, long time
after the code patching happened. Therefore, the CodeHacker class is
actually not the best place to put that method (but we did, in order to
be certain to insert the hooks into the correct class loader).

While at it, get rid of the setLegacyService() method: we do not set
the legacy service at all any longer, just the legacy hooks: it is their
task to connect everything to the correct legacy service.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Patch in the _hooks field in the LegacyInjector class

The CodeHacker is not supposed to know anything about ImageJ 1.x, just
about code patching.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Move the preinit() logic from DefaultLegacyService into LegacyInjector

This is another change in the overall project to separate better between
legacy code patching and the legacy service.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
CodeHacker: refactor the code printing the JavaAgent hint

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Allow LegacyInjector.preinit() to be called multiple times

The subsequent calls will simply verify that all was patched alright and
then return.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Always start with a fresh ClassPool when patching ImageJ 1.x

That way, we will be able to patch multiple ImageJ 1.x 'instances' in
different ClassLoaders with the same LegacyInjector instance.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Deprecate DefaultLegacyService's preinit() in favor of LegacyInjector's

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Start a new projects: ij1-patcher

This project will not depend on ImageJ2, but ij-legacy will rely on
ij1-patcher to provide an appropriately patched ImageJ 1.x.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Extract utilities from SciJava-common into ij1-patcher

To be as useful as possible, the ij1-patcher project can have only
javassist as a dependency (and that only because there is simply no other
way to patch ImageJ 1.x efficiently).

Therefore, let's provide SciJava-common' utility functions required by the
classes we want to move into ij1-patcher.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Move some classes from ij-legacy into the new ij1-patcher

This change moves a self-contained set of classes related to
runtime-patching ImageJ 1.x from ij-legacy into ij1-patcher.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
CodeHacker: add a way to commit non-IJ1 classes into the given class loader

We add three classes in the legacy patching: LegacyHooks,
EssentialLegacyHooks and HeadlessGenericDialog. These must be known to
the class loader, of course.

With LegacyHooks, we want to make it accessible both to the calling
classes and ImageJ, so it makes sense to share that interface (via the
slightly method to return it from findClasses(), violating the
convention that a class loader should only return classes whose
associated class loader is in its hierarchy).

With EssentialLegacyHooks and HeadlessGenericDialog, this is not
possible: they access the ImageJ 1.x classes themselves, and therefore
they would access the *wrong* ImageJ 1.x classes if we were to reuse
those classes from a different class loader. Therefore, we need to
commit those classes to the same class loader the ImageJ 1.x classes
are living in.

This makes only a difference if the class loader that gets passed to
CodeHacker is a different one than the one which loaded CodeHacker.
That is exactly the way we intend to handle things in the near future:
to be at least able to encapsulate ImageJ 1.x "instances" by loading
them into special-purpose class loaders.

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