You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by st...@apache.org on 2012/02/19 13:38:48 UTC
[2/2] git commit: DELTASPIKE-92 introduce ContainerCtrl API
DELTASPIKE-92 introduce ContainerCtrl API
Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/135a8aca
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/135a8aca
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/135a8aca
Branch: refs/heads/master
Commit: 135a8aca15be4f69cf40cb008f00b4ad742caf86
Parents: b343901
Author: Mark Struberg <st...@apache.org>
Authored: Fri Feb 17 09:00:18 2012 +0100
Committer: Mark Struberg <st...@apache.org>
Committed: Sat Feb 18 10:08:45 2012 +0100
----------------------------------------------------------------------
deltaspike/containerctrl/api/pom.xml | 59 ++++++++++
.../containerctrl/api/ContainerControl.java | 84 +++++++++++++++
.../containerctrl/api/ContainerControlLoader.java | 60 ++++++++++
deltaspike/containerctrl/pom.xml | 43 ++++++++
deltaspike/parent/pom.xml | 2 +-
deltaspike/pom.xml | 1 +
6 files changed, 248 insertions(+), 1 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/135a8aca/deltaspike/containerctrl/api/pom.xml
----------------------------------------------------------------------
diff --git a/deltaspike/containerctrl/api/pom.xml b/deltaspike/containerctrl/api/pom.xml
new file mode 100644
index 0000000..12b06eb
--- /dev/null
+++ b/deltaspike/containerctrl/api/pom.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.deltaspike.containerctrl</groupId>
+ <artifactId>containerctrl-project</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>containerctrl-api</artifactId>
+ <packaging>jar</packaging>
+
+ <name>CDI ContainerControl API</name>
+ <description>
+ This project provides a way to genericly run CDI containers
+ from inside of unit tests or Java SE applications.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jcdi_1.0_spec</artifactId>
+ <optional>true</optional>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-atinject_1.0_spec</artifactId>
+ <optional>true</optional>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-interceptor_1.1_spec</artifactId>
+ <optional>true</optional>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/135a8aca/deltaspike/containerctrl/api/src/main/java/org/apache/deltaspike/containerctrl/api/ContainerControl.java
----------------------------------------------------------------------
diff --git a/deltaspike/containerctrl/api/src/main/java/org/apache/deltaspike/containerctrl/api/ContainerControl.java b/deltaspike/containerctrl/api/src/main/java/org/apache/deltaspike/containerctrl/api/ContainerControl.java
new file mode 100644
index 0000000..e9566a6
--- /dev/null
+++ b/deltaspike/containerctrl/api/src/main/java/org/apache/deltaspike/containerctrl/api/ContainerControl.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.deltaspike.containerctrl.api;
+
+
+import java.lang.annotation.Annotation;
+import javax.enterprise.inject.spi.BeanManager;
+
+
+/**
+ * <p>A CdiTestContainer provides access to an underlying JSR-299 (CDI)
+ * Container. It allows starting and stopping the container and to start
+ * and stop the built-in contexts of that container.</p>
+ *
+ * <p>The intention is to provide a portable control for CDI containers in
+ * Java SE environments. It is <b>not</b> intended for environments in which the
+ * CDI container is under full control of the server already, e.g. in
+ * EE-containers.</p>
+ */
+public interface ContainerControl
+{
+ /**
+ * Booting the CdiTestContainer will scan the whole classpath
+ * for Beans and extensions available.
+ * @throws Exception the container might throw a DeploymentException or similar
+ * on startup.
+ */
+ void bootContainer() throws Exception;
+
+ /**
+ * This will shutdown the underlying CDI container.
+ */
+ void shutdownContainer() throws Exception;
+
+ /**
+ * This will start all container built-in Contexts
+ */
+ void startContexts();
+
+ /**
+ * Stop all container built-in Contexts and destroy all beans properly
+ */
+ void stopContexts();
+
+ /**
+ * Start the specified scope. This only works for scopes which are handled
+ * by the CDI container itself. Custom scoped of 3rd party
+ * Context implementations shall be started directly (they are portable anyway).
+ *
+ * @param scopeClass e.g. RequestScoped.class
+ */
+ void startContext(Class<? extends Annotation> scopeClass);
+
+ /**
+ * Stop the specified scope. This only works for scopes which are handled
+ * by the CDI container itself. Custom scoped of 3rd party
+ * Context implementations shall be stopped directly (they are portable anyway).
+ *
+ * @param scopeClass e.g. RequestScoped.class
+ */
+ void stopContext(Class<? extends Annotation> scopeClass);
+
+ /**
+ * @return the {@link BeanManager} or <code>null</code> it not available
+ */
+ BeanManager getBeanManager();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/135a8aca/deltaspike/containerctrl/api/src/main/java/org/apache/deltaspike/containerctrl/api/ContainerControlLoader.java
----------------------------------------------------------------------
diff --git a/deltaspike/containerctrl/api/src/main/java/org/apache/deltaspike/containerctrl/api/ContainerControlLoader.java b/deltaspike/containerctrl/api/src/main/java/org/apache/deltaspike/containerctrl/api/ContainerControlLoader.java
new file mode 100644
index 0000000..fb9de13
--- /dev/null
+++ b/deltaspike/containerctrl/api/src/main/java/org/apache/deltaspike/containerctrl/api/ContainerControlLoader.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.deltaspike.containerctrl.api;
+
+import java.util.Iterator;
+import java.util.ServiceLoader;
+
+/**
+ * <p>This class provides access to the ContainerControl.</p>
+ * <p>It uses the {@code java.util.ServiceLoader} mechanism to
+ * automatically pickup the container providers from the classpath.</p>
+ */
+public final class ContainerControlLoader
+{
+ private ContainerControlLoader()
+ {
+ // private ct to prevent instantiation
+ }
+
+
+ public static ContainerControl getCdiContainer()
+ {
+ ContainerControl testContainer = null;
+
+ //doesn't support the implementation loader (there is no dependency to owb-impl
+ ServiceLoader<ContainerControl> cdiContainerLoader = ServiceLoader.load(ContainerControl.class);
+ Iterator<ContainerControl> cdiIt = cdiContainerLoader.iterator();
+ if (cdiIt.hasNext())
+ {
+ testContainer = cdiIt.next();
+ }
+ else
+ {
+ throw new RuntimeException("Could not find a ContainerControl available in the classpath!");
+ }
+
+ if (cdiIt.hasNext())
+ {
+ throw new RuntimeException("Too many ContainerControl found in the classpath!");
+ }
+
+ return testContainer;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/135a8aca/deltaspike/containerctrl/pom.xml
----------------------------------------------------------------------
diff --git a/deltaspike/containerctrl/pom.xml b/deltaspike/containerctrl/pom.xml
new file mode 100644
index 0000000..eee673e
--- /dev/null
+++ b/deltaspike/containerctrl/pom.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.deltaspike</groupId>
+ <artifactId>parent-code</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ <relativePath>../parent/code/pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.apache.deltaspike.containerctrl</groupId>
+ <artifactId>containerctrl-project</artifactId>
+ <packaging>pom</packaging>
+
+ <name>Apache DeltaSpike ContainerControl parent</name>
+
+ <modules>
+ <module>api</module>
+<!--
+ <module>impl-owb</module>
+ <module>impl-weld</modul>
+-->
+ </modules>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/135a8aca/deltaspike/parent/pom.xml
----------------------------------------------------------------------
diff --git a/deltaspike/parent/pom.xml b/deltaspike/parent/pom.xml
index b267086..9c6b433 100644
--- a/deltaspike/parent/pom.xml
+++ b/deltaspike/parent/pom.xml
@@ -155,7 +155,7 @@
<id>rdebusscher</id>
<name>Rudy De Busscher</name>
<email>rdebusscher@apache.org</email>
- <organization>C4J, Belgium</organization>
+ <organization>C4J, Belgium</organization>
<roles>
<role>Committer</role>
</roles>
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/135a8aca/deltaspike/pom.xml
----------------------------------------------------------------------
diff --git a/deltaspike/pom.xml b/deltaspike/pom.xml
index caa2ebc..2240071 100644
--- a/deltaspike/pom.xml
+++ b/deltaspike/pom.xml
@@ -56,6 +56,7 @@
<module>parent</module>
<module>test-utils</module>
<module>core</module>
+ <module>containerctrl</module>
<module>modules</module>
</modules>