Do not "override" managed version of the ImageJ 1.x dependency

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Fix indentation
LegacyEnvironment: apply legacy patches lazily

So far, ImageJ 1.x is patched completely as soon as the
LegacyEnvironment is instantiated. This is not always desirable,
however: in tests, for example, one will want to disable the
ij.plugin.dirs handling.

So let's prepare the LegacyEnvironment for "lazy" patching, i.e.
waiting with the legacy patches until ImageJ 1.x is accessed. We
can later add methods that exploit the gap between instantiating
the environment and "instantiating" ImageJ 1.x to modify the patches
according to the caller's wishes.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Initialize a LegacyInjector with the LegacyEnvironment

This injector will hold information about selective legacy patching.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Allow disabling ij1.plugin.dirs handling

This is useful for tests, for example.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
LegacyEnvironment: Show trace of premature initialization

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Refactor test environment instantiation

We have an awful lot of places where we instantiate a headless
legacy environment. In the next commits, we will want to disable
ij1.plugin.dir handling, so let's refactor first.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Use new API to disable ij1.plugin.dir handling in unit tests

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Prepare CodeHacker to be accessed for debugging

Through the next few commits, we will work on adding some facilities for
debugging menu structure issues. This will make it easier to figure out
the root cause when things go wrong with newer ImageJ 1.x versions.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
LegacyEnvironment: Allow overriding the default injector

The API is only intended for internal use, hence it is package-local
only.

If we ever want this to be public API, we can easily do that -- after an
appropriate time during which we can flesh out the details.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Add internal support for augmenting the legacy patches

This patch adds a way to ask the LegacyInjector to call a callback before
and after legacy patching, for more fine-grained control intended to help
figuring out what causes problems with new ImageJ 1.x versions.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Add helpers to diagnose problems with the menu structure

By overriding the injector used for legacy patching, we can patch ImageJ
1.x in addition to the regular legacy patches, e.g. to help diagnosing
problems with the menu structure (a very finicky business due to the
many divergent code paths that add menu items to the menu structure in
ImageJ 1.x -- fifteen at the time of writing...).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Fix the menu structure in headless mode

Shortcuts can be registered with ImageJ 1.x in a persistent way -- they
are written to $HOME/.imagej/IJ_Props.txt. This case was not yet handled
by ij1-patcher's menu structure code.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Merge branch 'fix-menu-structure'

This topic branch fixes a problem with the menu structure (namely when
the user installed shortcuts, persisted in $HOME/.imagej/IJ_Prefs.txt),
and a couple of other problems identified in the course of fixing said
problem.

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