[jboss-svn-commits] JBoss Common SVN: r4214 - in arquillian/trunk/containers: openwebbeans-embedded and 11 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Apr 4 16:37:44 EDT 2010


Author: dan.j.allen
Date: 2010-04-04 16:37:43 -0400 (Sun, 04 Apr 2010)
New Revision: 4214

Added:
   arquillian/trunk/containers/openwebbeans-embedded/
   arquillian/trunk/containers/openwebbeans-embedded/pom.xml
   arquillian/trunk/containers/openwebbeans-embedded/src/
   arquillian/trunk/containers/openwebbeans-embedded/src/main/
   arquillian/trunk/containers/openwebbeans-embedded/src/main/java/
   arquillian/trunk/containers/openwebbeans-embedded/src/main/java/org/
   arquillian/trunk/containers/openwebbeans-embedded/src/main/java/org/jboss/
   arquillian/trunk/containers/openwebbeans-embedded/src/main/java/org/jboss/arquillian/
   arquillian/trunk/containers/openwebbeans-embedded/src/main/java/org/jboss/arquillian/openwebbeans/
   arquillian/trunk/containers/openwebbeans-embedded/src/main/java/org/jboss/arquillian/openwebbeans/OpenWebBeansSEContainer.java
   arquillian/trunk/containers/openwebbeans-embedded/src/main/java/org/jboss/arquillian/openwebbeans/OpenWebBeansSETestEnricher.java
   arquillian/trunk/containers/openwebbeans-embedded/src/main/java/org/jboss/arquillian/openwebbeans/ShrinkWrapClassLoader.java
   arquillian/trunk/containers/openwebbeans-embedded/src/main/java/org/jboss/arquillian/openwebbeans/ShrinkWrapMetaDataDiscovery.java
   arquillian/trunk/containers/openwebbeans-embedded/src/main/resources/
   arquillian/trunk/containers/openwebbeans-embedded/src/main/resources/META-INF/
   arquillian/trunk/containers/openwebbeans-embedded/src/main/resources/META-INF/services/
   arquillian/trunk/containers/openwebbeans-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer
   arquillian/trunk/containers/openwebbeans-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestEnricher
   arquillian/trunk/containers/openwebbeans-embedded/src/test/
   arquillian/trunk/containers/openwebbeans-embedded/src/test/java/
   arquillian/trunk/containers/openwebbeans-embedded/src/test/resources/
Log:
ARQ-96 OpenWebBeans embedded container implementation



Property changes on: arquillian/trunk/containers/openwebbeans-embedded
___________________________________________________________________
Name: svn:ignore
   + target


Added: arquillian/trunk/containers/openwebbeans-embedded/pom.xml
===================================================================
--- arquillian/trunk/containers/openwebbeans-embedded/pom.xml	                        (rev 0)
+++ arquillian/trunk/containers/openwebbeans-embedded/pom.xml	2010-04-04 20:37:43 UTC (rev 4214)
@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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>
+      <groupId>org.jboss.arquillian</groupId>
+      <artifactId>arquillian-build</artifactId>
+      <version>1.0.0-SNAPSHOT</version>
+      <relativePath>../build/pom.xml</relativePath>
+   </parent>
+
+   <modelVersion>4.0.0</modelVersion>
+
+   <groupId>org.jboss.arquillian.container</groupId>
+   <artifactId>arquillian-openwebbeans-embedded</artifactId>
+   <name>Arquillian Container OpenWebBeans Embedded</name>
+   <description>OpenWebBeans Embedded Container integration for the Arquillian Project</description>
+
+   <properties>
+      <version.openwebbeans>1.0.0-M4</version.openwebbeans>
+   </properties>
+
+   <dependencies>
+
+      <dependency>
+         <groupId>org.jboss.arquillian</groupId>
+         <artifactId>arquillian-spi</artifactId>
+         <version>${project.version}</version>
+      </dependency>
+
+      <dependency>
+         <groupId>org.jboss.arquillian.protocol</groupId>
+         <artifactId>arquillian-protocol-local</artifactId>
+         <version>${project.version}</version>
+      </dependency>
+
+      <dependency>
+         <groupId>org.jboss.shrinkwrap</groupId>
+         <artifactId>shrinkwrap-impl-base</artifactId>
+      </dependency>
+
+      <dependency>
+         <groupId>org.jboss.arquillian.packager</groupId>
+         <artifactId>arquillian-packager-applicationarchive</artifactId>
+         <version>${project.version}</version>
+      </dependency>
+
+      <dependency>
+         <groupId>org.jboss.arquillian.testenricher</groupId>
+         <artifactId>arquillian-testenricher-cdi</artifactId>
+         <version>${project.version}</version>
+      </dependency>
+
+      <dependency>
+         <groupId>org.apache.openwebbeans</groupId>
+         <artifactId>openwebbeans-spi</artifactId>
+         <version>${version.openwebbeans}</version>
+      </dependency>   
+
+      <dependency>
+         <groupId>org.apache.openwebbeans</groupId>
+         <artifactId>openwebbeans-impl</artifactId>
+            <version>${version.openwebbeans}</version>
+      </dependency>
+
+      <dependency>
+         <groupId>org.apache.geronimo.specs</groupId>
+         <artifactId>geronimo-el_2.2_spec</artifactId>
+            <version>1.0-beta</version>
+      </dependency>
+
+      <dependency>
+         <groupId>org.apache.geronimo.specs</groupId>
+         <artifactId>geronimo-validation_1.0_spec</artifactId>
+         <version>1.0</version>
+      </dependency>
+
+      <dependency>
+         <groupId>org.apache.geronimo.specs</groupId>
+         <artifactId>geronimo-jta_1.1_spec</artifactId>
+         <version>1.1.1</version>
+      </dependency>
+
+      <dependency>
+         <groupId>org.apache.geronimo.specs</groupId>
+         <artifactId>geronimo-interceptor_1.1_spec</artifactId>
+         <version>1.0.0-beta</version>
+      </dependency>
+
+      <dependency>
+         <groupId>org.apache.geronimo.specs</groupId>
+         <artifactId>geronimo-jcdi_1.0_spec</artifactId>
+         <version>1.0-beta</version>
+      </dependency>
+
+      <dependency>
+         <groupId>org.apache.geronimo.specs</groupId>
+         <artifactId>geronimo-atinject_1.0_spec</artifactId>
+         <version>1.0-beta</version>
+      </dependency>
+
+      <dependency>
+         <groupId>org.apache.geronimo.specs</groupId>
+         <artifactId>geronimo-servlet_2.5_spec</artifactId>
+         <version>1.2</version>
+      </dependency>
+
+      <dependency>
+         <groupId>junit</groupId>
+         <artifactId>junit</artifactId>
+         <scope>test</scope>
+      </dependency>
+
+   </dependencies>
+</project>

Added: arquillian/trunk/containers/openwebbeans-embedded/src/main/java/org/jboss/arquillian/openwebbeans/OpenWebBeansSEContainer.java
===================================================================
--- arquillian/trunk/containers/openwebbeans-embedded/src/main/java/org/jboss/arquillian/openwebbeans/OpenWebBeansSEContainer.java	                        (rev 0)
+++ arquillian/trunk/containers/openwebbeans-embedded/src/main/java/org/jboss/arquillian/openwebbeans/OpenWebBeansSEContainer.java	2010-04-04 20:37:43 UTC (rev 4214)
@@ -0,0 +1,333 @@
+/*
+ * JBoss, Community-driven Open Source Middleware
+ * Copyright 2010, JBoss by Red Hat, Inc., 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.openwebbeans;
+
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.UUID;
+import java.util.logging.Logger;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionContext;
+import org.apache.webbeans.context.ContextFactory;
+import org.apache.webbeans.lifecycle.StandaloneLifeCycle;
+import org.apache.webbeans.spi.ContainerLifecycle;
+
+import org.jboss.arquillian.protocol.local.LocalMethodExecutor;
+import org.jboss.arquillian.spi.ContainerMethodExecutor;
+import org.jboss.arquillian.spi.DeployableContainer;
+import org.jboss.arquillian.spi.DeploymentException;
+import org.jboss.arquillian.spi.LifecycleException;
+import org.jboss.arquillian.spi.TestMethodExecutor;
+import org.jboss.arquillian.spi.TestResult;
+import org.jboss.shrinkwrap.api.Archive;
+
+/**
+ * An embedded Arquillian container for OpenWebBeans
+ *
+ * <p>This {@link DeployableContainer} implementation provides an embedded
+ * container that bootstraps the OpenWebBeans JSR-299 implementation in SE (or
+ * standalone) mode. It's akin to the Weld embedded container.</p>
+ *
+ * <p>The OpenWebBeans container is started in the deploy() method and shutdown
+ * in the undeploy() method. The container is controlled using the {@link
+ * StandaloneLifeCycle} from OpenWebBeans. The default discovery service
+ * (metadata scanner) is replaced by a discovery service that is adapted to load
+ * /META-INF/beans.xml resources and managed bean classes from a ShrinkWrap
+ * archive.</p>
+ *
+ * <p>The current thread's context ClassLoader is also replaced with a
+ * ClassLoader implementation that can discover resources in a ShrinkWrap
+ * archive.</p>
+ *
+ * @author <a href="mailto:dan.allen at mojavelinux.com">Dan Allen</a>
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ * @see org.jboss.arquillian.weld.WeldSEContainer
+ */
+public class OpenWebBeansSEContainer implements DeployableContainer
+{
+   private static final Logger log = Logger.getLogger(OpenWebBeansSEContainer.class.getName());
+
+   public final static ThreadLocal<ContainerInstanceHolder> CONTAINER_INSTANCE_HOLDER = new ThreadLocal<ContainerInstanceHolder>();
+   
+   /**
+    * @see org.jboss.arquillian.spi.DeployableContainer#start()
+    */
+   @Override
+   public void start() throws LifecycleException
+   {
+   }
+
+   /**
+    * @see org.jboss.arquillian.spi.DeployableContainer#stop()
+    */
+   @Override
+   public void stop() throws LifecycleException
+   {
+   }
+
+   /**
+    * @see org.jboss.arquillian.spi.DeployableContainer#deploy(org.jboss.shrinkwrap.api.Archive)
+    */
+   @Override
+   public ContainerMethodExecutor deploy(final Archive<?> archive)
+         throws DeploymentException
+   {
+      ClassLoader cl = new ShrinkWrapClassLoader(archive);
+
+      Thread.currentThread().setContextClassLoader(cl);
+
+      final ShrinkWrapMetaDataDiscovery discovery = new ShrinkWrapMetaDataDiscovery(archive);
+      ContainerLifecycle lifecycle = new StandaloneLifeCycle()
+      {
+         // TODO this override method will need to change to afterInitApplication(Properties) after 1.0.0-M4
+         @Override
+         public void init()
+         {
+            super.init();
+            log.info("Using discovery service impl class adapted to ShrinkWrap archive : [" + discovery.getClass().getName() + "]");
+            this.discoveryService = discovery;
+         }
+      };
+
+      try
+      {
+         lifecycle.start(null);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Failed to start standalone OpenWebBeans container", e);
+      }
+
+      BeanManager manager = lifecycle.getBeanManager();
+
+      // start the application lifecycle
+      ContextFactory.initApplicationContext(null);
+      // start the session lifecycle
+      HttpSession session = new MockHttpSession();
+      ContextFactory.initSessionContext(session);
+      
+      CONTAINER_INSTANCE_HOLDER.set(new ContainerInstanceHolder(lifecycle, session, manager));
+
+      // TODO: replace with a before/after invoke interceptor ?
+      return new LocalMethodExecutor() {
+         @Override
+         public TestResult invoke(TestMethodExecutor testMethodExecutor)
+         {
+            try 
+            {
+            	// start the request lifecycle
+               ContextFactory.initRequestContext(null);
+               ContextFactory.initConversationContext(null);
+               return super.invoke(testMethodExecutor);
+            } 
+            finally
+            {
+            	// end the request lifecycle
+               ContextFactory.destroyConversationContext();
+               ContextFactory.destroyRequestContext(null);
+            }
+         }
+      };
+   }
+
+   /**
+    * @see org.jboss.arquillian.spi.DeployableContainer#undeploy(org.jboss.shrinkwrap.api.Archive)
+    */
+   @Override
+   public void undeploy(Archive<?> archive) throws DeploymentException
+   {
+      ContainerInstanceHolder holder = CONTAINER_INSTANCE_HOLDER.get();
+      if (holder != null) {
+         // end the session lifecycle
+         ContextFactory.destroySessionContext(holder.getSession());
+         ContextFactory.destroyApplicationContext(null);
+         
+         holder.getLifecycle().stop(null);
+         Thread.currentThread().setContextClassLoader(Thread.currentThread().getContextClassLoader().getParent());
+      }
+      CONTAINER_INSTANCE_HOLDER.set(null);
+   }
+   
+   public static class ContainerInstanceHolder {
+      
+      private BeanManager manager;
+
+      private ContainerLifecycle lifecycle;
+
+      private HttpSession session;
+
+      public ContainerInstanceHolder(ContainerLifecycle lifecycle, HttpSession session, BeanManager manager)
+      {
+         super();
+         this.lifecycle = lifecycle;
+         this.session = session;
+         this.manager = manager;
+      }
+
+      public ContainerLifecycle getLifecycle()
+      {
+         return lifecycle;
+      }
+
+      public HttpSession getSession()
+      {
+         return session;
+      }
+
+      public BeanManager getManager()
+      {
+         return manager;
+      }
+   }
+
+   private class MockHttpSession implements HttpSession
+   {
+      private final long creationTime;
+      private final String id;
+      private final Map<String, Object> attributes;
+      private int maxInactiveInterval = 60000;
+
+      public MockHttpSession()
+      {
+         creationTime = System.currentTimeMillis();
+         id = UUID.randomUUID().toString();
+         attributes = new HashMap<String, Object>();
+      }
+
+      @Override
+      public long getCreationTime()
+      {
+         return creationTime;
+      }
+
+      @Override
+      public String getId()
+      {
+         return id;
+      }
+
+      @Override
+      public long getLastAccessedTime()
+      {
+         return creationTime;
+      }
+
+      @Override
+      public ServletContext getServletContext()
+      {
+         throw new UnsupportedOperationException("Not supported.");
+      }
+
+      @Override
+      public void setMaxInactiveInterval(int i)
+      {
+         this.maxInactiveInterval = i;
+      }
+
+      @Override
+      public int getMaxInactiveInterval()
+      {
+         return maxInactiveInterval;
+      }
+
+      @Override
+      public HttpSessionContext getSessionContext()
+      {
+         throw new UnsupportedOperationException("Not supported.");
+      }
+
+      @Override
+      public Object getAttribute(String string)
+      {
+         return attributes.get(string);
+      }
+
+      @Override
+      public Object getValue(String string)
+      {
+         return getAttribute(string);
+      }
+
+      @Override
+      public Enumeration getAttributeNames()
+      {
+         final Iterator<String> nameIt = attributes.keySet().iterator();
+         return new Enumeration() {
+
+            @Override
+            public boolean hasMoreElements()
+            {
+               return nameIt.hasNext();
+            }
+
+            @Override
+            public Object nextElement()
+            {
+               return nameIt.next();
+            }
+         };
+      }
+
+      @Override
+      public String[] getValueNames()
+      {
+         return attributes.keySet().toArray(new String[0]);
+      }
+
+      @Override
+      public void setAttribute(String string, Object value)
+      {
+         attributes.put(string, value);
+      }
+
+      @Override
+      public void putValue(String string, Object value)
+      {
+         setAttribute(string, value);
+      }
+
+      @Override
+      public void removeAttribute(String string)
+      {
+         attributes.remove(string);
+      }
+
+      @Override
+      public void removeValue(String string)
+      {
+         removeAttribute(string);
+      }
+
+      @Override
+      public void invalidate()
+      {
+         attributes.clear();
+      }
+
+      @Override
+      public boolean isNew()
+      {
+         return true;
+      }
+
+   }
+}

Added: arquillian/trunk/containers/openwebbeans-embedded/src/main/java/org/jboss/arquillian/openwebbeans/OpenWebBeansSETestEnricher.java
===================================================================
--- arquillian/trunk/containers/openwebbeans-embedded/src/main/java/org/jboss/arquillian/openwebbeans/OpenWebBeansSETestEnricher.java	                        (rev 0)
+++ arquillian/trunk/containers/openwebbeans-embedded/src/main/java/org/jboss/arquillian/openwebbeans/OpenWebBeansSETestEnricher.java	2010-04-04 20:37:43 UTC (rev 4214)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Community-driven Open Source Middleware
+ * Copyright 2010, JBoss by Red Hat, Inc., 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.openwebbeans;
+
+import javax.enterprise.inject.spi.BeanManager;
+import org.jboss.arquillian.openwebbeans.OpenWebBeansSEContainer.ContainerInstanceHolder;
+
+import org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher;
+
+/**
+ * A CDI injection enricher adaptor that retrieves the {@link BeanManager} from
+ * the thread local for the current OpenWebBeans container instance.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @author <a href="mailto:dan.allen at mojavelinux.com">Dan Allen</a>
+ * @version $Revision: $
+ */
+public class OpenWebBeansSETestEnricher extends CDIInjectionEnricher
+{
+   @Override
+   protected BeanManager lookupBeanManager()
+   {
+      ContainerInstanceHolder holder = OpenWebBeansSEContainer.CONTAINER_INSTANCE_HOLDER.get();
+      if (holder != null)
+      {
+         return holder.getManager();
+      }
+      return null;
+   }
+}

Added: arquillian/trunk/containers/openwebbeans-embedded/src/main/java/org/jboss/arquillian/openwebbeans/ShrinkWrapClassLoader.java
===================================================================
--- arquillian/trunk/containers/openwebbeans-embedded/src/main/java/org/jboss/arquillian/openwebbeans/ShrinkWrapClassLoader.java	                        (rev 0)
+++ arquillian/trunk/containers/openwebbeans-embedded/src/main/java/org/jboss/arquillian/openwebbeans/ShrinkWrapClassLoader.java	2010-04-04 20:37:43 UTC (rev 4214)
@@ -0,0 +1,117 @@
+/*
+ * JBoss, Community-driven Open Source Middleware
+ * Copyright 2010, JBoss by Red Hat, Inc., 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.openwebbeans;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+import java.security.SecureClassLoader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.Iterator;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.Asset;
+
+/**
+ * A ClassLoader implementation that can locate resources in a ShrinkWrap archive
+ *
+ * <p><strong>NOTE</strong> This is a prototype implementation of this concept. It 
+ * does not address all classloading concerns as of yet.</p>
+ *
+ * @author <a href="mailto:dan.allen at mojavelinux.com">Dan Allen</a>
+ */
+public class ShrinkWrapClassLoader extends SecureClassLoader
+{
+   public static final String ARCHIVE_PROTOCOL = "archive:/";
+
+   private final Archive<?> archive;
+
+   public ShrinkWrapClassLoader(Archive<?> archive)
+   {
+      super();
+      this.archive = archive;
+   }
+
+   @Override
+   protected URL findResource(final String name)
+   {
+      final Asset a = archive.get(name);
+      if (a == null)
+      {
+         return null;
+      }
+      try
+      {
+         return new URL(null, ARCHIVE_PROTOCOL + name, new URLStreamHandler()
+         {
+            @Override
+            protected java.net.URLConnection openConnection(URL u) throws java.io.IOException
+            {
+               return new URLConnection(u)
+               {
+                  @Override
+                  public void connect() throws IOException
+                  {
+                  }
+
+                  @Override
+                  public InputStream getInputStream()
+                        throws IOException
+                  {
+                     return a.openStream();
+                  }
+               };
+            }
+
+            ;
+         });
+      }
+      catch (Exception e)
+      {
+         return null;
+      }
+   }
+
+   @Override
+   protected Enumeration<URL> findResources(String name) throws IOException
+   {
+      Iterator<URL> it = new ArrayList<URL>(0).iterator();
+      URL resource = findResource(name);
+      if (resource != null)
+      {
+         it = Arrays.asList(resource).iterator();
+      }
+      final Iterator<URL> i = it;
+      return new Enumeration<URL>()
+      {
+         @Override
+         public boolean hasMoreElements()
+         {
+            return i.hasNext();
+         }
+
+         @Override
+         public URL nextElement()
+         {
+            return i.next();
+         }
+      };
+   }
+}

Added: arquillian/trunk/containers/openwebbeans-embedded/src/main/java/org/jboss/arquillian/openwebbeans/ShrinkWrapMetaDataDiscovery.java
===================================================================
--- arquillian/trunk/containers/openwebbeans-embedded/src/main/java/org/jboss/arquillian/openwebbeans/ShrinkWrapMetaDataDiscovery.java	                        (rev 0)
+++ arquillian/trunk/containers/openwebbeans-embedded/src/main/java/org/jboss/arquillian/openwebbeans/ShrinkWrapMetaDataDiscovery.java	2010-04-04 20:37:43 UTC (rev 4214)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, Community-driven Open Source Middleware
+ * Copyright 2010, JBoss by Red Hat, Inc., 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.openwebbeans;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+import java.util.Map;
+import org.apache.webbeans.spi.deployer.AbstractMetaDataDiscovery;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ArchivePath;
+import org.jboss.shrinkwrap.api.Asset;
+import org.jboss.shrinkwrap.api.Filters;
+import org.jboss.shrinkwrap.impl.base.asset.ClassAsset;
+
+/**
+ * A ScannerService implementation that processes a ShrinkWrap bean archive
+ *
+ * <p>Arquillian supplies an in-memory ShrinkWrap archive which the test class
+ * is to use to load classes and resources. This implementation of the
+ * OpenWebBeans ScannerService SPI looks for the presence of a
+ * /META-INF/beans.xml in the ShrinkWrap archive. If present, it registers the
+ * location with the OpenWebBeans container, then proceeds to retrieve classes
+ * from that archive and pass them to the AnnotationDB to be scanned and
+ * processed as managed bean classes.</p>
+ *
+ * @author <a href="mailto:dan.allen at mojavelinux.com">Dan Allen</a>
+ */
+public class ShrinkWrapMetaDataDiscovery extends AbstractMetaDataDiscovery
+{
+   private Archive<?> archive;
+
+   public ShrinkWrapMetaDataDiscovery(Archive<?> archive)
+   {
+      super();
+      this.archive = archive;
+   }
+
+   @Override
+   protected void configure() throws Exception
+   {
+      Map<ArchivePath, Asset> beansXmls = archive.getContent(Filters.include("/META-INF/beans.xml"));
+	  boolean beansXmlPresent = false;
+      for (final Map.Entry<ArchivePath, Asset> entry : beansXmls.entrySet())
+      {
+         try
+         {
+            addWebBeansXmlLocation(
+                  new URL(null, "archive:/" + entry.getKey().get(), new URLStreamHandler()
+                  {
+                     @Override
+                     protected java.net.URLConnection openConnection(URL u) throws java.io.IOException
+                     {
+                        return new URLConnection(u)
+                        {
+                           @Override
+                           public void connect() throws IOException {}
+
+                           @Override
+                           public InputStream getInputStream() throws IOException
+                           {
+                              return entry.getValue().openStream();
+                           }
+                        };
+                     };
+                  }));
+		    beansXmlPresent = true;
+         }
+         catch (Exception e)
+         {
+            e.printStackTrace();
+         }
+      }
+
+	  if (beansXmlPresent)
+	  {
+         Map<ArchivePath, Asset> classes = archive.getContent(Filters.include(".*\\.class"));
+         for (Map.Entry<ArchivePath, Asset> classEntry : classes.entrySet())
+         {
+            if (classEntry.getValue() instanceof ClassAsset)
+            {
+               try
+               {
+                  getAnnotationDB().scanClass(((ClassAsset) classEntry.getValue()).openStream());
+               }
+               catch (Exception e)
+               {
+                  e.printStackTrace();
+               }
+            }
+         }
+	  }
+   }
+}

Added: arquillian/trunk/containers/openwebbeans-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer
===================================================================
--- arquillian/trunk/containers/openwebbeans-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer	                        (rev 0)
+++ arquillian/trunk/containers/openwebbeans-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer	2010-04-04 20:37:43 UTC (rev 4214)
@@ -0,0 +1 @@
+org.jboss.arquillian.openwebbeans.OpenWebBeansSEContainer

Added: arquillian/trunk/containers/openwebbeans-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestEnricher
===================================================================
--- arquillian/trunk/containers/openwebbeans-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestEnricher	                        (rev 0)
+++ arquillian/trunk/containers/openwebbeans-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestEnricher	2010-04-04 20:37:43 UTC (rev 4214)
@@ -0,0 +1 @@
+org.jboss.arquillian.openwebbeans.OpenWebBeansSETestEnricher



More information about the jboss-svn-commits mailing list