Skip to content

Commit cbd0ec5

Browse files
committed
ServiceHelper: assign PluginInfo to Services
Normally, plugin are instantiated using PluginInfo#createInstance(), which injects the matching PluginInfo metadata for plugins implementing HasPluginInfo, and assigns the expected priority for plugins implementing Prioritized. But Service creation is special, because we want to instantiate Service dependencies recursively -- which makes the ServiceHelper more complex. The ServiceHelper code was injecting priority via service.setPriority, but not injecting plugin metadata via service.setInfo. Now it does both.
1 parent cf53740 commit cbd0ec5

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/main/java/org/scijava/service/ServiceHelper.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class ServiceHelper extends AbstractContextual {
6565
* Classes to scan when searching for dependencies. Data structure is a map
6666
* with keys being relevant classes, and values being associated priorities.
6767
*/
68-
private final Map<Class<? extends Service>, Double> classPoolMap;
68+
private final Map<Class<? extends Service>, PluginInfo<?>> classPoolMap;
6969

7070
/** Classes to scan when searching for dependencies, sorted by priority. */
7171
private final List<Class<? extends Service>> classPoolList;
@@ -303,9 +303,10 @@ private <S extends Service> S createServiceRecursively(final Class<S> c)
303303
final S service = c.newInstance();
304304
service.setContext(getContext());
305305

306-
// propagate priority if known
307-
final Double priority = classPoolMap.get(c);
308-
if (priority != null) service.setPriority(priority);
306+
// propagate plugin metadata and priority if known
307+
final PluginInfo<?> info = classPoolMap.get(c);
308+
service.setInfo(info);
309+
if (info != null) service.setPriority(info.getPriority());
309310

310311
// NB: If there are any @EventHandler annotated methods, we treat the
311312
// EventService as a required dependency, _unless_ there is also an
@@ -358,7 +359,7 @@ private <S extends Service> S createServiceRecursively(final Class<S> c)
358359

359360
/** Asks the plugin index for all available service implementations. */
360361
private void findServiceClasses(
361-
final Map<Class<? extends Service>, Double> serviceMap,
362+
final Map<Class<? extends Service>, PluginInfo<?>> serviceMap,
362363
final List<Class<? extends Service>> serviceList)
363364
{
364365
// ask the plugin index for the (sorted) list of available services
@@ -368,8 +369,7 @@ private void findServiceClasses(
368369
for (final PluginInfo<Service> info : services) {
369370
try {
370371
final Class<? extends Service> c = info.loadClass();
371-
final double priority = info.getPriority();
372-
serviceMap.put(c, priority);
372+
serviceMap.put(c, info);
373373
serviceList.add(c);
374374
}
375375
catch (final Throwable e) {

0 commit comments

Comments
 (0)