Skip to content

Commit ca1aa0d

Browse files
committed
PluginInfo: fall back to @plugin class annotation
Normally, plugins are discovered by scanning the SJC annotation index, present in the resource META-INF/json/org.scijava.plugin.Plugin. However, PluginInfo objects can also be created explicitly and added directly to a PluginIndex. This is especially useful for unit tests. When this happens, the PluginInfo(String, Class) constructor passed a null Plugin annotation, resulting in no plugin metadata at all. It is much better for the code path through that constructor to scrap the given Class for its associated Plugin annotation, if any.
1 parent 27fb650 commit ca1aa0d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/main/java/org/scijava/plugin/PluginInfo.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,14 @@ protected PluginInfo(final String className,
177177
setPluginType(pluginType);
178178
setMenuPath(null);
179179
setMenuRoot(UIDetails.APPLICATION_MENU_ROOT);
180-
if (annotation != null) {
181-
this.annotation = annotation;
182-
populateValues();
180+
if (annotation == null) {
181+
// attempt to obtain the annotation from the plugin class, if available
182+
if (pluginClass != null) {
183+
this.annotation = pluginClass.getAnnotation(Plugin.class);
184+
}
183185
}
186+
else this.annotation = annotation;
187+
populateValues();
184188
this.classLoader = classLoader;
185189
}
186190

0 commit comments

Comments
 (0)