[jboss-svn-commits] JBoss Common SVN: r4545 - in arquillian/trunk: build and 6 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jun 24 04:45:23 EDT 2010
Author: thomas.diesler at jboss.com
Date: 2010-06-24 04:45:22 -0400 (Thu, 24 Jun 2010)
New Revision: 4545
Added:
arquillian/trunk/packagers/osgi/src/main/java/org/jboss/arquillian/packager/osgi/BundleArchive.java
Removed:
arquillian/trunk/containers/osgi-embedded/src/main/java/org/jboss/arquillian/osgi/OSGiFrameworkLifecycleController.java
Modified:
arquillian/trunk/.gitignore
arquillian/trunk/build/pom.xml
arquillian/trunk/containers/osgi-embedded/.classpath
arquillian/trunk/containers/osgi-embedded/pom.xml
arquillian/trunk/containers/osgi-embedded/src/main/java/org/jboss/arquillian/osgi/OSGiEmbeddedConfiguration.java
arquillian/trunk/containers/osgi-embedded/src/main/java/org/jboss/arquillian/osgi/OSGiEmbeddedContainer.java
arquillian/trunk/containers/osgi-embedded/src/main/java/org/jboss/arquillian/osgi/OSGiTestEnricher.java
arquillian/trunk/containers/osgi-embedded/src/test/java/org/jboss/arquillian/osgi/OSGiEmbeddedIntegrationTestCase.java
arquillian/trunk/packagers/osgi/pom.xml
arquillian/trunk/packagers/osgi/src/main/java/org/jboss/arquillian/packager/osgi/OSGiDeploymentPackager.java
arquillian/trunk/packagers/osgi/src/test/java/org/jboss/arquillian/packager/osgi/OSGiDeploymentPackagerTestCase.java
Log:
osgi: local framework and test bundle injection ok
Modified: arquillian/trunk/.gitignore
===================================================================
--- arquillian/trunk/.gitignore 2010-06-24 08:43:57 UTC (rev 4544)
+++ arquillian/trunk/.gitignore 2010-06-24 08:45:22 UTC (rev 4545)
@@ -18,8 +18,10 @@
containers/jbossas-remote-60/target
containers/openejb/target
containers/openwebbeans-embedded/target
+containers/osgi-embedded/target/
containers/reloaded/target
containers/weld-ee-embedded/target
+containers/weld-embedded/.classpath
containers/weld-embedded/target
doc/reference/target
examples/.project
@@ -47,15 +49,20 @@
packagers/javaee/.project
packagers/javaee/.settings/
packagers/javaee/target
+protocols/local/.classpath
protocols/local/target
+packagers/osgi/target/
protocols/servlet-ee5/target
+protocols/servlet-ee6/.classpath
protocols/servlet-ee6/target
spi/.classpath
spi/.project
spi/.settings/
spi/target
+testenrichers/cdi/.classpath
testenrichers/cdi/target
+testenrichers/ejb/.classpath
testenrichers/ejb/target
+testenrichers/resource/.classpath
testenrichers/resource/target
-testng/target
-
+testng/target
\ No newline at end of file
Modified: arquillian/trunk/build/pom.xml
===================================================================
--- arquillian/trunk/build/pom.xml 2010-06-24 08:43:57 UTC (rev 4544)
+++ arquillian/trunk/build/pom.xml 2010-06-24 08:45:22 UTC (rev 4545)
@@ -28,9 +28,11 @@
<version.javaee_api>6.0</version.javaee_api>
<version.jboss_embedded>1.0.0-alpha-1</version.jboss_embedded>
<version.jboss_osgi_spi>1.0.7-SNAPSHOT</version.jboss_osgi_spi>
+ <version.jboss_osgi_vfs>1.0.0</version.jboss_osgi_vfs>
<version.jetty_jetty>6.1.9</version.jetty_jetty>
<version.junit_junit>4.6</version.junit_junit>
<version.mockito_all>1.8.3</version.mockito_all>
+ <version.osgi>4.2.0</version.osgi>
<version.shrinkwrap_shrinkwrap>1.0.0-alpha-9</version.shrinkwrap_shrinkwrap>
<version.testng_testng>5.12.1</version.testng_testng>
@@ -189,6 +191,16 @@
<version>${version.jboss_osgi_spi}</version>
</dependency>
<dependency>
+ <groupId>org.jboss.osgi.vfs</groupId>
+ <artifactId>jboss-osgi-vfs</artifactId>
+ <version>${version.jboss_osgi_vfs}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.osgi.vfs</groupId>
+ <artifactId>jboss-osgi-vfs30</artifactId>
+ <version>${version.jboss_osgi_vfs}</version>
+ </dependency>
+ <dependency>
<groupId>org.jboss.shrinkwrap</groupId>
<artifactId>shrinkwrap-api</artifactId>
<version>${version.shrinkwrap_shrinkwrap}</version>
@@ -219,6 +231,16 @@
<version>${version.javaee_api}</version>
</dependency>
<dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${version.osgi}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>${version.osgi}</version>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${version.junit_junit}</version>
Modified: arquillian/trunk/containers/osgi-embedded/.classpath
===================================================================
--- arquillian/trunk/containers/osgi-embedded/.classpath 2010-06-24 08:43:57 UTC (rev 4544)
+++ arquillian/trunk/containers/osgi-embedded/.classpath 2010-06-24 08:45:22 UTC (rev 4545)
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry excluding="**" kind="src" path="src/main/resources"/>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
- <classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
+ <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
Modified: arquillian/trunk/containers/osgi-embedded/pom.xml
===================================================================
--- arquillian/trunk/containers/osgi-embedded/pom.xml 2010-06-24 08:43:57 UTC (rev 4544)
+++ arquillian/trunk/containers/osgi-embedded/pom.xml 2010-06-24 08:45:22 UTC (rev 4545)
@@ -42,13 +42,11 @@
<version>${project.version}</version>
</dependency>
- <!--
<dependency>
<groupId>org.jboss.arquillian.packager</groupId>
<artifactId>arquillian-packager-osgi</artifactId>
<version>${project.version}</version>
</dependency>
- -->
<!-- org.jboss.osgi -->
<dependency>
Modified: arquillian/trunk/containers/osgi-embedded/src/main/java/org/jboss/arquillian/osgi/OSGiEmbeddedConfiguration.java
===================================================================
--- arquillian/trunk/containers/osgi-embedded/src/main/java/org/jboss/arquillian/osgi/OSGiEmbeddedConfiguration.java 2010-06-24 08:43:57 UTC (rev 4544)
+++ arquillian/trunk/containers/osgi-embedded/src/main/java/org/jboss/arquillian/osgi/OSGiEmbeddedConfiguration.java 2010-06-24 08:45:22 UTC (rev 4545)
@@ -22,7 +22,7 @@
/**
* [TODO] OSGiEmbeddedConfiguration
*
- * @author Thomas.Diesler at jboss.com
+ * @author thomas.diesler at jboss.com
* @version $Revision: $
*/
public class OSGiEmbeddedConfiguration implements ContainerConfiguration
Modified: arquillian/trunk/containers/osgi-embedded/src/main/java/org/jboss/arquillian/osgi/OSGiEmbeddedContainer.java
===================================================================
--- arquillian/trunk/containers/osgi-embedded/src/main/java/org/jboss/arquillian/osgi/OSGiEmbeddedContainer.java 2010-06-24 08:43:57 UTC (rev 4544)
+++ arquillian/trunk/containers/osgi-embedded/src/main/java/org/jboss/arquillian/osgi/OSGiEmbeddedContainer.java 2010-06-24 08:45:22 UTC (rev 4545)
@@ -16,10 +16,7 @@
*/
package org.jboss.arquillian.osgi;
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-
+import org.jboss.arquillian.packager.osgi.BundleArchive;
import org.jboss.arquillian.protocol.local.LocalMethodExecutor;
import org.jboss.arquillian.spi.Configuration;
import org.jboss.arquillian.spi.ContainerMethodExecutor;
@@ -27,17 +24,11 @@
import org.jboss.arquillian.spi.DeployableContainer;
import org.jboss.arquillian.spi.DeploymentException;
import org.jboss.arquillian.spi.LifecycleException;
-import org.jboss.arquillian.spi.event.container.AfterDeploy;
-import org.jboss.arquillian.spi.event.container.BeforeSetup;
import org.jboss.logging.Logger;
-import org.jboss.osgi.framework.bundle.OSGiBundleManager;
import org.jboss.osgi.spi.framework.OSGiBootstrap;
import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
-import org.jboss.osgi.testing.OSGiTestHelper;
-import org.jboss.osgi.vfs.AbstractVFS;
import org.jboss.osgi.vfs.VirtualFile;
import org.jboss.shrinkwrap.api.Archive;
-import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
@@ -46,23 +37,24 @@
/**
* [TODO] OSGiEmbeddedContainer
*
- * @author Thomas.Diesler at jboss.com
+ * @author thomas.diesler at jboss.com
* @version $Revision: $
*/
public class OSGiEmbeddedContainer implements DeployableContainer
{
// Provide logging
private static final Logger log = Logger.getLogger(OSGiEmbeddedContainer.class);
-
+
private Framework framework;
-
+
@Override
public void setup(Context context, Configuration configuration)
{
OSGiBootstrapProvider provider = OSGiBootstrap.getBootstrapProvider();
framework = provider.getFramework();
+ context.add(Framework.class, framework);
}
-
+
@Override
public void start(Context context) throws LifecycleException
{
@@ -84,32 +76,52 @@
framework.stop();
framework.waitForStop(3000);
}
+ catch (RuntimeException rte)
+ {
+ throw rte;
+ }
catch (Exception ex)
{
- log.error("Cannot stop embedded OSGi Framework", ex);
+ throw new LifecycleException("Cannot stop embedded OSGi Framework", ex);
}
}
@Override
- public ContainerMethodExecutor deploy(Context context, final Archive<?> archive) throws DeploymentException
+ public ContainerMethodExecutor deploy(Context context, final Archive<?> archive) throws DeploymentException
{
- VirtualFile virtualFile = toVirtualFile(archive);
- BundleContext sysContext = framework.getBundleContext();
- sysContext.installBundle(archive.getName(), virtualFile.openStream());
+ try
+ {
+ if ((archive instanceof BundleArchive) == false)
+ throw new IllegalStateException("Archive is not a bundle archive: " + archive);
+
+ BundleContext sysContext = framework.getBundleContext();
+ VirtualFile virtualFile = ((BundleArchive)archive).getBundleInfo().getRoot();
+ Bundle bundle = sysContext.installBundle(archive.getName(), virtualFile.openStream());
+ context.add(Bundle.class, bundle);
+ }
+ catch (RuntimeException rte)
+ {
+ throw rte;
+ }
+ catch (Exception ex)
+ {
+ throw new DeploymentException("Cannot deploy: " + archive, ex);
+ }
return new LocalMethodExecutor();
}
@Override
public void undeploy(Context context, Archive<?> archive) throws DeploymentException
{
+ try
+ {
+ Bundle bundle = context.get(Bundle.class);
+ if (bundle != null)
+ bundle.uninstall();
+ }
+ catch (BundleException ex)
+ {
+ log.error("Cannot undeploy: " + archive, ex);
+ }
}
-
- private VirtualFile toVirtualFile(Archive<?> archive) throws IOException, MalformedURLException
- {
- ZipExporter exporter = archive.as(ZipExporter.class);
- File target = File.createTempFile("osgi-bundle_", ".jar");
- exporter.exportZip(target, true);
- target.deleteOnExit();
- return AbstractVFS.getRoot(target.toURI().toURL());
- }
}
\ No newline at end of file
Deleted: arquillian/trunk/containers/osgi-embedded/src/main/java/org/jboss/arquillian/osgi/OSGiFrameworkLifecycleController.java
===================================================================
--- arquillian/trunk/containers/osgi-embedded/src/main/java/org/jboss/arquillian/osgi/OSGiFrameworkLifecycleController.java 2010-06-24 08:43:57 UTC (rev 4544)
+++ arquillian/trunk/containers/osgi-embedded/src/main/java/org/jboss/arquillian/osgi/OSGiFrameworkLifecycleController.java 2010-06-24 08:45:22 UTC (rev 4545)
@@ -1,36 +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.arquillian.osgi;
-
-import org.jboss.arquillian.spi.Context;
-import org.jboss.arquillian.spi.event.Event;
-import org.jboss.arquillian.spi.event.suite.EventHandler;
-
-/**
- * [TODO] OSGiFrameworkLifecycleController
- *
- * @author Thomas.Diesler at jboss.com
- * @version $Revision: $
- */
-public class OSGiFrameworkLifecycleController implements EventHandler<Event>
-{
- @Override
- public void callback(Context context, Event event) throws Exception
- {
- System.out.println(context + ", " + event);
- }
-}
\ No newline at end of file
Modified: arquillian/trunk/containers/osgi-embedded/src/main/java/org/jboss/arquillian/osgi/OSGiTestEnricher.java
===================================================================
--- arquillian/trunk/containers/osgi-embedded/src/main/java/org/jboss/arquillian/osgi/OSGiTestEnricher.java 2010-06-24 08:43:57 UTC (rev 4544)
+++ arquillian/trunk/containers/osgi-embedded/src/main/java/org/jboss/arquillian/osgi/OSGiTestEnricher.java 2010-06-24 08:45:22 UTC (rev 4545)
@@ -16,15 +16,20 @@
*/
package org.jboss.arquillian.osgi;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import javax.inject.Inject;
+
import org.jboss.arquillian.spi.Context;
import org.jboss.arquillian.spi.TestEnricher;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.launch.Framework;
/**
* [TODO] OSGiTestEnricher
*
- * @author Thomas.Diesler at jboss.com
+ * @author thomas.diesler at jboss.com
* @version $Revision: $
*/
public class OSGiTestEnricher implements TestEnricher
@@ -32,8 +37,49 @@
@Override
public void enrich(Context context, Object testCase)
{
+ Class<? extends Object> testClass = testCase.getClass();
+ for (Field field : testClass.getDeclaredFields())
+ {
+ if (field.isAnnotationPresent(Inject.class))
+ {
+ if (field.getType().isAssignableFrom(Framework.class))
+ {
+ injectFramework(context, testCase, field);
+ }
+ if (field.getType().isAssignableFrom(Bundle.class))
+ {
+ injectBundle(context, testCase, field);
+ }
+ }
+ }
}
+ private void injectFramework(Context context, Object testCase, Field field)
+ {
+ try
+ {
+ Framework framework = context.get(Framework.class);
+ field.set(testCase, framework);
+ }
+ catch (IllegalAccessException ex)
+ {
+ throw new IllegalStateException("Cannot inject Framework", ex);
+ }
+ }
+
+ private void injectBundle(Context context, Object testCase, Field field)
+ {
+ try
+ {
+ Bundle bundle = context.get(Bundle.class);
+ field.set(testCase, bundle);
+ }
+ catch (IllegalAccessException ex)
+ {
+ throw new IllegalStateException("Cannot inject Bundle", ex);
+ }
+ }
+
@Override
public Object[] resolve(Context context, Method method)
{
Modified: arquillian/trunk/containers/osgi-embedded/src/test/java/org/jboss/arquillian/osgi/OSGiEmbeddedIntegrationTestCase.java
===================================================================
--- arquillian/trunk/containers/osgi-embedded/src/test/java/org/jboss/arquillian/osgi/OSGiEmbeddedIntegrationTestCase.java 2010-06-24 08:43:57 UTC (rev 4544)
+++ arquillian/trunk/containers/osgi-embedded/src/test/java/org/jboss/arquillian/osgi/OSGiEmbeddedIntegrationTestCase.java 2010-06-24 08:45:22 UTC (rev 4545)
@@ -16,8 +16,13 @@
*/
package org.jboss.arquillian.osgi;
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
+
import java.io.InputStream;
+import javax.inject.Inject;
+
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.osgi.testing.OSGiManifestBuilder;
@@ -26,6 +31,8 @@
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.launch.Framework;
/**
* WeldEmbeddedIntegrationTestCase
@@ -53,8 +60,28 @@
return archive.addClasses(OSGiEmbeddedIntegrationTestCase.class);
}
+ @Inject
+ Framework framework;
+
@Test
- public void shouldBeAbleToInjectBeanAsInstanceVariable() throws Exception
+ public void testFrameworkInjection() throws Exception
{
+ assertNotNull("Framework injected", framework);
}
+
+ @Inject
+ Bundle bundle;
+
+ @Test
+ public void testbundleInjection() throws Exception
+ {
+ assertNotNull("Bundle injected", bundle);
+ assertEquals("Bundle INSTALLED", Bundle.INSTALLED, bundle.getState());
+
+ bundle.start();
+ assertEquals("Bundle ACTIVE", Bundle.ACTIVE, bundle.getState());
+
+ bundle.stop();
+ assertEquals("Bundle RESOLVED", Bundle.RESOLVED, bundle.getState());
+ }
}
Modified: arquillian/trunk/packagers/osgi/pom.xml
===================================================================
--- arquillian/trunk/packagers/osgi/pom.xml 2010-06-24 08:43:57 UTC (rev 4544)
+++ arquillian/trunk/packagers/osgi/pom.xml 2010-06-24 08:45:22 UTC (rev 4545)
@@ -1,65 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
- <!--
- vi:ts=2:sw=2:expandtab:
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<!-- vi:ts=2:sw=2:expandtab: -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <!-- Parent -->
- <parent>
- <groupId>org.jboss.arquillian</groupId>
- <artifactId>arquillian-build</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- <relativePath>../../build/pom.xml</relativePath>
- </parent>
+ <!-- Parent -->
+ <parent>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-build</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../../build/pom.xml</relativePath>
+ </parent>
- <!-- Model Version -->
- <modelVersion>4.0.0</modelVersion>
+ <!-- Model Version -->
+ <modelVersion>4.0.0</modelVersion>
- <!-- Artifact Configuration -->
- <groupId>org.jboss.arquillian.packager</groupId>
- <artifactId>arquillian-packager-osgi</artifactId>
- <name>Arquillian Packager Java EE</name>
- <description>Java EE Packager for the Arquillian project</description>
+ <!-- Artifact Configuration -->
+ <groupId>org.jboss.arquillian.packager</groupId>
+ <artifactId>arquillian-packager-osgi</artifactId>
+ <name>Arquillian Packager OSGi</name>
+ <description>OSGi Packager for the Arquillian project</description>
- <!-- Properties -->
- <properties>
+ <!-- Properties -->
+ <properties>
- </properties>
+ </properties>
- <!-- Dependencies -->
- <dependencies>
+ <!-- Dependencies -->
+ <dependencies>
- <!--
- org.jboss.arquillian
- -->
- <dependency>
- <groupId>org.jboss.arquillian</groupId>
- <artifactId>arquillian-spi</artifactId>
- <version>${project.version}</version>
- </dependency>
+ <!-- org.jboss.arquillian -->
+ <dependency>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
- <dependency>
- <groupId>org.jboss.shrinkwrap</groupId>
- <artifactId>shrinkwrap-impl-base</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jboss.shrinkwrap</groupId>
- <artifactId>shrinkwrap-spi</artifactId>
- </dependency>
+ <!-- org.jboss.osgi -->
+ <dependency>
+ <groupId>org.jboss.osgi</groupId>
+ <artifactId>jboss-osgi-spi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
- <!--
- External Projects
- -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
+ <dependency>
+ <groupId>org.jboss.shrinkwrap</groupId>
+ <artifactId>shrinkwrap-impl-base</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.shrinkwrap</groupId>
+ <artifactId>shrinkwrap-spi</artifactId>
+ </dependency>
- </dependencies>
+ <!-- External Projects -->
+ <dependency>
+ <groupId>org.jboss.osgi.vfs</groupId>
+ <artifactId>jboss-osgi-vfs30</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
</project>
Added: arquillian/trunk/packagers/osgi/src/main/java/org/jboss/arquillian/packager/osgi/BundleArchive.java
===================================================================
--- arquillian/trunk/packagers/osgi/src/main/java/org/jboss/arquillian/packager/osgi/BundleArchive.java (rev 0)
+++ arquillian/trunk/packagers/osgi/src/main/java/org/jboss/arquillian/packager/osgi/BundleArchive.java 2010-06-24 08:45:22 UTC (rev 4545)
@@ -0,0 +1,168 @@
+/*
+ * 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.arquillian.packager.osgi;
+
+import java.util.Map;
+
+import org.jboss.osgi.spi.util.BundleInfo;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ArchivePath;
+import org.jboss.shrinkwrap.api.Asset;
+import org.jboss.shrinkwrap.api.Assignable;
+import org.jboss.shrinkwrap.api.Filter;
+import org.jboss.shrinkwrap.api.Node;
+import org.jboss.shrinkwrap.api.formatter.Formatter;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+
+ at SuppressWarnings("rawtypes")
+public class BundleArchive implements Archive
+{
+ private Archive delegate;
+ private BundleInfo bundleInfo;
+
+ public BundleArchive(Archive<JavaArchive> archive, BundleInfo info)
+ {
+ this.delegate = archive;
+ this.bundleInfo = info;
+ }
+
+ public BundleInfo getBundleInfo()
+ {
+ return bundleInfo;
+ }
+
+ public <TYPE extends Assignable> TYPE as(Class<TYPE> clazz)
+ {
+ return delegate.as(clazz);
+ }
+
+ public String getName()
+ {
+ return delegate.getName();
+ }
+
+ public Archive add(Asset asset, ArchivePath target) throws IllegalArgumentException
+ {
+ return delegate.add(asset, target);
+ }
+
+ public Archive add(Asset asset, ArchivePath target, String name) throws IllegalArgumentException
+ {
+ return delegate.add(asset, target, name);
+ }
+
+ public Archive add(Asset asset, String target) throws IllegalArgumentException
+ {
+ return delegate.add(asset, target);
+ }
+
+ public Archive addDirectory(String path) throws IllegalArgumentException
+ {
+ return delegate.addDirectory(path);
+ }
+
+ public Archive addDirectories(String... paths) throws IllegalArgumentException
+ {
+ return delegate.addDirectories(paths);
+ }
+
+ public Archive addDirectory(ArchivePath path) throws IllegalArgumentException
+ {
+ return delegate.addDirectory(path);
+ }
+
+ public Archive addDirectories(ArchivePath... paths) throws IllegalArgumentException
+ {
+ return delegate.addDirectories(paths);
+ }
+
+ public Node get(ArchivePath path) throws IllegalArgumentException
+ {
+ return delegate.get(path);
+ }
+
+ public Node get(String path) throws IllegalArgumentException
+ {
+ return delegate.get(path);
+ }
+
+ public boolean contains(ArchivePath path) throws IllegalArgumentException
+ {
+ return delegate.contains(path);
+ }
+
+ public boolean delete(ArchivePath path) throws IllegalArgumentException
+ {
+ return delegate.delete(path);
+ }
+
+ public Map getContent()
+ {
+ return delegate.getContent();
+ }
+
+ @SuppressWarnings("unchecked")
+ public Map getContent(Filter filter)
+ {
+ return delegate.getContent(filter);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Archive add(Archive archive, ArchivePath path) throws IllegalArgumentException
+ {
+ return delegate.add(archive, path);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Archive merge(Archive source) throws IllegalArgumentException
+ {
+ return delegate.merge(source);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Archive merge(Archive source, Filter filter) throws IllegalArgumentException
+ {
+ return delegate.merge(source, filter);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Archive merge(Archive source, ArchivePath path) throws IllegalArgumentException
+ {
+ return delegate.merge(source, path);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Archive merge(Archive source, ArchivePath path, Filter filter) throws IllegalArgumentException
+ {
+ return delegate.merge(source, path, filter);
+ }
+
+ public String toString()
+ {
+ return delegate.toString();
+ }
+
+ public String toString(boolean verbose)
+ {
+ return delegate.toString(verbose);
+ }
+
+ public String toString(Formatter formatter) throws IllegalArgumentException
+ {
+ return delegate.toString(formatter);
+ }
+}
\ No newline at end of file
Modified: arquillian/trunk/packagers/osgi/src/main/java/org/jboss/arquillian/packager/osgi/OSGiDeploymentPackager.java
===================================================================
--- arquillian/trunk/packagers/osgi/src/main/java/org/jboss/arquillian/packager/osgi/OSGiDeploymentPackager.java 2010-06-24 08:43:57 UTC (rev 4544)
+++ arquillian/trunk/packagers/osgi/src/main/java/org/jboss/arquillian/packager/osgi/OSGiDeploymentPackager.java 2010-06-24 08:45:22 UTC (rev 4545)
@@ -16,107 +16,67 @@
*/
package org.jboss.arquillian.packager.osgi;
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
import java.util.Collection;
import org.jboss.arquillian.spi.DeploymentPackager;
+import org.jboss.osgi.spi.util.BundleInfo;
+import org.jboss.osgi.vfs.AbstractVFS;
+import org.jboss.osgi.vfs.VirtualFile;
import org.jboss.shrinkwrap.api.Archive;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
+import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
/**
* Packager for running Arquillian against OSGi containers.
*
- * @author Thomas.Diesler at jboss.com
+ * @author thomas.diesler at jboss.com
* @version $Revision: $
*/
public class OSGiDeploymentPackager implements DeploymentPackager
{
- public Archive<?> generateDeployment(Archive<?> applicationArchive, Collection<Archive<?>> auxiliaryArchives)
+ public Archive<?> generateDeployment(Archive<?> bundleArchive, Collection<Archive<?>> auxiliaryArchives)
{
- if(JavaArchive.class.isInstance(applicationArchive))
+ if(JavaArchive.class.isInstance(bundleArchive))
{
- return handleArchive(JavaArchive.class.cast(applicationArchive), auxiliaryArchives);
+ return handleArchive(JavaArchive.class.cast(bundleArchive), auxiliaryArchives);
}
throw new IllegalArgumentException(OSGiDeploymentPackager.class.getName() +
- " can not handle archive of type " + applicationArchive.getClass().getName());
+ " can not handle archive of type " + bundleArchive.getClass().getName());
}
- private Archive<?> handleArchive(JavaArchive applicationArchive, Collection<Archive<?>> auxiliaryArchives)
+ private Archive<?> handleArchive(JavaArchive archive, Collection<Archive<?>> auxiliaryArchives)
{
- if(containsArchiveOfType(WebArchive.class, auxiliaryArchives))
+ try
{
- EnterpriseArchive deployment = ShrinkWrap.create("test.ear", EnterpriseArchive.class)
- .addModule(applicationArchive);
- for (Archive<?> moduleArchive : auxiliaryArchives)
- {
- if (WebArchive.class.isInstance(moduleArchive))
- {
- deployment.addModule(moduleArchive);
- }
- else
- {
- deployment.addLibrary(moduleArchive);
- }
- }
- return deployment;
+ VirtualFile virtualFile = toVirtualFile(archive);
+ BundleInfo info = BundleInfo.createBundleInfo(virtualFile);
+ return new BundleArchive(archive, info);
}
- else
+ catch (RuntimeException rte)
{
- WebArchive deployment = ShrinkWrap.create("test.war", WebArchive.class);
- deployment.addLibraries(auxiliaryArchives.toArray(new Archive[0]));
- deployment.addLibraries(applicationArchive);
- return deployment;
+ throw rte;
}
- }
-
- private Archive<?> handleArchive(EnterpriseArchive applicationArchive, Collection<Archive<?>> auxiliaryArchives)
- {
- if(!containsArchiveOfType(WebArchive.class, auxiliaryArchives))
+ catch (Exception ex)
{
- for (Archive<?> moduleArchive : auxiliaryArchives)
- {
- if ("arquillian-protocol.jar".equals(moduleArchive.getName()) &&
- JavaArchive.class.isInstance(moduleArchive))
- {
- applicationArchive.addModule(
- ShrinkWrap.create("test.war", WebArchive.class)
- .addLibraries(moduleArchive));
- }
- else
- {
- applicationArchive.addLibrary(moduleArchive);
- }
- }
+ throw new IllegalArgumentException("Not a valid OSGi bundle: " + archive, ex);
}
- else
- {
- for (Archive<?> moduleArchive : auxiliaryArchives)
- {
- if (WebArchive.class.isInstance(moduleArchive))
- {
- applicationArchive.addModule(moduleArchive);
- }
- else
- {
- applicationArchive.addLibrary(moduleArchive);
- }
- }
- }
- return applicationArchive;
}
-
- private boolean containsArchiveOfType(Class<? extends Archive<?>> clazz, Collection<Archive<?>> archives)
+
+ private VirtualFile toVirtualFile(Archive<?> archive) throws IOException, MalformedURLException
{
- for(Archive<?> archive : archives)
- {
- if(clazz.isInstance(archive))
- {
- return true;
- }
- }
- return false;
+ // [TODO] Can this be done in memory?
+ ZipExporter exporter = archive.as(ZipExporter.class);
+ String archiveName = archive.getName();
+ int dotIndex = archiveName.lastIndexOf(".");
+ if (dotIndex > 0)
+ archiveName = archiveName.substring(0, dotIndex);
+ File target = File.createTempFile(archiveName + "-", ".jar");
+ exporter.exportZip(target, true);
+ target.deleteOnExit();
+ return AbstractVFS.getRoot(target.toURI().toURL());
}
}
\ No newline at end of file
Modified: arquillian/trunk/packagers/osgi/src/test/java/org/jboss/arquillian/packager/osgi/OSGiDeploymentPackagerTestCase.java
===================================================================
--- arquillian/trunk/packagers/osgi/src/test/java/org/jboss/arquillian/packager/osgi/OSGiDeploymentPackagerTestCase.java 2010-06-24 08:43:57 UTC (rev 4544)
+++ arquillian/trunk/packagers/osgi/src/test/java/org/jboss/arquillian/packager/osgi/OSGiDeploymentPackagerTestCase.java 2010-06-24 08:45:22 UTC (rev 4545)
@@ -16,155 +16,63 @@
*/
package org.jboss.arquillian.packager.osgi;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
+import static org.junit.Assert.*;
-import org.jboss.arquillian.packager.osgi.OSGiDeploymentPackager;
+import java.io.InputStream;
+
+import org.jboss.osgi.testing.OSGiManifestBuilder;
import org.jboss.shrinkwrap.api.Archive;
-import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.Asset;
import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.junit.Assert;
import org.junit.Test;
-
/**
- * EEDeploymentPackagerTestCase
+ * OSGiDeploymentPackagerTestCase
*
- * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @author thomas.diesler at jboss.com
* @version $Revision: $
*/
public class OSGiDeploymentPackagerTestCase
{
@Test
- public void shouldHandleJavaArchiveEE5Protocol() throws Exception
+ public void testValidBundle() throws Exception
{
- Archive<?> archive = new OSGiDeploymentPackager().generateDeployment(
- ShrinkWrap.create("applicationArchive.jar", JavaArchive.class),
- createAuxiliaryArchivesEE5());
-
- Assert.assertTrue(
- "Verify that a defined JavaArchive using EE5 WebArchive protocol is build as EnterpriseArchive",
- EnterpriseArchive.class.isInstance(archive));
-
- Assert.assertTrue(
- "Verify that the auxiliaryArchives EE Modules are placed in /",
- archive.contains(ArchivePaths.create("/arquillian-protocol.war")));
-
- Assert.assertTrue(
- "Verify that the auxiliaryArchives are placed in /lib",
- archive.contains(ArchivePaths.create("/lib/auxiliaryArchive2.jar")));
-
- Assert.assertTrue(
- "Verify that the applicationArchive is placed in /",
- archive.contains(ArchivePaths.create("/applicationArchive.jar")));
+ final JavaArchive archive = ShrinkWrap.create("test-archive.jar", JavaArchive.class);
+ archive.setManifest(new Asset()
+ {
+ public InputStream openStream()
+ {
+ OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
+ builder.addBundleSymbolicName(archive.getName());
+ builder.addBundleManifestVersion(2);
+ return builder.openStream();
+ }
+ });
+ Archive<?> result = new OSGiDeploymentPackager().generateDeployment(archive, null);
+ assertNotNull("Result archive not null", result);
}
@Test
- public void shouldHandleJavaArchiveEE6Protocol() throws Exception
+ public void testInvalidBundle() throws Exception
{
- Archive<?> archive = new OSGiDeploymentPackager().generateDeployment(
- ShrinkWrap.create("applicationArchive.jar", JavaArchive.class),
- createAuxiliaryArchivesEE6());
-
- Assert.assertTrue(
- "Verify that a defined JavaArchive using EE6 JavaArchive protocol is build as WebArchive",
- WebArchive.class.isInstance(archive));
-
- Assert.assertTrue(
- "Verify that the auxiliaryArchives are placed in /WEB-INF/lib",
- archive.contains(ArchivePaths.create("/WEB-INF/lib/arquillian-protocol.jar")));
-
- Assert.assertTrue(
- "Verify that the auxiliaryArchives are placed in /WEB-INF/lib",
- archive.contains(ArchivePaths.create("/WEB-INF/lib/auxiliaryArchive2.jar")));
-
- Assert.assertTrue(
- "Verify that the applicationArchive is placed in /WEB-INF/lib",
- archive.contains(ArchivePaths.create("/WEB-INF/lib/applicationArchive.jar")));
+ final JavaArchive archive = ShrinkWrap.create("test-archive.jar", JavaArchive.class);
+ archive.setManifest(new Asset()
+ {
+ public InputStream openStream()
+ {
+ OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
+ return builder.openStream();
+ }
+ });
+ try
+ {
+ new OSGiDeploymentPackager().generateDeployment(archive, null);
+ fail("RuntimeException expected");
+ }
+ catch (RuntimeException ex)
+ {
+ // expected
+ }
}
-
- // as of now, War inside War is not supported. need to merge ?
- @Test(expected = IllegalArgumentException.class)
- public void shouldHandleWebArchiveEE5Protocol() throws Exception
- {
- new OSGiDeploymentPackager().generateDeployment(
- ShrinkWrap.create("applicationArchive.war", WebArchive.class),
- createAuxiliaryArchivesEE5());
-
- }
-
- @Test
- public void shouldHandleWebArchiveEE6Protocol() throws Exception
- {
- Archive<?> archive = new OSGiDeploymentPackager().generateDeployment(
- ShrinkWrap.create("applicationArchive.war", WebArchive.class),
- createAuxiliaryArchivesEE6());
-
- Assert.assertTrue(
- "Verify that a defined WebArchive using EE6 JavaArchive protocol is build as WebArchive",
- WebArchive.class.isInstance(archive));
-
- Assert.assertTrue(
- "Verify that the auxiliaryArchives are placed in /WEB-INF/lib",
- archive.contains(ArchivePaths.create("/WEB-INF/lib/arquillian-protocol.jar")));
-
- Assert.assertTrue(
- "Verify that the auxiliaryArchives are placed in /WEB-INF/lib",
- archive.contains(ArchivePaths.create("/WEB-INF/lib/auxiliaryArchive2.jar")));
- }
-
- @Test
- public void shouldHandleEnterpriseArchiveEE5Protocol() throws Exception
- {
- Archive<?> archive = new OSGiDeploymentPackager().generateDeployment(
- ShrinkWrap.create("applicationArchive.ear", EnterpriseArchive.class),
- createAuxiliaryArchivesEE5());
-
- Assert.assertTrue(
- "Verify that the auxiliaryArchives are placed in /",
- archive.contains(ArchivePaths.create("arquillian-protocol.war")));
-
- Assert.assertTrue(
- "Verify that the auxiliaryArchives are placed in /lib",
- archive.contains(ArchivePaths.create("/lib/auxiliaryArchive2.jar")));
-
- }
-
- @Test
- public void shouldHandleEnterpriseArchiveEE6Protocol() throws Exception
- {
- Archive<?> archive = new OSGiDeploymentPackager().generateDeployment(
- ShrinkWrap.create("applicationArchive.ear", EnterpriseArchive.class),
- createAuxiliaryArchivesEE6());
-
- Assert.assertTrue(
- "Verify that the auxiliaryArchives are placed in /",
- archive.contains(ArchivePaths.create("test.war")));
-
- Assert.assertTrue(
- "Verify that the auxiliaryArchives are placed in /lib",
- archive.contains(ArchivePaths.create("/lib/auxiliaryArchive2.jar")));
- }
-
- private Collection<Archive<?>> createAuxiliaryArchivesEE6()
- {
- List<Archive<?>> archives = new ArrayList<Archive<?>>();
- archives.add(ShrinkWrap.create("arquillian-protocol.jar", JavaArchive.class));
- archives.add(ShrinkWrap.create("auxiliaryArchive2.jar", JavaArchive.class));
-
- return archives;
- }
-
- private Collection<Archive<?>> createAuxiliaryArchivesEE5()
- {
- List<Archive<?>> archives = new ArrayList<Archive<?>>();
- archives.add(ShrinkWrap.create("arquillian-protocol.war", WebArchive.class));
- archives.add(ShrinkWrap.create("auxiliaryArchive2.jar", JavaArchive.class));
-
- return archives;
- }
}
More information about the jboss-svn-commits
mailing list