}
private void augmentImports(Builder builder, Jar jar, IBldBundle bundle)
throws IOException
{
Attributes main = jar.getManifest().getMainAttributes();
String impHeader = main.getValue(Constants.IMPORT_PACKAGE);
Map<String, Map<String, String>> bndImports = Processor.parseHeader(impHeader,
builder);
if (bndImports.isEmpty())
return;
ArrayList<String> self = new ArrayList<String>();
ArrayList<String> missing = new ArrayList<String>();
ArrayList<String> modified = new ArrayList<String>();
ArrayList<String> unversioned = new ArrayList<String>();
String expHeader = main.getValue(Constants.EXPORT_PACKAGE);
Set<String> bndExports = Processor.parseHeader(expHeader, builder).keySet();
HashMap<String, IPackageImport> imports = new HashMap<String, IPackageImport>();
for (IPackageImport pi : getImports(bundle))
{
switch (pi.getOSGiImport())
{
case NEVER:
break;
case ALWAYS:
String pkg = pi.getPackageName();
if (!bndImports.containsKey(pkg))
{
// Bnd doesn't think this import is needed - but we know
// better
HashMap<String, String> attrs = new HashMap<String, String>();
attrs.put(BldAttr.VERSION_ATTRIBUTE, pi.getVersions().toString());
bndImports.put(pkg, attrs);
modified.add(pkg + ";resolve=runtime");
}
// fall thru */
case AUTO:
imports.put(pi.getPackageName(), pi);
break;
}
}
boolean importDot = false;
for (String pkg : bndImports.keySet())
{
unused.remove(pkg);
Map<String, String> attrs = bndImports.get(pkg);
String currentVersion = (String) attrs.get(BldAttr.VERSION_ATTRIBUTE);
IPackageImport pi = imports.get(pkg);
if (pi != null)
{
VersionRange range = pi.getVersions();
String version = range.toString();
if (!version.equals(currentVersion)
&& !range.equals(VersionRange.ANY_VERSION))
{
attrs.put(BldAttr.VERSION_ATTRIBUTE, version);
if (pi.isOptional())
attrs.put(BldAttr.RESOLUTION_ATTRIBUTE,
BldAttr.RESOLUTION_OPTIONAL);
modified.add(pkg + ";version=" + version
+ (pi.isOptional() ? ";optional" : ""));
}
else if ((currentVersion == null) && !systemPkgs.contains(pkg))
{
unversioned.add(pkg);
}
}
else
{
// bnd added the import ...
if (currentVersion == null)
{
String defaultVersion = project.getDefaultPackageVersion(pkg);
if (defaultVersion != null)
{
attrs.put(BldAttr.VERSION_ATTRIBUTE, defaultVersion);
currentVersion = defaultVersion;
}
}
String imp = pkg
+ (currentVersion == null ? "" : ";version=" + currentVersion);
if (bndExports.contains(pkg))
{
self.add(imp);
}
else
{
if (pkg.equals("."))
{
warnings.add("Bnd wants to import '.' (ignored)");
importDot = true;
}
else
{
missing.add(imp);
}
}
}
}
if (!modified.isEmpty() || importDot)
{
if (importDot)
bndImports.remove(".");
// warnings.add("INFO: sigil modified imports: " + modified);
main.putValue(Constants.IMPORT_PACKAGE, Processor.printClauses(bndImports,
"resolution:"));
}
if (!self.isEmpty())
{