use of io.openk9.plugin.api.PluginInfo in project openk9 by smclab.
the class PluginBundleTrackerCustomizer method addingBundle.
@Override
public Void addingBundle(Bundle bundle, BundleEvent event) {
if (bundle.getState() != Bundle.ACTIVE) {
removedBundle(bundle, event, null);
return null;
}
Dictionary<String, String> headers = bundle.getHeaders(null);
if (headers.get(Constants.OPENK9_PLUGIN) == null) {
return null;
}
String pluginWebId = headers.get(Constants.OPENK9_PLUGIN_WEB_ID);
if (pluginWebId == null) {
pluginWebId = bundle.getSymbolicName();
}
PluginInfo pluginInfo = PluginInfo.DefaultPluginInfo.of(pluginWebId, BundleInfo.builder().id(bundle.getBundleId()).lastModified(bundle.getLastModified()).symbolicName(bundle.getSymbolicName()).version(bundle.getVersion().toString()).state(_STATE_MAP.get(bundle.getState())).build());
ServiceRegistration<PluginInfo> pluginInfoSR = bundle.getBundleContext().registerService(PluginInfo.class, pluginInfo, null);
_registrationMap.put(bundle, AutoCloseables.mergeAutoCloseableToSafe(pluginInfoSR::unregister));
return null;
}
use of io.openk9.plugin.api.PluginInfo in project openk9 by smclab.
the class PluginInfoServiceTrackerCustomizer method addingService.
@Override
public AutoCloseables.AutoCloseableSafe addingService(ServiceReference<PluginInfo> reference) {
PluginInfo pluginInfo = _bundleContext.getService(reference);
String path = "/plugins/" + pluginInfo.getPluginId() + "/static";
RouterHandler routerHandler = router -> router.route(HttpPrefixPredicate.of(path, HttpMethod.GET), BaseStaticEndpoint.of(reference.getBundle(), path, Strings.BLANK, ""));
ServiceRegistration<RouterHandler> serviceRegistration = _bundleContext.registerService(RouterHandler.class, routerHandler, null);
return AutoCloseables.mergeAutoCloseableToSafe(serviceRegistration::unregister);
}
Aggregations