// Check if the application archive already contains the test class
String path = javaClass.getName().replace('.', '/') + ".class";
if (appArchive.contains(path) == false)
((ClassContainer<?>) appArchive).addClass(javaClass);
final OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
Attributes attributes = manifest.getMainAttributes();
for (Entry<Object, Object> entry : attributes.entrySet()) {
String key = entry.getKey().toString();
String value = (String) entry.getValue();
if (key.equals("Manifest-Version"))
continue;
if (key.equals(Constants.IMPORT_PACKAGE)) {
String[] imports = value.split(",");
builder.addImportPackages(imports);
continue;
}
if (key.equals(Constants.EXPORT_PACKAGE)) {
String[] exports = value.split(",");
builder.addExportPackages(exports);
continue;
}
builder.addManifestHeader(key, value);
}
// Export the test class package
builder.addExportPackages(javaClass);
// Add the imports required by the test class
addImportsForClass(builder, javaClass);
// Add common test imports
builder.addImportPackages("org.jboss.arquillian.container.test.api", "org.jboss.arquillian.junit", "org.jboss.arquillian.osgi", "org.jboss.arquillian.test.api");
builder.addImportPackages("org.jboss.shrinkwrap.api", "org.jboss.shrinkwrap.api.asset", "org.jboss.shrinkwrap.api.spec");
builder.addImportPackages("org.junit", "org.junit.runner", "javax.inject", "org.osgi.framework");
// Add or replace the manifest in the archive
appArchive.delete(ArchivePaths.create(JarFile.MANIFEST_NAME));
appArchive.add(new Asset() {
public InputStream openStream() {
return builder.openStream();
}
}, JarFile.MANIFEST_NAME);
}