public ExportPackage(String name, Map<String, String> attributes, Map<String, String> directives) { super(name, attributes, directives); version = BundleDescription.getVersionRange(attributes.get(Constants.VERSION_ATTRIBUTE)).getLow(); }
private static VersionRange getVersionRange(String version) { if (version == null) { version = "0.0.0"; } return VersionRange.parse(version); }
for (Bundle b : bundle.getBundleContext().getBundles()) { if (requireBundleNames.contains(b.getSymbolicName()) && requireBundlesMap.get(b.getSymbolicName()).isInRange(b.getVersion())) {
public boolean isInRange(Version version) { // We might not have an upper end to the range. if (high == null) { return (version.compareTo(low) >= 0); } else if (isLowInclusive() && isHighInclusive()) { return (version.compareTo(low) >= 0) && (version.compareTo(high) <= 0); } else if (isHighInclusive()) { return (version.compareTo(low) > 0) && (version.compareTo(high) <= 0); } else if (isLowInclusive()) { return (version.compareTo(low) >= 0) && (version.compareTo(high) < 0); } return (version.compareTo(low) > 0) && (version.compareTo(high) < 0); }
public static VersionRange parse(String range) { // Check if the version is an interval. if (range.indexOf(',') >= 0) { String s = range.substring(1, range.length() - 1); String vlo = s.substring(0, s.indexOf(',')).trim(); String vhi = s.substring(s.indexOf(',') + 1, s.length()).trim(); return new VersionRange ( new Version(vlo), (range.charAt(0) == '['), new Version(vhi), (range.charAt(range.length() - 1) == ']')); } else { return new VersionRange(new Version(range), true, null, false); } }
private Set<PackageBundlePair> getImportingPairs(PackageAdmin packageAdmin, Bundle bundle, Set<String> wiredPackages) { BundleDescription description = new BundleDescription(bundle.getHeaders()); Set<PackageBundlePair> importingPairs = new HashSet<PackageBundlePair>(); List<BundleDescription.ImportPackage> imports = description.getImportPackage(); for (BundleDescription.ImportPackage packageImport : imports) { //find the packages that we are importing ExportedPackage[] exportedPackages = packageAdmin.getExportedPackages(packageImport.getName()); if (exportedPackages == null) { importingPairs.add(new PackageBundlePair(packageImport.getName(), packageImport.getVersionRange().toString(), null)); } else { for (ExportedPackage exportedPackage : exportedPackages) { Bundle exportingBundle = exportedPackage.getExportingBundle(); if (exportingBundle != bundle && containsBundle(exportedPackage.getImportingBundles(), bundle)) { importingPairs.add(new PackageBundlePair(packageImport.getName(), packageImport.getVersionRange().toString(), exportedPackage.getExportingBundle())); wiredPackages.add(toString(exportedPackage)); } } } } return importingPairs; }
private boolean needsProviderImports(Bundle persistenceBundle, BundleDescription providerDescription) { BundleDescription description = new BundleDescription(persistenceBundle.getHeaders()); for (HeaderEntry importPackage : description.getDynamicImportPackage()) { if ("*".equals(importPackage.getName())) { LOG.debug("Persistence bundle {} can load any class.", persistenceBundle.getSymbolicName()); return false; } } for (ImportPackage importPackage : description.getImportPackage()) { for (ExportPackage exportPackage : providerDescription.getExportPackage()) { if (importPackage.getName().equals(exportPackage.getName()) && importPackage.getVersionRange().isInRange(exportPackage.getVersion())) { LOG.debug("Persistence bundle {} already imports at least one package from JPA provider bundle.", persistenceBundle.getSymbolicName()); return false; } } } return true; }
public Version getVersion() { String headerValue = (String) headers.get(Constants.BUNDLE_VERSION); return getVersionRange(headerValue).getLow(); }