Search in sources :

Example 1 with PluginInfo

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;
}
Also used : PluginInfo(io.openk9.plugin.api.PluginInfo)

Example 2 with PluginInfo

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);
}
Also used : AutoCloseables(io.openk9.osgi.util.AutoCloseables) HttpPrefixPredicate(io.openk9.reactor.netty.util.HttpPrefixPredicate) ServiceTrackerCustomizer(org.osgi.util.tracker.ServiceTrackerCustomizer) PluginInfo(io.openk9.plugin.api.PluginInfo) RequiredArgsConstructor(lombok.RequiredArgsConstructor) HttpMethod(io.netty.handler.codec.http.HttpMethod) BaseStaticEndpoint(io.openk9.http.osgi.BaseStaticEndpoint) Strings(io.openk9.common.api.constant.Strings) RouterHandler(io.openk9.http.web.RouterHandler) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference) ServiceRegistration(org.osgi.framework.ServiceRegistration) RouterHandler(io.openk9.http.web.RouterHandler) PluginInfo(io.openk9.plugin.api.PluginInfo)

Aggregations

PluginInfo (io.openk9.plugin.api.PluginInfo)2 HttpMethod (io.netty.handler.codec.http.HttpMethod)1 Strings (io.openk9.common.api.constant.Strings)1 BaseStaticEndpoint (io.openk9.http.osgi.BaseStaticEndpoint)1 RouterHandler (io.openk9.http.web.RouterHandler)1 AutoCloseables (io.openk9.osgi.util.AutoCloseables)1 HttpPrefixPredicate (io.openk9.reactor.netty.util.HttpPrefixPredicate)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 BundleContext (org.osgi.framework.BundleContext)1 ServiceReference (org.osgi.framework.ServiceReference)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)1