You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ro...@apache.org on 2019/11/25 18:43:30 UTC

[aries-cdi] 11/27: add Weld CDI container that uses the Aries CDI SPI

This is an automated email from the ASF dual-hosted git repository.

rotty3000 pushed a commit to branch rotty3000/cdi-spi
in repository https://gitbox.apache.org/repos/asf/aries-cdi.git

commit 116023907d526ec63f56f4cf7cbad1a6f2c4528f
Author: Raymond Augé <ro...@apache.org>
AuthorDate: Fri Nov 22 16:45:53 2019 -0500

    add Weld CDI container that uses the Aries CDI SPI
    
    Signed-off-by: Raymond Augé <ro...@apache.org>
---
 cdi-bom/pom.xml                                    |   6 +
 cdi-weld/pom.xml                                   | 162 ++++++++++++
 .../java/org/apache/aries/cdi/weld/Activator.java  |  55 ++++
 .../aries/cdi/weld/BundleResourcesLoader.java      | 115 +++++++++
 .../apache/aries/cdi/weld/ContainerDeployment.java |  66 +++++
 .../aries/cdi/weld/ContainerDeploymentArchive.java |  84 +++++++
 .../aries/cdi/weld/ContainerEnvironment.java       |  43 ++++
 .../apache/aries/cdi/weld/ExtensionMetadata.java   |  41 +++
 .../aries/cdi/weld/WeldSeContainerInitializer.java | 280 +++++++++++++++++++++
 .../weld/WeldSeContainerInitializerFactory.java    |  44 ++++
 .../org/apache/aries/cdi/weld/package-info.java    |  23 ++
 pom.xml                                            |  40 +--
 12 files changed, 920 insertions(+), 39 deletions(-)

diff --git a/cdi-bom/pom.xml b/cdi-bom/pom.xml
index d3b97c4..c383257 100644
--- a/cdi-bom/pom.xml
+++ b/cdi-bom/pom.xml
@@ -88,6 +88,12 @@
 				<scope>runtime</scope>
 			</dependency>
 			<dependency>
+				<groupId>org.apache.aries.cdi</groupId>
+				<artifactId>org.apache.aries.cdi.weld</artifactId>
+				<version>${project.version}</version>
+				<scope>runtime</scope>
+			</dependency>
+			<dependency>
 				<groupId>org.apache.aries.spifly</groupId>
 				<artifactId>org.apache.aries.spifly.dynamic.framework.extension</artifactId>
 				<version>1.2</version>
diff --git a/cdi-weld/pom.xml b/cdi-weld/pom.xml
new file mode 100644
index 0000000..bbb8f9d
--- /dev/null
+++ b/cdi-weld/pom.xml
@@ -0,0 +1,162 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+/**
+ * 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.
+ */
+-->
+
+<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">
+
+	<modelVersion>4.0.0</modelVersion>
+
+	<parent>
+		<groupId>org.apache.aries.cdi</groupId>
+		<artifactId>org.apache.aries.cdi</artifactId>
+		<version>1.0.3-SNAPSHOT</version>
+		<relativePath>..</relativePath>
+	</parent>
+
+	<artifactId>org.apache.aries.cdi.weld</artifactId>
+	<name>Apache Aries CDI - Container using JBoss Weld</name>
+	<description>Apache Aries CDI - Container using JBoss Weld</description>
+
+	<licenses>
+		<license>
+			<name>ASL 2.0</name>
+			<url>https://www.apache.org/licenses/LICENSE-2.0</url>
+		</license>
+	</licenses>
+
+	<scm>
+		<connection>scm:git:git@github.com:apache/aries-cdi.git</connection>
+		<developerConnection>scm:git:git@github.com:apache/aries-cdi.git</developerConnection>
+		<tag>HEAD</tag>
+		<url>https://github.com/apache/aries-cdi</url>
+	</scm>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>biz.aQute.bnd</groupId>
+				<artifactId>bnd-maven-plugin</artifactId>
+				<configuration>
+					<bnd><![CDATA[
+						-cdiannotations:
+						-noclassforname: true
+					]]></bnd>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.aries.cdi</groupId>
+			<artifactId>org.apache.aries.cdi.extra</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.aries.cdi</groupId>
+			<artifactId>org.apache.aries.cdi.spi</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.geronimo.specs</groupId>
+			<artifactId>geronimo-annotation_1.3_spec</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.geronimo.specs</groupId>
+			<artifactId>geronimo-atinject_1.0_spec</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.geronimo.specs</groupId>
+			<artifactId>geronimo-interceptor_1.2_spec</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.geronimo.specs</groupId>
+			<artifactId>geronimo-jcdi_2.0_spec</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.jboss.weld</groupId>
+			<artifactId>weld-osgi-bundle</artifactId>
+			<version>${weld.version}</version>
+			<exclusions>
+				<exclusion>
+					<groupId>javax.annotation</groupId>
+					<artifactId>javax.annotation-api</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>javax.enterprise</groupId>
+					<artifactId>cdi-api</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>javax.inject</groupId>
+					<artifactId>javax.inject</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>org.jboss.spec.javax.annotation</groupId>
+					<artifactId>jboss-annotations-api_1.3_spec</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>org.jboss.spec.javax.ejb</groupId>
+					<artifactId>jboss-ejb-api_3.2_spec</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>org.jboss.spec.javax.el</groupId>
+					<artifactId>jboss-el-api_3.0_spec</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>org.jboss.spec.javax.interceptor</groupId>
+					<artifactId>jboss-interceptors-api_1.2_spec</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>org.jboss.spec.javax.transaction</groupId>
+					<artifactId>jboss-transaction-api_1.2_spec</artifactId>
+				</exclusion>
+			</exclusions>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.apache.felix.http.servlet-api</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>org.osgi.namespace.extender</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>org.osgi.namespace.implementation</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>org.osgi.namespace.service</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>org.osgi.service.cdi</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>org.osgi.service.http.whiteboard</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>osgi.annotation</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>osgi.core</artifactId>
+		</dependency>
+	</dependencies>
+
+</project>
\ No newline at end of file
diff --git a/cdi-weld/src/main/java/org/apache/aries/cdi/weld/Activator.java b/cdi-weld/src/main/java/org/apache/aries/cdi/weld/Activator.java
new file mode 100644
index 0000000..3d83511
--- /dev/null
+++ b/cdi-weld/src/main/java/org/apache/aries/cdi/weld/Activator.java
@@ -0,0 +1,55 @@
+/**
+ * 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.apache.aries.cdi.weld;
+
+import static org.osgi.framework.Constants.BUNDLE_ACTIVATOR;
+import static org.osgi.framework.Constants.SERVICE_DESCRIPTION;
+import static org.osgi.framework.Constants.SERVICE_VENDOR;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.enterprise.inject.se.SeContainerInitializer;
+
+import org.osgi.annotation.bundle.Header;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+@Header(
+	name = BUNDLE_ACTIVATOR,
+	value = "${@class}"
+)
+public class Activator implements BundleActivator {
+
+	@Override
+	public void start(BundleContext bundleContext) throws Exception {
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put(SERVICE_DESCRIPTION, "Aries CDI - Weld SeContainerInitializer Factory");
+		properties.put(SERVICE_VENDOR, "Apache Software Foundation");
+		properties.put("aries.cdi.spi", "Weld");
+
+		_seContainerInitializer = bundleContext.registerService(
+			SeContainerInitializer.class, new WeldSeContainerInitializerFactory(bundleContext), properties);
+	}
+
+	@Override
+	public void stop(BundleContext context) throws Exception {
+		_seContainerInitializer.unregister();
+	}
+
+	private ServiceRegistration<SeContainerInitializer> _seContainerInitializer;
+
+}
diff --git a/cdi-weld/src/main/java/org/apache/aries/cdi/weld/BundleResourcesLoader.java b/cdi-weld/src/main/java/org/apache/aries/cdi/weld/BundleResourcesLoader.java
new file mode 100644
index 0000000..4485138
--- /dev/null
+++ b/cdi-weld/src/main/java/org/apache/aries/cdi/weld/BundleResourcesLoader.java
@@ -0,0 +1,115 @@
+/**
+ * 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.apache.aries.cdi.weld;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.aries.cdi.spi.loader.SpiLoader;
+import org.jboss.weld.resources.spi.ResourceLoader;
+import org.jboss.weld.resources.spi.ResourceLoadingException;
+import org.jboss.weld.serialization.spi.ProxyServices;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.namespace.PackageNamespace;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleWire;
+import org.osgi.framework.wiring.BundleWiring;
+
+public class BundleResourcesLoader implements ProxyServices, ResourceLoader {
+
+	BundleResourcesLoader(SpiLoader loader, Bundle spiImplBundle) {
+		BundleWiring spiImplWiring = spiImplBundle.adapt(BundleWiring.class);
+
+		List<Bundle> bundles = new ArrayList<>();
+
+		bundles.add(spiImplBundle);
+
+		List<BundleWire> requiredWires = spiImplWiring.getRequiredWires(PackageNamespace.PACKAGE_NAMESPACE);
+
+		for (BundleWire bundleWire : requiredWires) {
+			BundleCapability capability = bundleWire.getCapability();
+			Map<String, Object> attributes = capability.getAttributes();
+			String packageName = (String)attributes.get(PackageNamespace.PACKAGE_NAMESPACE);
+			if (!packageName.startsWith("org.jboss.weld.")) {
+				continue;
+			}
+
+			Bundle wireBundle = bundleWire.getProvider().getBundle();
+			if (!bundles.contains(wireBundle)) {
+				bundles.add(wireBundle);
+			}
+		}
+
+		loader.getBundles().addAll(bundles);
+
+		_classLoader = loader;
+	}
+
+
+	@Override
+	public void cleanup() {
+	}
+
+	@Override
+	public Class<?> classForName(String className) {
+		try {
+			return _classLoader.loadClass(className);
+		}
+		catch (ClassNotFoundException e) {
+			throw new ResourceLoadingException(ERROR_LOADING_CLASS + className, e);
+		}
+		catch (LinkageError e) {
+			throw new ResourceLoadingException(ERROR_LOADING_CLASS + className, e);
+		}
+		catch (TypeNotPresentException e) {
+			throw new ResourceLoadingException(ERROR_LOADING_CLASS + className, e);
+		}
+	}
+
+	@Override
+	public ClassLoader getClassLoader(Class<?> proxiedBeanType) {
+		return _classLoader;
+	}
+
+	@Override
+	public Class<?> loadBeanClass(String className) {
+		return classForName(className);
+	}
+
+	@Override
+	public URL getResource(String name) {
+		return _classLoader.getResource(name);
+	}
+
+	@Override
+	public Collection<URL> getResources(String name) {
+		try {
+			return Collections.list(_classLoader.getResources(name));
+		}
+		catch (IOException e) {
+			return Collections.emptyList();
+		}
+	}
+
+	private static final String ERROR_LOADING_CLASS = "Error loading class ";
+
+	private final ClassLoader _classLoader;
+
+}
\ No newline at end of file
diff --git a/cdi-weld/src/main/java/org/apache/aries/cdi/weld/ContainerDeployment.java b/cdi-weld/src/main/java/org/apache/aries/cdi/weld/ContainerDeployment.java
new file mode 100644
index 0000000..188229b
--- /dev/null
+++ b/cdi-weld/src/main/java/org/apache/aries/cdi/weld/ContainerDeployment.java
@@ -0,0 +1,66 @@
+/**
+ * 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.apache.aries.cdi.weld;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.enterprise.inject.spi.Extension;
+
+import org.jboss.weld.bootstrap.api.ServiceRegistry;
+import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.weld.bootstrap.spi.CDI11Deployment;
+import org.jboss.weld.bootstrap.spi.Metadata;
+
+public class ContainerDeployment implements CDI11Deployment {
+
+	public ContainerDeployment(Iterable<Metadata<Extension>> extensions, BeanDeploymentArchive beanDeploymentArchive) {
+		_extensions = extensions;
+		_beanDeploymentArchive = beanDeploymentArchive;
+
+		_beanDeploymentArchives = new ArrayList<BeanDeploymentArchive>();
+		_beanDeploymentArchives.add(beanDeploymentArchive);
+	}
+
+	@Override
+	public BeanDeploymentArchive getBeanDeploymentArchive(Class<?> beanClass) {
+		return _beanDeploymentArchive;
+	}
+
+	@Override
+	public Collection<BeanDeploymentArchive> getBeanDeploymentArchives() {
+		return _beanDeploymentArchives;
+	}
+
+	@Override
+	public Iterable<Metadata<Extension>> getExtensions() {
+		return _extensions;
+	}
+
+	@Override
+	public ServiceRegistry getServices() {
+		return _beanDeploymentArchive.getServices();
+	}
+
+	@Override
+	public BeanDeploymentArchive loadBeanDeploymentArchive(Class<?> aClass) {
+		return _beanDeploymentArchive;
+	}
+
+	private final BeanDeploymentArchive _beanDeploymentArchive;
+	private final Collection<BeanDeploymentArchive> _beanDeploymentArchives;
+	private final Iterable<Metadata<Extension>> _extensions;
+
+}
\ No newline at end of file
diff --git a/cdi-weld/src/main/java/org/apache/aries/cdi/weld/ContainerDeploymentArchive.java b/cdi-weld/src/main/java/org/apache/aries/cdi/weld/ContainerDeploymentArchive.java
new file mode 100644
index 0000000..bf5680a
--- /dev/null
+++ b/cdi-weld/src/main/java/org/apache/aries/cdi/weld/ContainerDeploymentArchive.java
@@ -0,0 +1,84 @@
+/**
+ * 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.apache.aries.cdi.weld;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.jboss.weld.bootstrap.api.ServiceRegistry;
+import org.jboss.weld.bootstrap.api.helpers.SimpleServiceRegistry;
+import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.weld.bootstrap.spi.BeansXml;
+import org.jboss.weld.bootstrap.spi.EEModuleDescriptor;
+import org.jboss.weld.bootstrap.spi.EEModuleDescriptor.ModuleType;
+import org.jboss.weld.bootstrap.spi.helpers.EEModuleDescriptorImpl;
+import org.jboss.weld.ejb.spi.EjbDescriptor;
+import org.jboss.weld.resources.spi.ResourceLoader;
+import org.jboss.weld.serialization.spi.ProxyServices;
+
+public class ContainerDeploymentArchive
+	implements BeanDeploymentArchive {
+
+	public <T extends ResourceLoader & ProxyServices> ContainerDeploymentArchive(
+		T loader, String id, Collection<String> beanClassNames, BeansXml beansXml) {
+
+		_id = id;
+		_beanClassNames = beanClassNames;
+		_beansXml = beansXml;
+		_services = new SimpleServiceRegistry();
+
+		if (loader != null) {
+			_services.add(ResourceLoader.class, loader);
+			_services.add(ProxyServices.class, loader);
+			_services.add(EEModuleDescriptor.class, new EEModuleDescriptorImpl(id, ModuleType.APPLICATION_CLIENT));
+		}
+	}
+
+	@Override
+	public Collection<String> getBeanClasses() {
+		return _beanClassNames;
+	}
+
+	@Override
+	public Collection<BeanDeploymentArchive> getBeanDeploymentArchives() {
+		return Collections.emptyList();
+	}
+
+	@Override
+	public BeansXml getBeansXml() {
+		return _beansXml;
+	}
+
+	@Override
+	public Collection<EjbDescriptor<?>> getEjbs() {
+		return Collections.emptyList();
+	}
+
+	@Override
+	public String getId() {
+		return _id;
+	}
+
+	@Override
+	public ServiceRegistry getServices() {
+		return _services;
+	}
+
+	private final Collection<String> _beanClassNames;
+	private final BeansXml _beansXml;
+	private final String _id;
+	private final ServiceRegistry _services;
+
+}
\ No newline at end of file
diff --git a/cdi-weld/src/main/java/org/apache/aries/cdi/weld/ContainerEnvironment.java b/cdi-weld/src/main/java/org/apache/aries/cdi/weld/ContainerEnvironment.java
new file mode 100644
index 0000000..458a625
--- /dev/null
+++ b/cdi-weld/src/main/java/org/apache/aries/cdi/weld/ContainerEnvironment.java
@@ -0,0 +1,43 @@
+/**
+ * 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.apache.aries.cdi.weld;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.weld.bootstrap.api.Environment;
+import org.jboss.weld.bootstrap.api.Service;
+
+public class ContainerEnvironment implements Environment {
+
+	public ContainerEnvironment() {
+		_requiredBeanDeploymentArchiveServices = new HashSet<Class<? extends Service>>();
+		_requiredDeploymentServices = new HashSet<Class<? extends Service>>();
+	}
+
+	@Override
+	public Set<Class<? extends Service>> getRequiredBeanDeploymentArchiveServices() {
+		return _requiredBeanDeploymentArchiveServices;
+	}
+
+	@Override
+	public Set<Class<? extends Service>> getRequiredDeploymentServices() {
+		return _requiredDeploymentServices;
+	}
+
+	private final Set<Class<? extends Service>> _requiredBeanDeploymentArchiveServices;
+	private final Set<Class<? extends Service>> _requiredDeploymentServices;
+
+}
\ No newline at end of file
diff --git a/cdi-weld/src/main/java/org/apache/aries/cdi/weld/ExtensionMetadata.java b/cdi-weld/src/main/java/org/apache/aries/cdi/weld/ExtensionMetadata.java
new file mode 100644
index 0000000..0d99465
--- /dev/null
+++ b/cdi-weld/src/main/java/org/apache/aries/cdi/weld/ExtensionMetadata.java
@@ -0,0 +1,41 @@
+/**
+ * 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.apache.aries.cdi.weld;
+
+import javax.enterprise.inject.spi.Extension;
+
+import org.jboss.weld.bootstrap.spi.Metadata;
+
+public class ExtensionMetadata implements Metadata<Extension> {
+
+	public ExtensionMetadata(Extension extension, String location) {
+		_extension = extension;
+		_location = location;
+	}
+
+	@Override
+	public Extension getValue() {
+		return _extension;
+	}
+
+	@Override
+	public String getLocation() {
+		return _location;
+	}
+
+	private final Extension _extension;
+	private final String _location;
+
+}
\ No newline at end of file
diff --git a/cdi-weld/src/main/java/org/apache/aries/cdi/weld/WeldSeContainerInitializer.java b/cdi-weld/src/main/java/org/apache/aries/cdi/weld/WeldSeContainerInitializer.java
new file mode 100644
index 0000000..1de5bff
--- /dev/null
+++ b/cdi-weld/src/main/java/org/apache/aries/cdi/weld/WeldSeContainerInitializer.java
@@ -0,0 +1,280 @@
+package org.apache.aries.cdi.weld;
+
+import static java.util.Collections.list;
+import static java.util.Objects.requireNonNull;
+import static org.apache.aries.cdi.spi.Keys.BEANS_XML_PROPERTY;
+import static org.apache.aries.cdi.spi.Keys.BUNDLECONTEXT_PROPERTY;
+
+import java.lang.annotation.Annotation;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Properties;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.se.SeContainer;
+import javax.enterprise.inject.se.SeContainerInitializer;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.util.TypeLiteral;
+
+import org.apache.aries.cdi.spi.loader.SpiLoader;
+import org.jboss.weld.bootstrap.WeldBootstrap;
+import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.weld.bootstrap.spi.BeansXml;
+import org.jboss.weld.bootstrap.spi.Deployment;
+import org.jboss.weld.bootstrap.spi.Metadata;
+import org.jboss.weld.xml.BeansXmlParser;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleReference;
+
+public class WeldSeContainerInitializer extends SeContainerInitializer {
+
+	public WeldSeContainerInitializer(BundleContext bundleContext) {
+		weldBundleContext = bundleContext;
+	}
+
+	@Override
+	public SeContainerInitializer addBeanClasses(Class<?>... classes) {
+		beanClasses.addAll(Arrays.asList(classes));
+		return this;
+	}
+
+	@Override
+	public SeContainerInitializer addPackages(Class<?>... packageClasses) {
+		// TODO Auto-generated method stub
+		return this;
+	}
+
+	@Override
+	public SeContainerInitializer addPackages(boolean scanRecursively, Class<?>... packageClasses) {
+		// TODO Auto-generated method stub
+		return this;
+	}
+
+	@Override
+	public SeContainerInitializer addPackages(Package... packages) {
+		// TODO Auto-generated method stub
+		return this;
+	}
+
+	@Override
+	public SeContainerInitializer addPackages(boolean scanRecursively, Package... packages) {
+		// TODO Auto-generated method stub
+		return this;
+	}
+
+	@Override
+	public SeContainerInitializer addExtensions(Extension... extensions) {
+		this.extensions.addAll(Arrays.asList(extensions));
+		return this;
+	}
+
+	@Override
+	public SeContainerInitializer addExtensions(Class<? extends Extension>... extensions) {
+		this.extensionClasses.addAll(Arrays.asList(extensions));
+		return this;
+	}
+
+	@Override
+	public SeContainerInitializer enableInterceptors(Class<?>... interceptorClasses) {
+		// TODO Auto-generated method stub
+		return this;
+	}
+
+	@Override
+	public SeContainerInitializer enableDecorators(Class<?>... decoratorClasses) {
+		// TODO Auto-generated method stub
+		return this;
+	}
+
+	@Override
+	public SeContainerInitializer selectAlternatives(Class<?>... alternativeClasses) {
+		// TODO Auto-generated method stub
+		return this;
+	}
+
+	@Override
+	public SeContainerInitializer selectAlternativeStereotypes(
+		Class<? extends Annotation>... alternativeStereotypeClasses) {
+
+		// TODO Auto-generated method stub
+		return this;
+	}
+
+	@Override
+	public SeContainerInitializer addProperty(String key, Object value) {
+		properties.putIfAbsent(key, value);
+		return this;
+	}
+
+	@Override
+	public SeContainerInitializer setProperties(Map<String, Object> properties) {
+		properties.putAll(properties);
+		return this;
+	}
+
+	@Override
+	public SeContainerInitializer disableDiscovery() {
+		// TODO Auto-generated method stub
+		return this;
+	}
+
+	@Override
+	public SeContainerInitializer setClassLoader(ClassLoader classLoader) {
+		this.classLoader = (SpiLoader)classLoader;
+		return this;
+	}
+
+	@Override
+	@SuppressWarnings("unchecked")
+	public SeContainer initialize() {
+		Thread currentThread = Thread.currentThread();
+		ClassLoader current = currentThread.getContextClassLoader();
+		BundleResourcesLoader resourceLoader = new BundleResourcesLoader(requireNonNull(classLoader), weldBundleContext.getBundle());
+
+		try {
+			currentThread.setContextClassLoader(classLoader);
+			clientBundleContext = requireNonNull(BundleContext.class.cast(properties.get(BUNDLECONTEXT_PROPERTY)));
+
+			Optional.ofNullable(clientBundleContext.getBundle().getHeaders()).ifPresent(
+				headers -> list(headers.elements()).stream()
+					.filter(it -> it.startsWith("org.jboss.weld."))
+					.forEach(key -> properties.setProperty(key, headers.get(key))
+				)
+			);
+
+			// Add external extensions
+			List<Metadata<Extension>> metaExtensions = extensions.stream().map(
+				extension -> {
+					Bundle extensionBundle = BundleReference.class.cast(extension.getClass().getClassLoader()).getBundle();
+					classLoader.getBundles().add(extensionBundle);
+					return new ExtensionMetadata(extension, extensionBundle.toString());
+				}
+			).collect(Collectors.toList());
+
+			BeansXml beansXml = BeansXml.EMPTY_BEANS_XML;
+
+			Collection<URL> beanDescriptorURLs = Collection.class.cast(properties.get(BEANS_XML_PROPERTY));
+
+			if (!beanDescriptorURLs.isEmpty()) {
+				BeansXmlParser beansXmlParser = new BeansXmlParser();
+				beansXml = beansXmlParser.parse(beanDescriptorURLs);
+			}
+
+			String id = clientBundleContext.getBundle().toString();
+
+			bootstrap = new WeldBootstrap();
+
+			beanDeploymentArchive = new ContainerDeploymentArchive(
+				resourceLoader,
+				id,
+				beanClasses.stream().map(Class::getName).collect(Collectors.toList()),
+				beansXml);
+
+			Deployment deployment = new ContainerDeployment(metaExtensions, beanDeploymentArchive);
+
+			bootstrap.startExtensions(metaExtensions);
+			bootstrap.startContainer(id, new ContainerEnvironment(), deployment);
+			bootstrap.startInitialization();
+			bootstrap.deployBeans();
+			bootstrap.validateBeans();
+			bootstrap.endInitialization();
+
+			return new WeldSeContainer();
+		}
+		finally {
+			currentThread.setContextClassLoader(current);
+		}
+	}
+
+	private volatile BeanDeploymentArchive beanDeploymentArchive;
+	private volatile WeldBootstrap bootstrap;
+	private volatile BundleContext clientBundleContext;
+	private volatile SpiLoader classLoader;
+	private final Set<Class<?>> beanClasses = new HashSet<>();
+	private final List<Extension> extensions = new ArrayList<>();
+	private final List<Class<? extends Extension>> extensionClasses = new ArrayList<>();
+	private final BundleContext weldBundleContext;
+	private final Properties properties = new Properties();
+
+	private class WeldSeContainer implements SeContainer {
+
+		private volatile boolean running = true;
+
+		@Override
+		public void close() {
+			running = false;
+			Thread currentThread = Thread.currentThread();
+			ClassLoader current = currentThread.getContextClassLoader();
+			try {
+				currentThread.setContextClassLoader(requireNonNull(classLoader));
+				bootstrap.shutdown();
+			}
+			finally {
+				currentThread.setContextClassLoader(current);
+			}
+		}
+
+		@Override
+		public Instance<Object> select(Annotation... qualifiers) {
+			return bootstrap.getManager(beanDeploymentArchive).createInstance().select(qualifiers);
+		}
+
+		@Override
+		public <U> Instance<U> select(Class<U> subtype, Annotation... qualifiers) {
+			return bootstrap.getManager(beanDeploymentArchive).createInstance().select(subtype, qualifiers);
+		}
+
+		@Override
+		public <U> Instance<U> select(TypeLiteral<U> subtype, Annotation... qualifiers) {
+			return bootstrap.getManager(beanDeploymentArchive).createInstance().select(subtype, qualifiers);
+		}
+
+		@Override
+		public boolean isUnsatisfied() {
+			return bootstrap.getManager(beanDeploymentArchive).createInstance().isUnsatisfied();
+		}
+
+		@Override
+		public boolean isAmbiguous() {
+			return bootstrap.getManager(beanDeploymentArchive).createInstance().isAmbiguous();
+		}
+
+		@Override
+		public void destroy(Object instance) {
+			bootstrap.getManager(beanDeploymentArchive).createInstance().destroy(instance);
+		}
+
+		@Override
+		public Iterator<Object> iterator() {
+			return bootstrap.getManager(beanDeploymentArchive).createInstance().iterator();
+		}
+
+		@Override
+		public boolean isRunning() {
+			return running;
+		}
+
+		@Override
+		public BeanManager getBeanManager() {
+			return bootstrap.getManager(beanDeploymentArchive);
+		}
+
+		@Override
+		public Object get() {
+			return bootstrap.getManager(beanDeploymentArchive).createInstance().get();
+		}
+
+	}
+
+}
diff --git a/cdi-weld/src/main/java/org/apache/aries/cdi/weld/WeldSeContainerInitializerFactory.java b/cdi-weld/src/main/java/org/apache/aries/cdi/weld/WeldSeContainerInitializerFactory.java
new file mode 100644
index 0000000..3ec972f
--- /dev/null
+++ b/cdi-weld/src/main/java/org/apache/aries/cdi/weld/WeldSeContainerInitializerFactory.java
@@ -0,0 +1,44 @@
+/**
+ * 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.apache.aries.cdi.weld;
+
+import javax.enterprise.inject.se.SeContainerInitializer;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.PrototypeServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+
+public class WeldSeContainerInitializerFactory implements PrototypeServiceFactory<SeContainerInitializer> {
+
+	public WeldSeContainerInitializerFactory(BundleContext bundleContext) {
+		this.bundleContext = bundleContext;
+	}
+
+	@Override
+	public SeContainerInitializer getService(
+		Bundle bundle, ServiceRegistration<SeContainerInitializer> registration) {
+
+		return new WeldSeContainerInitializer(bundleContext);
+	}
+
+	@Override
+	public void ungetService(
+		Bundle bundle, ServiceRegistration<SeContainerInitializer> registration, SeContainerInitializer service) {
+	}
+
+	private final BundleContext bundleContext;
+
+}
diff --git a/cdi-weld/src/main/java/org/apache/aries/cdi/weld/package-info.java b/cdi-weld/src/main/java/org/apache/aries/cdi/weld/package-info.java
new file mode 100644
index 0000000..0e4cdfe
--- /dev/null
+++ b/cdi-weld/src/main/java/org/apache/aries/cdi/weld/package-info.java
@@ -0,0 +1,23 @@
+/**
+ * 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.
+ */
+
+@org.osgi.annotation.bundle.Capability(
+	attribute = {
+		"objectClass:List<String>=javax.enterprise.inject.se.SeContainerInitializer",
+		"aries.cdi.spi=Weld"
+	},
+	namespace = org.osgi.namespace.service.ServiceNamespace.SERVICE_NAMESPACE
+)
+@org.osgi.service.cdi.annotations.RequireCDIImplementation
+package org.apache.aries.cdi.weld;
diff --git a/pom.xml b/pom.xml
index a5958da..61b5854 100644
--- a/pom.xml
+++ b/pom.xml
@@ -64,6 +64,7 @@
 		<module>cdi-extension-http</module>
 		<module>cdi-extension-jndi</module>
 		<module>cdi-owb</module>
+		<module>cdi-weld</module>
 		<module>cdi-bom</module>
 		<module>cdi-itests</module>
 		<module>cdi-executable</module>
@@ -114,45 +115,6 @@
 				<version>1.1</version>
 			</dependency>
 			<dependency>
-				<groupId>org.jboss.weld</groupId>
-				<artifactId>weld-osgi-bundle</artifactId>
-				<version>${weld.version}</version>
-				<exclusions>
-					<exclusion>
-						<groupId>javax.annotation</groupId>
-						<artifactId>javax.annotation-api</artifactId>
-					</exclusion>
-					<exclusion>
-						<groupId>javax.enterprise</groupId>
-						<artifactId>cdi-api</artifactId>
-					</exclusion>
-					<exclusion>
-						<groupId>javax.inject</groupId>
-						<artifactId>javax.inject</artifactId>
-					</exclusion>
-					<exclusion>
-						<groupId>org.jboss.spec.javax.annotation</groupId>
-						<artifactId>jboss-annotations-api_1.3_spec</artifactId>
-					</exclusion>
-					<exclusion>
-						<groupId>org.jboss.spec.javax.ejb</groupId>
-						<artifactId>jboss-ejb-api_3.2_spec</artifactId>
-					</exclusion>
-					<exclusion>
-						<groupId>org.jboss.spec.javax.el</groupId>
-						<artifactId>jboss-el-api_3.0_spec</artifactId>
-					</exclusion>
-					<exclusion>
-						<groupId>org.jboss.spec.javax.interceptor</groupId>
-						<artifactId>jboss-interceptors-api_1.2_spec</artifactId>
-					</exclusion>
-					<exclusion>
-						<groupId>org.jboss.spec.javax.transaction</groupId>
-						<artifactId>jboss-transaction-api_1.2_spec</artifactId>
-					</exclusion>
-				</exclusions>
-			</dependency>
-			<dependency>
 				<groupId>org.osgi</groupId>
 				<artifactId>org.osgi.namespace.extender</artifactId>
 				<version>1.0.1</version>