0

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 Answers1

0

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.

Dmytro Pishchukhin
  • 2,369
  • 1
  • 14
  • 19
  • Yes, it is installed in Eclipse. I can get the RepositoryAdmin with the following code ServiceTracker m_tracker = new ServiceTracker(ctx, RepositoryAdmin.class.getName(), null); m_tracker.open(); // for (Bundle b : ctx.getBundles()) { // if (b.getSymbolicName().contains( // "org.apache.felix.bundlerepository")) { // b.start(); // } // } RepositoryAdmin repoAdmin = (RepositoryAdmin) m_tracker.getService(); – Chandler Zhang Apr 02 '13 at 14:52
  • Yes, it is installed in Eclipse. I can get the RepositoryAdmin. But when I try to resolve an bundle, the return value is false. And during the resolve, the 1st unsatisfied requirement is "bundle:(&(symbolicname=system.bundle))". How should I config system.bundle? – Chandler Zhang Apr 02 '13 at 14:58