Hi Olivier, Have you looked into using the OSGi Bundle Repository for this ? The RFC spec is here [1] and Apache Felix has a nice implementation of it at [2]. You might also want to look at Peter's blog entry at [3].
After having set up such a repository, the bundlerepository bundle takes away all your pains of resolving dependencies and automatically include them for deployment. Hope this helps. Regards Felix [1] http://www2.osgi.org/download/rfc-0112_BundleRepository.pdf [2] http://svn.apache.org/repos/asf/felix/trunk/bundlerepository [3] http://www.osgi.org/blog/2006/04/bundle-repository.html Am Mittwoch, den 04.07.2007, 21:08 +0100 schrieb Pernet, Olivier: > Hi, > > I'm trying to retrieve all dependencies of a particular bundle, to be > able to create a new JVM, start an OSGi framework in there and install > my bundle and its dependencies. > I've come up with something using the PackageAdmin service, but it feels > really hackish. My main pain point is that there seem to be no way to > get all imported packages for a bundle (please prove me wrong here!) > > So, here's my solution (untested yet, I thought I'd ask before wasting > time in case there's something better): > > private List retrieveDaemonBundleDependencies() { > // List<Bundle> > List dependencies = new ArrayList(); > > // Eeek. > // No other way to get imported packages (?) > Dictionary dict = daemonBundle.getHeaders(); > String importsString = (String) > dict.get(Constants.IMPORT_PACKAGE); > String[] imports = importsString.split(","); > for (int i=0; i<imports.length; i++) { > String[] nameAndAttrs = imports[i].split(";"); > String packageName = nameAndAttrs[0].trim(); > dependencies.add(getExportingBundle(packageName)); > } > > return dependencies; > } > > private Bundle getExportingBundle(String packageName) { > ExportedPackage[] exportedPackages = > packageAdmin.getExportedPackages(packageName); > for (int i=0; i<exportedPackages.length; i++) { > if (contains(exportedPackages[i].getImportingBundles(), > daemonBundle)) > return exportedPackages[i].getExportingBundle(); > } > throw new IllegalStateException("Exporting bundle not found for > package: " + packageName); > } > > private boolean contains(Object[] objects, Object o) { > for (int i=0; i<objects.length; i++) > if (objects[i].equals(o)) return true; > return false; > } > > Thanks for your help! > > _______________________________________________ > OSGi Developer Mail List > [email protected] > http://www2.osgi.org/mailman/listinfo/osgi-dev _______________________________________________ OSGi Developer Mail List [email protected] http://www2.osgi.org/mailman/listinfo/osgi-dev
