Dear Peter, BJ
Sorry, took some time because I wanted to build a self-contained example.
Framework is org.apache.felix.framework-4.2.1.jar
I want to build a host application with an embedded framework as plugin container.
Test Case outline:
@Before
public void setup() throws Exception {
/* basically:
fwk = getFrameworkFactory(
resourceRoot.resolve(EmbeddedFramework.FRAMEWORK_FACTORY_PATH))
.newFramework(m);
fwk.start();
*/
efwk = new EmbeddedFramework(test_FRAMEWORK_FACTORY_PATH);
fwk = efwk.createFramework();
}
@Test
public void list() throws Exception {
Path repoAdmin = BND_DIR
.resolve("localrepo/org.apache.felix.bundlerepository/org.apache.felix.bundlerepository-2.0.2.jar");
Path resolver = BND_DIR
.resolve("localrepo/org.apache.felix.resolver/org.apache.felix.resolver-1.0.0.jar");
Path repoService = BND_DIR
.resolve("releaserepo/base.impl.reposervice/base.impl.reposervice-1.0.21.jar");
// more seed packages
...
efwk.installBundles(asList(scr, repoAdmin, resolver, repoService, cmpn));
efwk.startBundles();
repoService is a component that looks like this:
import org.apache.felix.bundlerepository.Reason;
import org.apache.felix.bundlerepository.RepositoryAdmin;
import org.apache.felix.bundlerepository.Resolver;
import org.apache.felix.bundlerepository.Resource;
...
@Component(immediate = true)
public class RepoService {
// got this with a service reference
AtomicReference<RepositoryAdmin> repoAdmin = new AtomicReference<>();
@Activate
public void activate(BundleContext bctx) throws MalformedURLException,
Exception {
repoAdmin.get().addRepository(
new URL("file:/home/p/kepler-osgi/cnf/releaserepo/index.xml"));
repoAdmin.get().addRepository(
new URL("file:/home/p/kepler-osgi/cnf/localrepo/index.xml"));
Resolver resolver = repoAdmin.get().resolver();
String resFilter = "(&(uri=*base.api*)(version=3.0.0))";
Resource[] resources = repoAdmin.get().discoverResources(resFilter);
for (Resource res : resources) {
resolver.add(res);
if (resolver.resolve()) {
for (Resource depRes : resolver.getRequiredResources()) {
System.out.println("Deploying dependency: "
+ depRes.getPresentationName() + " (" + depRes.getSymbolicName()
+ ") " + depRes.getVersion());
}
resolver.deploy(START);
} else {
for (Reason reason : resolver.getUnsatisfiedRequirements()) {
System.out.println("missing " + reason.getRequirement().getFilter());
}
}
}
}
...
and base.api has the following MANIFEST
Export-Package: ....
Import-Package: ....
When I run the testcase list(), the reposervice component starts and I get a missing requirement:
missing (&(
osgi.ee=JavaSE)(version=1.8))
From what I understand, this should be a capability of the framework
@BJ: the Provide-Capability I copied is the default setting of the felix framework 4.2.1, do you mean I need to change this ?
Thanks a lot, sorry if the code is too long , but I am really not sure where the problem is ...
Peter