LegacyClassLoader: Make use of 'known' and 'shared' classes less confusing

The comment should make the purpose of the known and shared classes much
clearer. Also, by using static final hash maps, we can now easily extend
the list of shared and known classes (without that fragile 'sharedCount'
hack).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Format the LegacyClassLoader source code a bit

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Move the NoSuchMethodException handler into LegacyHooks

Needed because EssentialLegacyHooks is not intended to be subclassed.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Make sure that bare .class plugins in plugins/**/* are picked up by IJ1

When there is a A_.class file in, say, ImageJ.app/plugins/blub/x/, but the
corresponding class is actually not in the package blub.x, ImageJ 1.x
falls back to trying first x.A_ and then A_. For that to work, the
subdirectories have to be added to the class path.

Needless to say, requiring callers to make sure that the subdirectories
are contained in the class path would be such an inelegant solution that
we rather add rather ugly code to make sure that there is actually a
plugin class loader that contains said directories. But only if really,
really necessary.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Merge early part of remote branch 'callbacks' into HEAD

Let's cherry-pick the LegacyClassLoader clean-ups, even if we might
not end up merging the infrastructure for calls into the
encapsulated ImageJ 1.x...

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Make IJ.getClassLoader() consistent

We should not return the class loader that happens to be the current
thread context class loader at the time IJ.getClassLoader() was called,
but rather the context class loader at the time the encapsulated ImageJ
1.x instance was initialized.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Leave preinit() early when the patches were already applied

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
alreadyPatched(): also look at the parent class loaders

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Patch the class loader containing the ImageJ 1.x classes

... not a class loader whose *parent* contains them...

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Add a unit test for the class loader issues

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Merge 'context-class-loader' into HEAD