private List<XPackageRequirement> findMatchingPatterns(String resName) { List<XPackageRequirement> dynamicRequirements = getDynamicPackageRequirements(hostRev); // Dynamic imports may not be used when the package is exported String pathName = VFSUtils.getPathFromClassName(resName); List<XPackageCapability> packageCapabilities = getPackageCapabilities(hostRev); for (XPackageCapability packageCap : packageCapabilities) { String packagePath = packageCap.getPackageName().replace('.', '/'); if (pathName.equals(packagePath)) return Collections.emptyList(); } List<XPackageRequirement> foundMatch = new ArrayList<XPackageRequirement>(); for (XPackageRequirement dynreq : dynamicRequirements) { final String pattern = dynreq.getPackageName(); if (pattern.equals("*")) { foundMatch.add(dynreq); continue; } String patternPath = getPatternPath(pattern); if (pathName.startsWith(patternPath)) { foundMatch.add(dynreq); continue; } } if (foundMatch.isEmpty() == false) log.tracef( "Found match for path [%s] with Dynamic-ImportPackage pattern: %s", resName, foundMatch); else log.tracef("Class [%s] does not match Dynamic-ImportPackage patterns", resName); return foundMatch; }
@Override public Iterator<Resource> iterateResources(String startPath, boolean recursive) { // Collect paths for substituted packages List<String> importedPaths = new ArrayList<String>(); BundleWiring wiring = hostRev.getBundle().adapt(BundleWiring.class); List<BundleRequirement> preqs = wiring != null ? wiring.getRequirements(PackageNamespace.PACKAGE_NAMESPACE) : null; if (preqs != null) { for (BundleRequirement req : preqs) { XPackageRequirement preq = (XPackageRequirement) req; String packageName = preq.getPackageName(); importedPaths.add(packageName.replace('.', '/')); } } Iterator<Resource> itres = delegate.iterateResources(startPath, recursive); if (importedPaths.isEmpty()) { return itres; } // Filter substituted packages List<Resource> filteredResources = new ArrayList<Resource>(); while (itres.hasNext()) { Resource res = itres.next(); String pathname = res.getName(); int lastIndex = pathname.lastIndexOf('/'); String respath = lastIndex > 0 ? pathname.substring(0, lastIndex) : pathname; if (!importedPaths.contains(respath)) { filteredResources.add(res); } } return filteredResources.iterator(); }
private List<XPackageRequirement> getDynamicPackageRequirements(BundleRevision brev) { List<XPackageRequirement> result = new ArrayList<XPackageRequirement>(); for (Requirement aux : brev.getRequirements(WIRING_PACKAGE_NAMESPACE)) { XPackageRequirement req = (XPackageRequirement) aux; if (req.isDynamic()) { result.add(req); } } return result; }
private XPackageCapability getCandidateCapability( BundleRevision brev, XPackageRequirement packageReq) { for (XPackageCapability packageCap : getPackageCapabilities(brev)) { if (packageReq.matches(packageCap)) { log.tracef("Matching package capability: %s", packageCap); return packageCap; } } return null; }