ij-legacy: fix CodeHacker#replaceParameterInNew

We decided to count the parameter index from 1, not 0, so we should do
that in the sanity checking before the real parameter replacement, too.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Teach the CodeHacker to test whether a class contains a given method

We will need this to avoid letting CodeHacker fail gracefully when
something was not found: after all, we want the unit testing to find
regressions, in particular with respect to ImageJ 1.x (which changes
things quite often for aesthetical reasons, sometimes at the expense
of backwards-compatibility).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
LegacyExtensions: make stackTraceContains() public

We may eventually want to move this to ij-core or even scijava-common,
but for now the only user lives in ij-legacy (and the other upcoming
user, CodeHacker, lives in ij-legacy, too).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
LegacyExtensions: before patching, ensure GenericDialog#showDialog exists

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
LegacyExtensions: before patching, ensure CommandFinder#export exists

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
ij-legacy: prepare for ImageJ 1.48a

ImageJ 1.48a renamed PluginClassLoader's addJAR() method into addJar()...

Reported by Aryeh Weiss.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
ij-legacy: prepare to avoid exceptions when legacy patching failed

When starting Fiji with another ImageJ 1.x version than the one we
compiled against, it is not a good idea to fail patching with an
exception and prevent Fiji from starting.

Better to report the failure but still try to start up.

However, when we run unit tests, we want to fail loudly when patches
failed...

This commit adds the infrastructure to throw the exceptions in unit
testing mode and to dump them to stderr and try to continue otherwise.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
ij-legacy: Do not throw exceptions when legacy patching failed

When starting Fiji with another ImageJ 1.x version than the one we
compiled against, it is not a good idea to fail patching with an
exception and prevent Fiji from starting.

Better to report the failure but still try to start up, in line with
Postel's Law: be conservative in what you do, be liberal in what you
accept from others.

However, when we run unit tests, we want to fail loudly when patches
failed...

This commit uses the CodeHacker#maybeThrow() infrastructure to throw
the exceptions in unit testing mode and to dump them to stderr and
try to continue otherwise.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Merge branch 'postelize-legacy'

The main purpose of this branch is to have two modes in ij-legacy's
patching:

- the default mode in which exceptions are only logged, but do not let
  the patching fail (in following Postel's Law, so that Fiji can always
  start up, even if unexpected changes in ImageJ 1.x make the legacy
  patches fail), and

- the unit testing mode in which failed legacy patching is fatal and
  makes the unit tests fail, too.

These changes triggered a real bug fix in setting the app name: patched
ImageJ 1.x would still have "ImageJ" in the Quit dialog even when
started from Fiji due to a now-fixed bug in the sanity check in
CodeHacker's replaceParameterInNew() method.

Lastly, the bug reported by Aryeh Weiss (which triggered this branch)
was fixed: ImageJ 1.48a made the legacy patching fail due to
PluginClassLoader's addJAR() method having been renamed to addJar() in
said version.

This merge also addresses http://trac.imagej.net/ticket/1959.

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