We are loading OSGi Bundles with Apache Felix and its subproject Apache File Install from a given folder. In our case it is possible that in this folder will be bundles with an Import-Package
which is not on the container's classpath. This results in an error log message (every 2 seconds). (This is ok, the bundle should not be loaded).
My question is: Is there a possibility to filter bundles before they are installed?
I checked the implementation of org.apache.felix.fileinstall.internal.DirectoryWatcher
and figuered out that I probably want a org.apache.felix.fileinstall.ArtifactListener
:
final ArtifactListener myListener = new ArtifactListener() {
@Override
public boolean canHandle(final File artifact) {
return bundleFullfillsPrecoditions(artifact);
}
};
Unfortunatly I do not manage to register that listener correctly (and canHandle is never been called). I tried to register it as a service on the BundleContext:
//Initialize Felix Framework
org.osgi.framework.launch.Framework osgiFramework = this.createFramework(configuration);
osgiFramework.init();
osgiFramework.start();
//Register Listener?
osgiFramework.getBundleContext().registerService(ArtifactListener.class, myListener, null);
//Start File Install Bundle
org.osgi.framework.Bundle pluginFolderWatcher = osgiFramework.getBundleContext().installBundle(getFolderWatcherJarPath());
pluginFolderWatcher.start();
Maybe its the wrong way, or I missed something. Do you have ideas? Thanks in advance.