LOG.debug( "Creating bundle for [" + jarInfo + "]" );
LOG.debug( "Overwrite mode: " + overwriteMode );
LOG.trace( "Using instructions " + instructions );
final Jar jar = new Jar( "dot", jarInputStream );
final Manifest manifest = jar.getManifest();
// Make the jar a bundle if it is not already a bundle
if( manifest == null
|| OverwriteMode.KEEP != overwriteMode
|| ( manifest.getMainAttributes().getValue( Analyzer.EXPORT_PACKAGE ) == null
&& manifest.getMainAttributes().getValue( Analyzer.IMPORT_PACKAGE ) == null )
)
{
// Do not use instructions as default for properties because it looks like BND uses the props
// via some other means then getProperty() and so the instructions will not be used at all
// So, just copy instructions to properties
final Properties properties = new Properties();
properties.putAll(instructions);
properties.put("Generated-By-FAB-From", jarInfo);
properties.put(Analyzer.PLUGIN, ANALYZER_PLUGIN_NAMES);
final Analyzer analyzer = new Analyzer();
analyzer.setJar(jar);
analyzer.setProperties(properties);
// now lets add all the new embedded jars
for (Map.Entry<String, Object> entry : embeddedResources.entrySet()) {
String path = entry.getKey();
Object value = entry.getValue();
Resource resource = toResource(value);
if (resource != null) {
jar.putResource(path, resource);
try {
File file = toFile(value);
analyzer.addClasspath(file);
} catch (IOException e) {
LOG.warn("Failed to get File for " + value + ". " + e, e);
}
}
}
if (manifest != null && OverwriteMode.MERGE == overwriteMode) {
analyzer.mergeManifest(manifest);
}
checkMandatoryProperties(analyzer, jar, jarInfo);
Manifest newManifest = analyzer.calcManifest();
jar.setManifest( newManifest );
Attributes main = jar.getManifest().getMainAttributes();
// Hack to add back META-INF imports
String importPackage = main.getValue(Analyzer.IMPORT_PACKAGE);
for (Descriptors.PackageRef key : analyzer.getReferred().keySet()) {
if (key.getFQN().startsWith("META-INF.")) {