diff --git a/arquillian/common/src/main/java/org/jboss/as/arquillian/container/CommonApplicationArchiveProcessor.java b/arquillian/common/src/main/java/org/jboss/as/arquillian/container/CommonApplicationArchiveProcessor.java deleted file mode 100644 index f13e5f51e2a..00000000000 --- a/arquillian/common/src/main/java/org/jboss/as/arquillian/container/CommonApplicationArchiveProcessor.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2009, Red Hat Middleware LLC, and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jboss.as.arquillian.container; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.jar.JarFile; -import java.util.jar.Manifest; - -import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor; -import org.jboss.arquillian.test.spi.TestClass; -import org.jboss.logging.Logger; -import org.jboss.osgi.spi.util.BundleInfo; -import org.jboss.shrinkwrap.api.Archive; -import org.jboss.shrinkwrap.api.ArchivePath; -import org.jboss.shrinkwrap.api.ArchivePaths; -import org.jboss.shrinkwrap.api.Node; -import org.jboss.shrinkwrap.impl.base.io.IOUtil; - -/** - * An {@link ApplicationArchiveProcessor} that delegates to deployment type specific packagers. - * - * @author Thomas.Diesler@jboss.com - * @author Kabir Khan - * @since 17-Nov-2010 - */ -public class CommonApplicationArchiveProcessor implements ApplicationArchiveProcessor { - - private static final Logger log = Logger.getLogger(CommonApplicationArchiveProcessor.class); - - @Override - public void process(Archive appArchive, TestClass testClass) { - ApplicationArchiveProcessor archiveProcessor; - if (isBundleArchive(testClass, appArchive)) { - archiveProcessor = new OSGiApplicationArchiveProcessor(); - } else { - archiveProcessor = new ModuleApplicationArchiveProcessor(); - } - - log.debugf("Process archive '%s' with: %s", appArchive.getName(), archiveProcessor); - archiveProcessor.process(appArchive, testClass); - - // Debug the application archive manifest - ArchivePath manifestPath = ArchivePaths.create(JarFile.MANIFEST_NAME); - Node node = appArchive.get(manifestPath); - if (node == null) { - log.errorf("Cannot find manifest in: %s", appArchive.getName()); - } else { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try { - IOUtil.copy(node.getAsset().openStream(), baos); - } catch (IOException ex) { - } - log.debugf("Manifest for %s: \n%s", appArchive.getName(), new String(baos.toByteArray())); - } - } - - private boolean isBundleArchive(TestClass testClass, Archive appArchive) { - Manifest manifest = ManifestUtils.getOrCreateManifest(appArchive); - return BundleInfo.isValidBundleManifest(manifest); - } -} diff --git a/arquillian/common/src/main/java/org/jboss/as/arquillian/container/CommonContainerExtension.java b/arquillian/common/src/main/java/org/jboss/as/arquillian/container/CommonContainerExtension.java index e8dd132e738..8ce7079d9d5 100644 --- a/arquillian/common/src/main/java/org/jboss/as/arquillian/container/CommonContainerExtension.java +++ b/arquillian/common/src/main/java/org/jboss/as/arquillian/container/CommonContainerExtension.java @@ -30,7 +30,7 @@ public class CommonContainerExtension implements LoadableExtension { @Override public void register(ExtensionBuilder builder) { - builder.service(ApplicationArchiveProcessor.class, DelegatingApplicationArchiveProcessor.class); + builder.service(ApplicationArchiveProcessor.class, OSGiApplicationArchiveProcessor.class); builder.service(DeploymentExceptionTransformer.class, ExceptionTransformer.class); } } diff --git a/arquillian/common/src/main/java/org/jboss/as/arquillian/container/DelegatingApplicationArchiveProcessor.java b/arquillian/common/src/main/java/org/jboss/as/arquillian/container/DelegatingApplicationArchiveProcessor.java deleted file mode 100644 index 109b9783bc9..00000000000 --- a/arquillian/common/src/main/java/org/jboss/as/arquillian/container/DelegatingApplicationArchiveProcessor.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2009, Red Hat Middleware LLC, and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jboss.as.arquillian.container; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.jar.JarFile; -import java.util.jar.Manifest; - -import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor; -import org.jboss.arquillian.test.spi.TestClass; -import org.jboss.logging.Logger; -import org.jboss.osgi.spi.util.BundleInfo; -import org.jboss.shrinkwrap.api.Archive; -import org.jboss.shrinkwrap.api.ArchivePath; -import org.jboss.shrinkwrap.api.ArchivePaths; -import org.jboss.shrinkwrap.api.Node; -import org.jboss.shrinkwrap.impl.base.io.IOUtil; - -/** - * An {@link ApplicationArchiveProcessor} that delegates to deployment type specific packagers. - * - * @author Thomas.Diesler@jboss.com - * @author Kabir Khan - * @since 17-Nov-2010 - */ -public class DelegatingApplicationArchiveProcessor implements ApplicationArchiveProcessor { - - private static final Logger log = Logger.getLogger(DelegatingApplicationArchiveProcessor.class); - - @Override - public void process(Archive appArchive, TestClass testClass) { - ApplicationArchiveProcessor archiveProcessor; - if (isBundleArchive(testClass, appArchive)) { - archiveProcessor = new OSGiApplicationArchiveProcessor(); - } else { - archiveProcessor = new ModuleApplicationArchiveProcessor(); - } - - log.debugf("Process archive '%s' with: %s", appArchive.getName(), archiveProcessor); - archiveProcessor.process(appArchive, testClass); - - // Debug the application archive manifest - ArchivePath manifestPath = ArchivePaths.create(JarFile.MANIFEST_NAME); - Node node = appArchive.get(manifestPath); - if (node == null) { - log.errorf("Cannot find manifest in: %s", appArchive.getName()); - } else { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try { - IOUtil.copy(node.getAsset().openStream(), baos); - } catch (IOException ex) { - } - log.debugf("Manifest for %s: \n%s", appArchive.getName(), new String(baos.toByteArray())); - } - } - - private boolean isBundleArchive(TestClass testClass, Archive appArchive) { - Manifest manifest = ManifestUtils.getOrCreateManifest(appArchive); - return BundleInfo.isValidBundleManifest(manifest); - } -} diff --git a/arquillian/common/src/main/java/org/jboss/as/arquillian/container/ManifestUtils.java b/arquillian/common/src/main/java/org/jboss/as/arquillian/container/ManifestUtils.java index 72c0533a5e6..29bf9fd1126 100644 --- a/arquillian/common/src/main/java/org/jboss/as/arquillian/container/ManifestUtils.java +++ b/arquillian/common/src/main/java/org/jboss/as/arquillian/container/ManifestUtils.java @@ -32,23 +32,18 @@ * * @author Kabir Khan */ -public class ManifestUtils { +class ManifestUtils { - public static Manifest getManifest(Archive archive, boolean create) { - Manifest manifest = null; + public static Manifest getManifest(Archive archive) { try { Node node = archive.get(JarFile.MANIFEST_NAME); - if (node == null) { - manifest = new Manifest(); - Attributes attributes = manifest.getMainAttributes(); - attributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0"); - } else if (create) { - manifest = new Manifest(node.getAsset().openStream()); + if (node != null && node.getAsset() != null) { + return new Manifest(node.getAsset().openStream()); } - return manifest; } catch (Exception ex) { throw new IllegalStateException("Cannot obtain manifest", ex); } + return null; } public static Manifest getOrCreateManifest(Archive archive) { diff --git a/arquillian/common/src/main/java/org/jboss/as/arquillian/container/ModuleApplicationArchiveProcessor.java b/arquillian/common/src/main/java/org/jboss/as/arquillian/container/ModuleApplicationArchiveProcessor.java deleted file mode 100644 index 542cdeb0dab..00000000000 --- a/arquillian/common/src/main/java/org/jboss/as/arquillian/container/ModuleApplicationArchiveProcessor.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2009, Red Hat Middleware LLC, and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jboss.as.arquillian.container; - -import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor; -import org.jboss.arquillian.test.spi.TestClass; -import org.jboss.logging.Logger; -import org.jboss.shrinkwrap.api.Archive; -import org.jboss.shrinkwrap.api.ArchivePath; -import org.jboss.shrinkwrap.api.ArchivePaths; -import org.jboss.shrinkwrap.api.asset.Asset; -import org.jboss.shrinkwrap.api.container.ManifestContainer; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.jar.Attributes; -import java.util.jar.JarFile; -import java.util.jar.Manifest; - -/** - * An {@link ApplicationArchiveProcessor} for module test deployments. - * - * @author Thomas.Diesler@jboss.com - * @author Kabir Khan - * @since 17-Nov-2010 - */ -public class ModuleApplicationArchiveProcessor implements ApplicationArchiveProcessor { - - private static final Logger log = Logger.getLogger(ModuleApplicationArchiveProcessor.class); - - static final List defaultDependencies = new ArrayList(); - - static { - defaultDependencies.add("deployment.arquillian-service"); - defaultDependencies.add("org.jboss.modules"); - defaultDependencies.add("org.jboss.msc"); - } - /* - static final List jsfDependencies = new ArrayList(); - static { - jsfDependencies.add("org.jboss.jsfunit.arquillian"); - jsfDependencies.add("org.jboss.jsfunit.core"); - jsfDependencies.add("org.jboss.jsfunit.arquillian"); - jsfDependencies.add("net.sourceforge.htmlunit"); - jsfDependencies.add("org.apache.james.mime4j"); - jsfDependencies.add("org.apache.commons.codec"); - jsfDependencies.add("org.apache.commons.collections"); - jsfDependencies.add("org.apache.commons.io"); - jsfDependencies.add("org.apache.commons.lang"); - jsfDependencies.add("org.apache.commons.logging"); - jsfDependencies.add("org.apache.httpcomponents"); - jsfDependencies.add("org.apache.xalan"); - jsfDependencies.add("org.apache.xerces"); - jsfDependencies.add("org.w3c.css.sac"); - jsfDependencies.add("net.sourceforge.cssparser"); - jsfDependencies.add("net.sourceforge.nekohtml"); - } - */ - - @Override - public void process(Archive appArchive, TestClass testClass) { - if (appArchive instanceof ManifestContainer == false) - throw new IllegalArgumentException("ManifestContainer expected " + appArchive); - - final Manifest manifest = ManifestUtils.getOrCreateManifest(appArchive); - Attributes attributes = manifest.getMainAttributes(); - if (attributes.getValue(Attributes.Name.MANIFEST_VERSION.toString()) == null) { - attributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0"); - } - String value = attributes.getValue("Dependencies"); - StringBuffer moduleDeps = new StringBuffer(value != null && value.trim().length() > 0 ? value : "org.jboss.modules"); - for (String dep : defaultDependencies) { - if (moduleDeps.indexOf(dep) < 0) - moduleDeps.append("," + dep); - } - /* - if (Boolean.valueOf(System.getProperty("jboss.arquillian.jsfunit", "false"))) { - for (String dep : jsfDependencies) { - if (moduleDeps.indexOf(dep) < 0) { - moduleDeps.append("," + dep); - } - } - } - */ - log.debugf("Add dependencies: %s", moduleDeps); - attributes.putValue("Dependencies", moduleDeps.toString()); - - // Add the manifest to the archive - ArchivePath manifestPath = ArchivePaths.create(JarFile.MANIFEST_NAME); - appArchive.delete(manifestPath); - appArchive.add(new Asset() { - public InputStream openStream() { - try { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - manifest.write(baos); - return new ByteArrayInputStream(baos.toByteArray()); - } catch (IOException ex) { - throw new IllegalStateException("Cannot write manifest", ex); - } - } - }, manifestPath); - } -} diff --git a/arquillian/common/src/main/java/org/jboss/as/arquillian/container/OSGiApplicationArchiveProcessor.java b/arquillian/common/src/main/java/org/jboss/as/arquillian/container/OSGiApplicationArchiveProcessor.java index 79d60bd2ad0..59ee31c4c44 100644 --- a/arquillian/common/src/main/java/org/jboss/as/arquillian/container/OSGiApplicationArchiveProcessor.java +++ b/arquillian/common/src/main/java/org/jboss/as/arquillian/container/OSGiApplicationArchiveProcessor.java @@ -25,6 +25,9 @@ import org.jboss.arquillian.container.osgi.AbstractOSGiApplicationArchiveProcessor; import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor; +import org.jboss.arquillian.test.spi.TestClass; +import org.jboss.osgi.spi.util.BundleInfo; +import org.jboss.shrinkwrap.api.Archive; /** @@ -35,8 +38,25 @@ */ public class OSGiApplicationArchiveProcessor extends AbstractOSGiApplicationArchiveProcessor { + @Override + public void process(Archive appArchive, TestClass testClass) { + if(isValidOSGiBundle(appArchive)) { + super.process(appArchive, testClass); + } + } + @Override protected Manifest createBundleManifest(String symbolicName) { return null; } + + private boolean isValidOSGiBundle(Archive appArchive) { + Manifest manifest = ManifestUtils.getManifest(appArchive); + if(manifest != null) { + if(BundleInfo.isValidBundleManifest(manifest)) { + return true; + } + } + return false; + } } diff --git a/arquillian/protocol-jmx/src/main/java/org/jboss/as/arquillian/protocol/jmx/JMXProtocolPackager.java b/arquillian/protocol-jmx/src/main/java/org/jboss/as/arquillian/protocol/jmx/JMXProtocolPackager.java index 00dcc5d123a..2e9a2c1d69f 100644 --- a/arquillian/protocol-jmx/src/main/java/org/jboss/as/arquillian/protocol/jmx/JMXProtocolPackager.java +++ b/arquillian/protocol-jmx/src/main/java/org/jboss/as/arquillian/protocol/jmx/JMXProtocolPackager.java @@ -27,9 +27,14 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.URL; +import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.List; import java.util.Set; +import java.util.jar.Attributes; +import java.util.jar.JarFile; +import java.util.jar.Manifest; import org.jboss.arquillian.container.test.spi.RemoteLoadableExtension; import org.jboss.arquillian.container.test.spi.TestDeployment; @@ -42,14 +47,17 @@ import org.jboss.logging.Logger; import org.jboss.msc.service.ServiceActivator; import org.jboss.osgi.framework.Constants; +import org.jboss.osgi.spi.util.BundleInfo; import org.jboss.osgi.testing.ManifestBuilder; import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.ArchivePath; import org.jboss.shrinkwrap.api.ArchivePaths; import org.jboss.shrinkwrap.api.Node; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.Asset; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.asset.UrlAsset; +import org.jboss.shrinkwrap.api.container.ManifestContainer; import org.jboss.shrinkwrap.api.spec.JavaArchive; /** @@ -65,6 +73,14 @@ */ public class JMXProtocolPackager implements DeploymentPackager { + private static final List defaultDependencies = new ArrayList(); + + static { + defaultDependencies.add("deployment.arquillian-service"); + defaultDependencies.add("org.jboss.modules"); + defaultDependencies.add("org.jboss.msc"); + } + private static final Logger log = Logger.getLogger(JMXProtocolPackager.class); private ServiceArchiveHolder archiveHolder; @@ -81,6 +97,7 @@ public Archive generateDeployment(TestDeployment testDeployment, Collection

appArchive) { + if (appArchive instanceof ManifestContainer == false) + throw new IllegalArgumentException("ManifestContainer expected " + appArchive); + + final Manifest manifest = ManifestUtils.getOrCreateManifest(appArchive); + + // Don't enrich with Modules Dependencies if this is a OSGi bundle + if(BundleInfo.isValidBundleManifest(manifest)) { + return; + } + Attributes attributes = manifest.getMainAttributes(); + if (attributes.getValue(Attributes.Name.MANIFEST_VERSION.toString()) == null) { + attributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0"); + } + String value = attributes.getValue("Dependencies"); + StringBuffer moduleDeps = new StringBuffer(value != null && value.trim().length() > 0 ? value : "org.jboss.modules"); + for (String dep : defaultDependencies) { + if (moduleDeps.indexOf(dep) < 0) + moduleDeps.append("," + dep); + } + + log.debugf("Add dependencies: %s", moduleDeps); + attributes.putValue("Dependencies", moduleDeps.toString()); + + // Add the manifest to the archive + ArchivePath manifestPath = ArchivePaths.create(JarFile.MANIFEST_NAME); + appArchive.delete(manifestPath); + appArchive.add(new Asset() { + public InputStream openStream() { + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + manifest.write(baos); + return new ByteArrayInputStream(baos.toByteArray()); + } catch (IOException ex) { + throw new IllegalStateException("Cannot write manifest", ex); + } + } + }, manifestPath); + } } diff --git a/arquillian/protocol-jmx/src/main/java/org/jboss/as/arquillian/protocol/jmx/ManifestUtils.java b/arquillian/protocol-jmx/src/main/java/org/jboss/as/arquillian/protocol/jmx/ManifestUtils.java new file mode 100644 index 00000000000..6ea2865eba5 --- /dev/null +++ b/arquillian/protocol-jmx/src/main/java/org/jboss/as/arquillian/protocol/jmx/ManifestUtils.java @@ -0,0 +1,71 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2010, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.as.arquillian.protocol.jmx; + +import java.util.jar.Attributes; +import java.util.jar.JarFile; +import java.util.jar.Manifest; + +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.Node; + +/** + * + * @author Kabir Khan + */ +class ManifestUtils { + + public static Manifest getManifest(Archive archive, boolean create) { + Manifest manifest = null; + try { + Node node = archive.get(JarFile.MANIFEST_NAME); + if (node == null) { + manifest = new Manifest(); + Attributes attributes = manifest.getMainAttributes(); + attributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0"); + } else if (create) { + manifest = new Manifest(node.getAsset().openStream()); + } + return manifest; + } catch (Exception ex) { + throw new IllegalStateException("Cannot obtain manifest", ex); + } + } + + public static Manifest getOrCreateManifest(Archive archive) { + Manifest manifest; + try { + Node node = archive.get(JarFile.MANIFEST_NAME); + if (node == null) { + manifest = new Manifest(); + Attributes attributes = manifest.getMainAttributes(); + attributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0"); + } else { + manifest = new Manifest(node.getAsset().openStream()); + } + return manifest; + } catch (Exception ex) { + throw new IllegalStateException("Cannot obtain manifest", ex); + } + } + +}