Olivier,
You may want to look at the State API defined in Equinox (see package
org.eclipse.osgi.service.resolver).
It allows to reason about a non-running system and analyze the dependencies
using the information available in the manifest.
It is the main API that PDE tooling as well as the new equinox provisioning
work uses. You can find some helper code and usage of this API in
org.eclipse.pde.build (class PDEState).
HTH,
PaScaL
"Pernet, Olivier"
<[EMAIL PROTECTED]
p.com> To
Sent by: <[email protected]>
osgi-dev-bounces@ cc
www2.osgi.org
Subject
[osgi-dev] Retrieving a bundle's
07/04/2007 04:08 dependencies
PM
Please respond to
OSGi Developer
Mail List
<[EMAIL PROTECTED]
gi.org>
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