private static String getFragmentHost(IInstallableUnit unit, String fragmentName) { Collection<IRequirement> requires = unit.getRequirements(); for (IRequirement iRequirement : requires) { if (iRequirement instanceof IRequiredCapability) { IRequiredCapability requiredCapability = (IRequiredCapability) iRequirement; if (fragmentName.equals(requiredCapability.getName())) { String fragmentHost = requiredCapability.getName(); if (!requiredCapability.getRange().toString().equals("0.0.0")) { // $NON-NLS-1$ fragmentHost += ";bundle-version=\"" + requiredCapability.getRange() + '"'; // $NON-NLS-1$ } return fragmentHost; } } } return null; }
public static BundleInfo createBundleInfo(File bundleFile, IInstallableUnit unit) { BundleInfo bundleInfo = new BundleInfo(); if (bundleFile != null) bundleInfo.setLocation(bundleFile.toURI()); Collection<IProvidedCapability> capabilities = unit.getProvidedCapabilities(); for (IProvidedCapability capability : capabilities) { String nameSpace = capability.getNamespace(); if (nameSpace.equals("osgi.bundle")) { // $NON-NLS-1$ bundleInfo.setSymbolicName(capability.getName()); bundleInfo.setVersion(capability.getVersion().toString()); } else if (nameSpace.equals("osgi.fragment")) { // $NON-NLS-1$ String fragmentName = capability.getName(); String fragmentHost = getFragmentHost(unit, fragmentName); // shouldn't happen as long as the metadata is well-formed if (fragmentHost == null) LogHelper.log(createError("Unable to find fragment host for IU: " + unit)); // $NON-NLS-1$ else bundleInfo.setFragmentHost(fragmentHost); bundleInfo.setVersion(capability.getVersion().toString()); } } return bundleInfo; }