// Process imports
String importPkgStr = attribs.getValue(Constants.IMPORT_PACKAGE);
Parameters importsMap = new Parameters(importPkgStr);
for (Entry<String,Attrs> entry : importsMap.entrySet()) {
String pkgName = entry.getKey();
Attrs importAttribs = entry.getValue();
// Calculate the importing classes for this import
Map<String,List<Clazz>> classMap = new HashMap<String,List<Clazz>>();
Collection<Clazz> classes = Collections.emptyList();
try {
classes = builder.getClasses("", "IMPORTING", pkgName);
} catch (Exception e) {
logger.logError("Error querying importing classes.", e);
}
for (Clazz clazz : classes) {
String fqn = clazz.getFQN();
int index = fqn.lastIndexOf('.');
if (index < 0)
continue;
String pkg = fqn.substring(0, index);
List<Clazz> list = classMap.get(pkg);
if (list == null) {
list = new LinkedList<Clazz>();
classMap.put(pkg, list);
}
list.add(clazz);
}
// Check if this is a self-import
boolean selfImport = false;
List<ExportPackage> matchingExports = exports.get(pkgName);
if (matchingExports != null) {
String versionRangeStr = importAttribs.get(Constants.VERSION_ATTRIBUTE);
VersionRange versionRange = (versionRangeStr != null) ? new VersionRange(versionRangeStr) : new VersionRange("0");
for (ExportPackage export : matchingExports) {
String versionStr = export.getAttribs().get(Constants.VERSION_ATTRIBUTE);
Version version = (versionStr != null) ? new Version(versionStr) : new Version(0);
if (versionRange.includes(version)) {
selfImport = true;
break;
}
}
}
ImportPackage importPackage = new ImportPackage(pkgName, selfImport, importAttribs, usedBy.get(pkgName), classMap);
List<ImportPackage> importList = imports.get(pkgName);
if (importList == null) {
importList = new LinkedList<ImportPackage>();
imports.put(pkgName, importList);
}
importList.add(importPackage);
}
// Process require-bundles
String requireBundlesStr = attribs.getValue(Constants.REQUIRE_BUNDLE);
final Parameters requiredBundleMap = new Parameters(requireBundlesStr);
for (Entry<String,Attrs> entry : requiredBundleMap.entrySet()) {
String name = entry.getKey();
Attrs rbAttribs = entry.getValue();
// Check if the required bundle is already included in the closure
boolean satisfied = false;
Set<Version> includedVersions = bundleVersions.get(name);
if (includedVersions != null) {
String versionRangeStr = rbAttribs.get(Constants.BUNDLE_VERSION_ATTRIBUTE);
VersionRange versionRange = (versionRangeStr != null) ? new VersionRange(versionRangeStr) : new VersionRange("0");
for (Version includedVersion : includedVersions) {
if (versionRange.includes(includedVersion)) {
satisfied = true;
break;