Permalink
Browse files

ARQ-266 Update Weld SE Embedded Container to Weld 1.1 API

  • Loading branch information...
1 parent e0ac668 commit 03c2492f58a162e1dadabb5e68931bd1670ef1ab @aslakknutsen aslakknutsen committed Sep 5, 2010
Showing with 810 additions and 0 deletions.
  1. +1 −0 containers/pom.xml
  2. +117 −0 containers/weld-se-embedded-1.1/pom.xml
  3. +61 −0 ....1/src/main/java/org/jboss/arquillian/container/weld/se/embedded_1/ContextClassLoaderManager.java
  4. +36 −0 ...dded-1.1/src/main/java/org/jboss/arquillian/container/weld/se/embedded_1/WeldSEConfiguration.java
  5. +142 −0 ...embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/se/embedded_1/WeldSEContainer.java
  6. +38 −0 ...edded-1.1/src/main/java/org/jboss/arquillian/container/weld/se/embedded_1/WeldSETestEnricher.java
  7. +35 −0 ...org/jboss/arquillian/container/weld/se/embedded_1/shrinkwrap/ShrinkwrapBeanDeploymentArchive.java
  8. +210 −0 ...jboss/arquillian/container/weld/se/embedded_1/shrinkwrap/ShrinkwrapBeanDeploymentArchiveImpl.java
  9. +1 −0 ...ices/org.jboss.arquillian.container.weld.se.embedded_1.shrinkwrap.ShrinkwrapBeanDeploymentArchive
  10. +1 −0 ...embedded-1.1/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration
  11. +1 −0 ...se-embedded-1.1/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer
  12. +1 −0 ...s/weld-se-embedded-1.1/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestEnricher
  13. +75 −0 .../test/java/org/jboss/arquillian/container/weld/se/embedded_1/WeldEmbeddedIntegrationTestCase.java
  14. +34 −0 ...se-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/se/embedded_1/beans/MyBean.java
  15. +57 −0 ...s/arquillian/container/weld/se/embedded_1/shrinkwrap/ShrinkwrapBeanDeploymentArchiveTestCase.java
View
@@ -50,6 +50,7 @@
<module>jetty-embedded-7</module>
<module>tomcat-embedded-6</module>
<module>weld-se-embedded-1</module>
+ <module>weld-se-embedded-1.1</module>
<module>weld-ee-embedded-1.1</module>
<module>openejb-embedded-3.1</module>
<module>openwebbeans-embedded-1</module>
@@ -0,0 +1,117 @@
+<?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 -->
+ <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>
+
+ <!-- Artifact Configuration -->
+ <groupId>org.jboss.arquillian.container</groupId>
+ <artifactId>arquillian-weld-se-embedded-1.1</artifactId>
+ <name>Arquillian Container Weld SE Embedded 1.1.x</name>
+ <description>Weld SE 1.1.x Embedded Container integration for the Arquillian Project</description>
+
+
+ <!-- Properties -->
+ <properties>
+
+ <!-- Versioning -->
+ <version.weld_core>1.1.0.Beta1</version.weld_core>
+
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <!-- org.jboss.weld -->
+ <dependency>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-core-bom</artifactId>
+ <version>${version.weld_core}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <!-- Dependencies -->
+ <dependencies>
+
+ <!-- org.jboss.arquillian -->
+ <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.arquillian.testenricher</groupId>
+ <artifactId>arquillian-testenricher-cdi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.shrinkwrap</groupId>
+ <artifactId>shrinkwrap-impl-base</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.shrinkwrap</groupId>
+ <artifactId>shrinkwrap-extension-classloader</artifactId>
+ </dependency>
+
+ <!-- org.jboss.weld -->
+ <dependency>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>el-api</artifactId>
+ <version>2.2</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Test dependencies -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-junit</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
@@ -0,0 +1,61 @@
+/*
+ * 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.container.weld.se.embedded_1;
+
+import java.io.IOException;
+
+import org.jboss.shrinkwrap.classloader.ShrinkWrapClassLoader;
+
+/**
+ * ContextClassLoaderManager
+ *
+ * @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class ContextClassLoaderManager
+{
+ private ShrinkWrapClassLoader shrinkWrapClassLoader;
+ private ClassLoader contextClassLoader;
+
+ public ContextClassLoaderManager(final ShrinkWrapClassLoader shrinkWrapClassLoader)
+ {
+ if(shrinkWrapClassLoader == null)
+ {
+ throw new IllegalArgumentException("ShrinkWrapClassLoader must be specified");
+ }
+ this.shrinkWrapClassLoader = shrinkWrapClassLoader;
+ }
+
+ public void enable()
+ {
+ this.contextClassLoader = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(shrinkWrapClassLoader);
+ }
+
+ public void disable()
+ {
+ Thread.currentThread().setContextClassLoader(contextClassLoader);
+ try
+ {
+ this.shrinkWrapClassLoader.close();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Could not close ShrinkWrapClassLoader", e);
+ }
+ }
+}
@@ -0,0 +1,36 @@
+/*
+ * 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.container.weld.se.embedded_1;
+
+import org.jboss.arquillian.spi.ContainerConfiguration;
+import org.jboss.arquillian.spi.ContainerProfile;
+
+/**
+ * WeldSEConfiguration
+ *
+ * @author <a href="mailto:aknutsen@redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class WeldSEConfiguration implements ContainerConfiguration
+{
+
+ public ContainerProfile getContainerProfile()
+ {
+ return ContainerProfile.STANDALONE;
+ }
+
+}
@@ -0,0 +1,142 @@
+/*
+ * 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.container.weld.se.embedded_1;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+import javax.enterprise.inject.spi.Extension;
+
+import org.jboss.arquillian.container.weld.se.embedded_1.shrinkwrap.ShrinkwrapBeanDeploymentArchive;
+import org.jboss.arquillian.protocol.local.LocalMethodExecutor;
+import org.jboss.arquillian.spi.Configuration;
+import org.jboss.arquillian.spi.ContainerMethodExecutor;
+import org.jboss.arquillian.spi.Context;
+import org.jboss.arquillian.spi.DeployableContainer;
+import org.jboss.arquillian.spi.DeploymentException;
+import org.jboss.arquillian.spi.LifecycleException;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.weld.bootstrap.WeldBootstrap;
+import org.jboss.weld.bootstrap.api.Environments;
+import org.jboss.weld.bootstrap.api.ServiceRegistry;
+import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.weld.bootstrap.spi.Deployment;
+import org.jboss.weld.bootstrap.spi.Metadata;
+import org.jboss.weld.context.api.helpers.ConcurrentHashMapBeanStore;
+import org.jboss.weld.manager.api.WeldManager;
+
+/**
+ * WeldSEContainer
+ *
+ * @author <a href="mailto:aslak@conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class WeldSEContainer implements DeployableContainer
+{
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.DeployableContainer#setup(org.jboss.arquillian.spi.Context, org.jboss.arquillian.spi.Configuration)
+ */
+ public void setup(Context context, Configuration configuration)
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.DeployableContainer#start(org.jboss.arquillian.spi.Context)
+ */
+ public void start(Context context) throws LifecycleException
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.DeployableContainer#stop(org.jboss.arquillian.spi.Context)
+ */
+ public void stop(Context context) throws LifecycleException
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.DeployableContainer#deploy(org.jboss.arquillian.spi.Context, org.jboss.shrinkwrap.api.Archive)
+ */
+ public ContainerMethodExecutor deploy(Context context, final Archive<?> archive)
+ throws DeploymentException
+ {
+ final ShrinkwrapBeanDeploymentArchive beanArchive = archive.as(ShrinkwrapBeanDeploymentArchive.class);
+
+ final Deployment deployment = new Deployment()
+ {
+ public Collection<BeanDeploymentArchive> getBeanDeploymentArchives()
+ {
+ return Arrays.asList((BeanDeploymentArchive)beanArchive);
+ }
+
+ public ServiceRegistry getServices()
+ {
+ return beanArchive.getServices();
+ }
+
+ public BeanDeploymentArchive loadBeanDeploymentArchive(
+ Class<?> beanClass)
+ {
+ return beanArchive;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.weld.bootstrap.spi.Deployment#getExtensions()
+ */
+ public Iterable<Metadata<Extension>> getExtensions()
+ {
+ return Collections.emptyList();
+ }
+ };
+
+ ContextClassLoaderManager classLoaderManager = new ContextClassLoaderManager(beanArchive.getClassLoader());
+ classLoaderManager.enable();
+
+ context.add(ContextClassLoaderManager.class, classLoaderManager);
+
+ WeldBootstrap bootstrap = new WeldBootstrap();
+ beanArchive.setBootstrap(bootstrap);
+
+ bootstrap.startContainer(Environments.SE, deployment, new ConcurrentHashMapBeanStore())
+ .startInitialization()
+ .deployBeans()
+ .validateBeans()
+ .endInitialization();
+
+ WeldManager manager = bootstrap.getManager(beanArchive);
+
+ context.add(WeldBootstrap.class, bootstrap);
+ context.add(WeldManager.class, manager);
+
+ return new LocalMethodExecutor();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.DeployableContainer#undeploy(org.jboss.arquillian.spi.Context, org.jboss.shrinkwrap.api.Archive)
+ */
+ public void undeploy(Context context, Archive<?> archive) throws DeploymentException
+ {
+ WeldBootstrap bootstrap = context.get(WeldBootstrap.class);
+ if(bootstrap != null)
+ {
+ bootstrap.shutdown();
+ }
+ ContextClassLoaderManager classLoaderManager = context.get(ContextClassLoaderManager.class);
+ classLoaderManager.disable();
+ }
+}
Oops, something went wrong.

0 comments on commit 03c2492

Please sign in to comment.