Skip to content
Permalink
Browse files

LegacyService: handle all ModuleInfos

When it's a ScriptInfo, continue to handle shift specially.
Otherwise, always use moduleService.run. The special cases
for CommandInfo running via CommandService, and ScriptInfo
running via ScriptService, did nothing else than delegate to
the ModuleService anyway.

This also has the happy side effect of avoiding a bug caused
by CommandService.run returning null -- which occurs when
the command in question implements Module directly. Using
ModuleService's run method instead has no such issue.

See also:
https://forum.image.sc/t/issue-in-scijava-common/23402
  • Loading branch information...
ctrueden committed Mar 3, 2019
1 parent 03558c1 commit 1c06d969f705991f7d01c77f80c63fceb1d715a8
Showing with 8 additions and 17 deletions.
  1. +8 −17 src/main/java/net/imagej/legacy/LegacyService.java
@@ -294,29 +294,20 @@ public Object runLegacyCompatibleCommand(final String key) {
checkActive();
final ModuleInfo info = legacyCompatible.get(key);
if (info == null) return null;
if (info instanceof CommandInfo) try {
final Future<?> future = commandService.run((CommandInfo) info, true);
return future == null ? null : future.get();
}
catch (final Exception e) {
if (e instanceof RuntimeException) throw (RuntimeException) e;
throw new RuntimeException(e);
}
if (info instanceof ScriptInfo) {
if (ij1Helper.shiftKeyDown()) {
// open the script in the script editor
return openScriptInTextEditor((ScriptInfo) info);
}
try {
return scriptService.run((ScriptInfo) info, true).get();
}
catch (final Exception e) {
if (e instanceof RuntimeException) throw (RuntimeException) e;
throw new RuntimeException(e);
}
}
throw new IllegalArgumentException("Unhandled info for '" + key + "': " +
info);
try {
final Future<?> future = moduleService.run(info, true);
return future == null ? null : future.get();
}
catch (final Exception e) {
if (e instanceof RuntimeException) throw (RuntimeException) e;
throw new RuntimeException(e);
}
}

/**

0 comments on commit 1c06d96

Please sign in to comment.
You can’t perform that action at this time.