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/04/08 17:11:36 UTC

[aries-cdi] branch master updated: information about bnd 4.3.0 discover mode from beans.xml

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 8632652  information about bnd 4.3.0 discover mode from beans.xml
8632652 is described below

commit 863265251457ee474bcdb14bcaf85b6087071327
Author: Raymond Auge <ro...@apache.org>
AuthorDate: Mon Apr 8 13:10:56 2019 -0400

    information about bnd 4.3.0 discover mode from beans.xml
    
    add test case in preperation
    
    Signed-off-by: Raymond Auge <ro...@apache.org>
---
 README.md                                          | 34 +++++++++++++-
 cdi-executable/executable.bndrun                   |  8 ++--
 cdi-itests/bnd.bnd                                 |  3 +-
 cdi-itests/bnd/tb14.bnd                            | 14 ++++++
 cdi-itests/bnd/tb14.xml                            | 26 +++++++++++
 cdi-itests/itest.bndrun                            | 12 ++---
 .../apache/aries/cdi/test/cases/SlimTestCase.java  | 26 +++++++++++
 .../org/apache/aries/cdi/test/cases/Test152_3.java | 22 +--------
 .../apache/aries/cdi/test/cases/Test152_3_1.java   | 12 +----
 .../apache/aries/cdi/test/cases/Test152_3_1_1.java | 12 +----
 .../cdi/test/cases/Test_discoverByBeansXml.java    | 54 ++++++++++++++++++++++
 .../java/org/apache/aries/cdi/test/tb14/ABean.java | 18 ++++++++
 12 files changed, 186 insertions(+), 55 deletions(-)

diff --git a/README.md b/README.md
index d411d32..460a18f 100644
--- a/README.md
+++ b/README.md
@@ -39,7 +39,39 @@ However all the required dependencies are available using the __Aries CDI BOM__:
 
 ## Tooling
 
-TODO
+In order to make the best use of OSGi CDI you should use tooling that supports it. [Bnd](https://bnd.bndtools.org) provides OOTB support for OSGi CDI annotations and enables a painless configuration model.
+
+OSGi CDI support in bnd comes with any tool that uses bnd versions `4.1.0+`:
+
+* [maven-bundle-plugin 4.1.0+](http://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html)
+* [bnd gradle plugin (for non-workspace) 4.1.0+](https://github.com/bndtools/bnd/tree/master/biz.aQute.bnd.gradle#gradle-plugin-for-non-bnd-workspace-builds)
+* [bndtools workspace 4.1.0+](https://bndtools.org/)
+* [bnd-maven-plugin 4.1.0+](https://github.com/bndtools/bnd/tree/master/maven/bnd-maven-plugin)
+
+### Setting up
+
+Bean discovery in bnd is handled by the __`-cdiannotations`__ instruction. The default value for this is __`*`__ (which is functionally equivalent to `*;discover=annotated_by_bean` described below.)
+
+Discovery is controlled by applying the attribute `discover` to glob pattern used for matching classes in the bundle by their fully qualified names (_the default glob `*` matches all classes._)
+
+Available `discover` options are:
+
+* __`none`__ - disable bean discovery
+* __`annotated`__ - uses the CDI definition of [annotated discovery mode](http://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#default_bean_discovery)
+* __`all`__ - discover all classes which could be beans
+* __`annotated_by_bean`__ - defined by bnd, this is __the effective default__ which means to look for classes annotated with `org.osgi.service.cdi.annotations.Bean` or packages annotated with `org.osgi.service.cdi.annotations.Beans`)
+
+In combination the glob and modes give the developer very concise control over discovery.
+
+If you want to emulate the CDI default use:
+
+```properties
+-cdiannotations: *;discover=annotated
+```
+
+#### beans.xml
+
+In bnd `4.3.0+` you can rely purely on the discovery mode calculated from existing `beans.xml` files in your project. This grants even less configuration friction for existing projects migrating to OSGi CDI.
 
 ## Pre-built runtime
 
diff --git a/cdi-executable/executable.bndrun b/cdi-executable/executable.bndrun
index b9639da..02b26d4 100644
--- a/cdi-executable/executable.bndrun
+++ b/cdi-executable/executable.bndrun
@@ -47,9 +47,9 @@
 	javax.ejb-api;version='[3.2.0,3.2.1)',\
 	javax.transaction-api;version='[1.2.0,1.2.1)',\
 	jboss-classfilewriter;version='[1.2.3,1.2.4)',\
-	org.apache.aries.cdi.extender;version='[1.0.2,1.0.3)',\
-	org.apache.aries.cdi.extension.http;version='[1.0.2,1.0.3)',\
-	org.apache.aries.cdi.extra;version='[1.0.2,1.0.3)',\
+	org.apache.aries.cdi.extender;version='[1.0.3,1.0.4)',\
+	org.apache.aries.cdi.extension.http;version='[1.0.3,1.0.4)',\
+	org.apache.aries.cdi.extra;version='[1.0.3,1.0.4)',\
 	org.apache.aries.spifly.dynamic.framework.extension;version='[1.2.0,1.2.1)',\
 	org.apache.felix.configadmin;version='[1.9.10,1.9.11)',\
 	org.apache.felix.gogo.command;version='[1.1.0,1.1.1)',\
@@ -66,4 +66,4 @@
 	org.jboss.weld.osgi-bundle;version='[3.0.5,3.0.6)',\
 	org.osgi.service.cdi;version='[1.0.0,1.0.1)',\
 	org.osgi.util.function;version='[1.1.0,1.1.1)',\
-	org.osgi.util.promise;version='[1.1.0,1.1.1)'
+	org.osgi.util.promise;version='[1.1.0,1.1.1)',\
diff --git a/cdi-itests/bnd.bnd b/cdi-itests/bnd.bnd
index 53e4dde..1fd7594 100644
--- a/cdi-itests/bnd.bnd
+++ b/cdi-itests/bnd.bnd
@@ -56,7 +56,8 @@ p = org.apache.aries.cdi.test
 	tb152_3_1_1k.jar,\
 	tb152_3_1_1l.jar,\
 	tb12.jar,\
-	tb13.jar
+	tb13.jar,\
+	tb14.jar
 
 # Don't forget that we had to coax the `maven-jar-plugin` NOT to include the `sub-bundle` packages in
 # the root bundle:
diff --git a/cdi-itests/bnd/tb14.bnd b/cdi-itests/bnd/tb14.bnd
new file mode 100644
index 0000000..1b8815b
--- /dev/null
+++ b/cdi-itests/bnd/tb14.bnd
@@ -0,0 +1,14 @@
+#    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.
+
+Export-Package: ${p}.tb14.*;-split-package:=first
+-includeresource: META-INF/beans.xml=bnd/tb14.xml
\ No newline at end of file
diff --git a/cdi-itests/bnd/tb14.xml b/cdi-itests/bnd/tb14.xml
new file mode 100644
index 0000000..f7f90ad
--- /dev/null
+++ b/cdi-itests/bnd/tb14.xml
@@ -0,0 +1,26 @@
+<?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.
+ */
+-->
+
+<beans
+	xmlns="http://xmlns.jcp.org/xml/ns/javaee"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="
+		http://xmlns.jcp.org/xml/ns/javaee
+		http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
+	bean-discovery-mode="all">
+</beans>
\ No newline at end of file
diff --git a/cdi-itests/itest.bndrun b/cdi-itests/itest.bndrun
index 3c0740a..2604522 100644
--- a/cdi-itests/itest.bndrun
+++ b/cdi-itests/itest.bndrun
@@ -48,11 +48,11 @@
 	javax.ejb-api;version='[3.2.0,3.2.1)',\
 	javax.transaction-api;version='[1.2.0,1.2.1)',\
 	jboss-classfilewriter;version='[1.2.3,1.2.4)',\
-	org.apache.aries.cdi.extender;version='[1.0.2,1.0.3)',\
-	org.apache.aries.cdi.extension.http;version='[1.0.2,1.0.3)',\
-	org.apache.aries.cdi.extension.jndi;version='[1.0.2,1.0.3)',\
-	org.apache.aries.cdi.extra;version='[1.0.2,1.0.3)',\
-	org.apache.aries.cdi.itests;version='[1.0.2,1.0.3)',\
+	org.apache.aries.cdi.extender;version='[1.0.3,1.0.4)',\
+	org.apache.aries.cdi.extension.http;version='[1.0.3,1.0.4)',\
+	org.apache.aries.cdi.extension.jndi;version='[1.0.3,1.0.4)',\
+	org.apache.aries.cdi.extra;version='[1.0.3,1.0.4)',\
+	org.apache.aries.cdi.itests;version='[1.0.3,1.0.4)',\
 	org.apache.aries.jndi.api;version='[1.1.0,1.1.1)',\
 	org.apache.aries.jndi.core;version='[1.0.2,1.0.3)',\
 	org.apache.aries.spifly.dynamic.framework.extension;version='[1.2.0,1.2.1)',\
@@ -75,4 +75,4 @@
 	org.jboss.weld.osgi-bundle;version='[3.0.5,3.0.6)',\
 	org.osgi.service.cdi;version='[1.0.0,1.0.1)',\
 	org.osgi.util.function;version='[1.1.0,1.1.1)',\
-	org.osgi.util.promise;version='[1.1.0,1.1.1)'
+	org.osgi.util.promise;version='[1.1.0,1.1.1)',\
diff --git a/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/SlimTestCase.java b/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/SlimTestCase.java
new file mode 100644
index 0000000..73ac5f8
--- /dev/null
+++ b/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/SlimTestCase.java
@@ -0,0 +1,26 @@
+package org.apache.aries.cdi.test.cases;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+public class SlimTestCase extends AbstractTestCase {
+
+	@BeforeClass
+	public static void beforeClass() throws Exception {
+	}
+
+	@AfterClass
+	public static void afterClass() throws Exception {
+	}
+
+	@Override
+	public void setUp() throws Exception {
+	}
+
+	@After
+	@Override
+	public void tearDown() throws Exception {
+	}
+
+}
diff --git a/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/Test152_3.java b/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/Test152_3.java
index 3430064..bd5f805 100644
--- a/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/Test152_3.java
+++ b/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/Test152_3.java
@@ -19,32 +19,12 @@ import static org.assertj.core.api.Assertions.assertThat;
 import javax.enterprise.context.spi.Context;
 
 import org.apache.aries.cdi.test.interfaces.BeanService;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
 import org.junit.Test;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
 import org.osgi.util.tracker.ServiceTracker;
 
-public class Test152_3 extends AbstractTestCase {
-
-	@BeforeClass
-	public static void beforeClass() throws Exception {
-	}
-
-	@AfterClass
-	public static void afterClass() throws Exception {
-	}
-
-	@Override
-	public void setUp() throws Exception {
-	}
-
-	@After
-	@Override
-	public void tearDown() throws Exception {
-	}
+public class Test152_3 extends SlimTestCase {
 
 	@Test
 	public void componentScopeContext() throws Exception {
diff --git a/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/Test152_3_1.java b/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/Test152_3_1.java
index 66d8826..2f6efca 100644
--- a/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/Test152_3_1.java
+++ b/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/Test152_3_1.java
@@ -25,8 +25,6 @@ import javax.enterprise.inject.spi.EventMetadata;
 
 import org.apache.aries.cdi.test.interfaces.BeanService;
 import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
 import org.junit.Test;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
@@ -37,15 +35,7 @@ import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.util.tracker.ServiceTracker;
 
-public class Test152_3_1 extends AbstractTestCase {
-
-	@BeforeClass
-	public static void beforeClass() throws Exception {
-	}
-
-	@AfterClass
-	public static void afterClass() throws Exception {
-	}
+public class Test152_3_1 extends SlimTestCase {
 
 	@Override
 	public void setUp() throws Exception {
diff --git a/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/Test152_3_1_1.java b/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/Test152_3_1_1.java
index 0183e1f..ce039c9 100644
--- a/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/Test152_3_1_1.java
+++ b/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/Test152_3_1_1.java
@@ -24,8 +24,6 @@ import java.util.function.Consumer;
 
 import org.apache.aries.cdi.test.interfaces.Pojo;
 import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
 import org.junit.Test;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
@@ -38,15 +36,7 @@ import org.osgi.util.promise.Deferred;
 import org.osgi.util.promise.Success;
 import org.osgi.util.tracker.ServiceTracker;
 
-public class Test152_3_1_1 extends AbstractTestCase {
-
-	@BeforeClass
-	public static void beforeClass() throws Exception {
-	}
-
-	@AfterClass
-	public static void afterClass() throws Exception {
-	}
+public class Test152_3_1_1 extends SlimTestCase {
 
 	@Override
 	public void setUp() throws Exception {
diff --git a/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/Test_discoverByBeansXml.java b/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/Test_discoverByBeansXml.java
new file mode 100644
index 0000000..24026be
--- /dev/null
+++ b/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/Test_discoverByBeansXml.java
@@ -0,0 +1,54 @@
+/**
+ * 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.test.cases;
+
+import static org.assertj.core.api.Assertions.*;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.junit.Ignore;
+import org.osgi.framework.Bundle;
+import org.osgi.service.cdi.runtime.CDIComponentRuntime;
+import org.osgi.service.cdi.runtime.dto.template.ContainerTemplateDTO;
+
+public class Test_discoverByBeansXml extends SlimTestCase {
+
+	@Ignore("Until we get bnd 4.3.0")
+	//@Test
+	public void componentScopeContext() throws Exception {
+		Bundle tbBundle = installBundle("tb14.jar");
+
+		getBeanManager(tbBundle);
+
+		try (CloseableTracker<CDIComponentRuntime, CDIComponentRuntime> ccrTracker = track(
+				"(objectClass=%s)", CDIComponentRuntime.class.getName())) {
+
+			CDIComponentRuntime ccr = ccrTracker.waitForService(timeout);
+
+			ContainerTemplateDTO containerTemplateDTO = ccr.getContainerTemplateDTO(tbBundle);
+
+			assertThat(containerTemplateDTO).isNotNull();
+
+			List<String> beans = containerTemplateDTO.components.stream().flatMap(c -> c.beans.stream()).collect(Collectors.toList());
+
+			assertThat(beans).isNotEmpty().contains("org.apache.aries.cdi.test.tb14.ABean");
+		}
+		finally {
+			tbBundle.uninstall();
+		}
+	}
+
+}
diff --git a/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb14/ABean.java b/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb14/ABean.java
new file mode 100644
index 0000000..e6a686c
--- /dev/null
+++ b/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb14/ABean.java
@@ -0,0 +1,18 @@
+/**
+ * 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.test.tb14;
+
+public class ABean {
+}