@@ -0,0 +1,2899 @@
+/**%0A * Copyright (c) 2000-present Liferay, Inc. All rights reserved.%0A *%0A * This library is free software; you can redistribute it and/or modify it under%0A * the terms of the GNU Lesser General Public License as published by the Free%0A * Software Foundation; either version 2.1 of the License, or (at your option)%0A * any later version.%0A *%0A * This library is distributed in the hope that it will be useful, but WITHOUT%0A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS%0A * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more%0A * details.%0A */%0A%0Apackage com.liferay.arquillian.processor;%0A%0Aimport aQute.bnd.osgi.Analyzer;%0Aimport aQute.bnd.osgi.Jar;%0A%0Aimport java.io.ByteArrayOutputStream;%0A%0Aimport java.util.jar.Manifest;%0A%0Aimport org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor;%0Aimport org.jboss.arquillian.test.spi.TestClass;%0Aimport org.jboss.shrinkwrap.api.Archive;%0Aimport org.jboss.shrinkwrap.api.asset.ByteArrayAsset;%0Aimport org.jboss.shrinkwrap.api.exporter.ZipExporter;%0Aimport org.jboss.shrinkwrap.api.spec.JavaArchive;%0A%0A/**%0A * This processor analyzes the jar after adding the test to fix the imports%0A * when needed.%0A *%0A * @author Carlos Sierra Andr%C3%A9s%0A */%0Apublic class BndApplicationArchiveProcessor implements ApplicationArchiveProcessor %7B%0A%0A%09public static final String MANIFEST_PATH = %22META-INF/MANIFEST.MF%22;%0A%0A%09@Override%0A%09public void process(Archive%3C?%3E applicationArchive, TestClass testClass) %7B%0A%0A%09%09JavaArchive javaArchive = applicationArchive.as(JavaArchive.class);%0A%0A%09%09javaArchive.addClass(testClass.getJavaClass());%0A%0A%09%09Analyzer analyzer = new Analyzer();%0A%0A%09%09try %7B%0A%09%09%09Manifest manifest = new Manifest(applicationArchive.get(MANIFEST_PATH).getAsset().openStream());%0A%0A%09%09%09String exportPackage = manifest.getMainAttributes().getValue(%22Export-Package%22);%0A%0A%09%09%09if (exportPackage == null %7C%7C exportPackage.isEmpty()) %7B%0A%09%09%09%09exportPackage = testClass.getJavaClass().getPackage().getName();%0A%09%09%09%7D%0A%09%09%09else %7B%0A%09%09%09%09exportPackage += %22,%22 + testClass.getJavaClass().getPackage().getName();%0A%09%09%09%7D%0A%0A%09%09%09manifest.getMainAttributes().putValue(%22Export-Package%22, exportPackage);%0A%0A%09%09%09analyzer.mergeManifest(manifest);%0A%0A%09%09%09ZipExporter zipExporter = applicationArchive.as(ZipExporter.class);%0A%0A%09%09%09Jar jar = new Jar(applicationArchive.getName(), zipExporter.exportAsInputStream());%0A%0A%09%09%09analyzer.setJar(jar);%0A%0A%09%09%09manifest = analyzer.calcManifest();%0A%0A%09%09%09ByteArrayOutputStream baos = new ByteArrayOutputStream();%0A%0A%09%09%09manifest.write(baos);%0A%0A%09%09%09ByteArrayAsset byteArrayAsset = new ByteArrayAsset(%0A%09%09%09%09baos.toByteArray());%0A%0A%09%09%09replaceManifest(applicationArchive, byteArrayAsset);%0A%09%09%7D%0A%09%09catch (Exception e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09finally %7B%0A%09%09%09analyzer.close();%0A%09%09%7D%0A%09%7D%0A%0A%09private void replaceManifest(%0A%09%09Archive%3C?%3E archive, ByteArrayAsset byteArrayAsset) %7B%0A%0A%09%09archive.delete(MANIFEST_PATH);%0A%0A%09%09archive.add(byteArrayAsset, MANIFEST_PATH);%0A%09%7D%0A%0A%7D

Add an ApplicationArchiveProcessor to calculate the final Manifest taking into accout the test class