How to find the package dependency of an OSGi bundle

934 Views Asked by At

I have 2 OSGi Bundle Repositories. I want to use API to check if a bundle has any dependency problems provided the 2 obr. How can I invoke api to do that? It seems I can use the following code with Felix API to do that. But how can I get the RepositoryAdmin object?

RepositoryAdmin repoAdmin = ...
repoAdmin.addRepository(new File("/home/chandler/ws/reliability/testParent/test.eba/target/localobr/repository.xml").toURI().toURL());
repoAdmin.addRepository(new File("/home/chandler/geronimo3/var/obr.xml").toURI().toURL());
List<Repository> repos = new ArrayList<Repository>();
for(Repository repo : repoAdmin.listRepositories()) {
repos.add(repo);
}       
repos.add(repoAdmin.getSystemRepository());
repos.add(getLocalRepository(repoAdmin));
Resolver resolver = repoAdmin.resolver(repos.toArray(new Repository[0]));
Resource resources[] = repoAdmin.discoverResources("(&(presentationname=*)(symbolicname=com.chandler.app.osgi.test))");
resolver.add(resources[0]);
boolean resolved = resolver.resolve();
1

There are 1 best solutions below

2
On

org.apache.felix.bundlerepository-x.y.z.jar should be installed and started in your OSGi framework. You can get RepositoryAdmin service from BundleContext instance.