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:43 UTC

[aries-cdi] 24/27: mp-config extension

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 df6d32119095a0bc414e4c0a78820627032fa3f4
Author: Raymond Augé <ro...@apache.org>
AuthorDate: Sun Nov 24 15:57:17 2019 -0500

    mp-config extension
    
    Signed-off-by: Raymond Augé <ro...@apache.org>
---
 cdi-bom/pom.xml                                    |   6 +
 cdi-extension-mp-config/pom.xml                    | 156 +++++++++++++++++++++
 .../apache/aries/cdi/extension/mp/config/BB.java   |  60 ++++++++
 .../mp/config/StubConfigProviderResolver.java      |  24 ++++
 .../cdi/extension/mp/config/StubExtension.java     |  52 +++++++
 .../cdi/extension/mp/config/package-info.java      |  39 ++++++
 pom.xml                                            |  14 ++
 7 files changed, 351 insertions(+)

diff --git a/cdi-bom/pom.xml b/cdi-bom/pom.xml
index c383257..29f8f16 100644
--- a/cdi-bom/pom.xml
+++ b/cdi-bom/pom.xml
@@ -71,6 +71,12 @@
 			</dependency>
 			<dependency>
 				<groupId>org.apache.aries.cdi</groupId>
+				<artifactId>org.apache.aries.cdi.extension.mp-config</artifactId>
+				<version>${project.version}</version>
+				<scope>compile</scope>
+			</dependency>
+			<dependency>
+				<groupId>org.apache.aries.cdi</groupId>
 				<artifactId>org.apache.aries.cdi.extra</artifactId>
 				<version>${project.version}</version>
 				<scope>compile</scope>
diff --git a/cdi-extension-mp-config/pom.xml b/cdi-extension-mp-config/pom.xml
new file mode 100644
index 0000000..eb7968d
--- /dev/null
+++ b/cdi-extension-mp-config/pom.xml
@@ -0,0 +1,156 @@
+<?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>
+
+	<properties>
+		<mp.config.version>1.3</mp.config.version>
+		<byte.buddy.version>1.10.3</byte.buddy.version>
+	</properties>
+
+	<artifactId>org.apache.aries.cdi.extension.mp-config</artifactId>
+	<name>Apache Aries CDI - MicroProfile Config ${mp.config.version} Using Apache Geronimo</name>
+	<description>Apache Aries CDI - MicroProfile Config ${mp.config.version} Using Apache Geronimo</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[
+						Export-Package: org.eclipse.microprofile.config.*
+						Import-Package: \
+							!net.bytebuddy.*,\
+							!org.osgi.annotation.bundle.*,\
+							*
+						-includepackage: org.apache.geronimo.config.*
+						-cdiannotations:
+						-noclassforname: true
+						-fixupmessages: "Split package...";is:=ignore
+					]]></bnd>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>net.bytebuddy</groupId>
+				<artifactId>byte-buddy-maven-plugin</artifactId>
+				<version>${byte.buddy.version}</version>
+				<executions>
+					<execution>
+						<goals>
+							<goal>transform</goal>
+						</goals>
+					</execution>
+				</executions>
+				<configuration>
+					<transformations>
+						<transformation>
+							<plugin>org.apache.aries.cdi.extension.mp.config.BB</plugin>
+							<arguments>
+								<argument>
+									<index>1</index>
+									<value>${mp.config.version}</value>
+								</argument>
+							</arguments>
+						</transformation>
+					</transformations>
+				</configuration>
+				<dependencies>
+					<dependency>
+						<groupId>org.osgi</groupId>
+						<artifactId>osgi.annotation</artifactId>
+						<version>7.0.0</version>
+					</dependency>
+				</dependencies>
+			</plugin>
+		</plugins>
+	</build>
+
+	<dependencies>
+		<dependency>
+			<groupId>biz.aQute.bnd</groupId>
+			<artifactId>biz.aQute.bnd.annotation</artifactId>
+			<version>${bnd.version}</version>
+			<scope>provided</scope>
+		</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-jcdi_2.0_spec</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.geronimo.config</groupId>
+			<artifactId>geronimo-config-impl</artifactId>
+			<version>1.2.2</version>
+			<scope>provided</scope>
+		</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>osgi.annotation</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>osgi.core</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>net.bytebuddy</groupId>
+			<artifactId>byte-buddy</artifactId>
+			<version>${byte.buddy.version}</version>
+			<scope>provided</scope>
+		</dependency>
+	</dependencies>
+
+</project>
\ No newline at end of file
diff --git a/cdi-extension-mp-config/src/main/java/org/apache/aries/cdi/extension/mp/config/BB.java b/cdi-extension-mp-config/src/main/java/org/apache/aries/cdi/extension/mp/config/BB.java
new file mode 100644
index 0000000..1de5285
--- /dev/null
+++ b/cdi-extension-mp-config/src/main/java/org/apache/aries/cdi/extension/mp/config/BB.java
@@ -0,0 +1,60 @@
+/**
+ * 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.extension.mp.config;
+
+import java.io.IOException;
+
+import org.osgi.annotation.bundle.Requirement;
+import org.osgi.service.cdi.CDIConstants;
+
+import net.bytebuddy.build.BuildLogger;
+import net.bytebuddy.build.Plugin;
+import net.bytebuddy.description.annotation.AnnotationDescription;
+import net.bytebuddy.description.type.TypeDescription;
+import net.bytebuddy.dynamic.ClassFileLocator;
+import net.bytebuddy.dynamic.DynamicType.Builder;
+
+public class BB implements Plugin {
+
+	private final BuildLogger buildLogger;
+	private final String mpVersion;
+
+	public BB(BuildLogger buildLogger, String mpVersion) {
+		this.buildLogger = buildLogger;
+		this.mpVersion = mpVersion;
+	}
+
+	@Override
+	public boolean matches(TypeDescription target) {
+		return target.getName().equals("org.eclipse.microprofile.config.inject.ConfigProperty");
+	}
+
+	@Override
+	public Builder<?> apply(Builder<?> builder, TypeDescription typeDescription, ClassFileLocator cfl) {
+		buildLogger.info("Processing class: " + typeDescription.getActualName());
+
+		return builder.annotateType(
+			AnnotationDescription.Builder.ofType(Requirement.class)
+				.define("namespace", CDIConstants.CDI_EXTENSION_PROPERTY)
+				.define("name", "eclipse.microprofile.config")
+				.define("version", mpVersion)
+				.build());
+	}
+
+	@Override
+	public void close() throws IOException {
+	}
+
+}
diff --git a/cdi-extension-mp-config/src/main/java/org/apache/aries/cdi/extension/mp/config/StubConfigProviderResolver.java b/cdi-extension-mp-config/src/main/java/org/apache/aries/cdi/extension/mp/config/StubConfigProviderResolver.java
new file mode 100644
index 0000000..63245e5
--- /dev/null
+++ b/cdi-extension-mp-config/src/main/java/org/apache/aries/cdi/extension/mp/config/StubConfigProviderResolver.java
@@ -0,0 +1,24 @@
+/**
+ * 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.extension.mp.config;
+
+import org.apache.geronimo.config.DefaultConfigProvider;
+import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
+
+import aQute.bnd.annotation.spi.ServiceProvider;
+
+@ServiceProvider(ConfigProviderResolver.class)
+public class StubConfigProviderResolver extends DefaultConfigProvider {
+}
diff --git a/cdi-extension-mp-config/src/main/java/org/apache/aries/cdi/extension/mp/config/StubExtension.java b/cdi-extension-mp-config/src/main/java/org/apache/aries/cdi/extension/mp/config/StubExtension.java
new file mode 100644
index 0000000..84040cd
--- /dev/null
+++ b/cdi-extension-mp-config/src/main/java/org/apache/aries/cdi/extension/mp/config/StubExtension.java
@@ -0,0 +1,52 @@
+/**
+ * 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.extension.mp.config;
+
+import static org.apache.aries.cdi.extension.mp.config.StubExtension.EXTENSION_NAME;
+import static org.osgi.service.cdi.CDIConstants.CDI_EXTENSION_PROPERTY;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.Extension;
+
+import org.apache.geronimo.config.cdi.ConfigExtension;
+import org.apache.geronimo.config.cdi.ConfigInjectionProducer;
+
+import aQute.bnd.annotation.spi.ServiceProvider;
+
+@ServiceProvider(
+	attribute = {
+		CDI_EXTENSION_PROPERTY + "=" + EXTENSION_NAME,
+		"service.scope=prototype",
+		"service.vendor=Apache Software Foundation",
+		"version:Version=1.3.0"
+	},
+	effective = "active",
+	uses = Extension.class,
+	value = Extension.class
+)
+public class StubExtension extends ConfigExtension {
+
+	public final static String EXTENSION_NAME = "eclipse.microprofile.config";
+
+	@Override
+	public void registerConfigProducer(@Observes AfterBeanDiscovery abd, BeanManager bm) {
+		abd.addBean().beanClass(ConfigInjectionProducer.class).createWith(c -> new ConfigInjectionProducer());
+
+		super.registerConfigProducer(abd, bm);
+	}
+
+}
diff --git a/cdi-extension-mp-config/src/main/java/org/apache/aries/cdi/extension/mp/config/package-info.java b/cdi-extension-mp-config/src/main/java/org/apache/aries/cdi/extension/mp/config/package-info.java
new file mode 100644
index 0000000..1980043
--- /dev/null
+++ b/cdi-extension-mp-config/src/main/java/org/apache/aries/cdi/extension/mp/config/package-info.java
@@ -0,0 +1,39 @@
+/**
+ * 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.
+ */
+
+@Capability(
+	attribute = "objectClass:List<String>=javax.enterprise.inject.spi.Extension",
+	namespace = SERVICE_NAMESPACE
+)
+@Capability(
+	namespace = CDI_EXTENSION_PROPERTY,
+	name = EXTENSION_NAME,
+	uses= {
+		javax.annotation.Priority.class,
+		javax.enterprise.event.Observes.class,
+		Extension.class
+	},
+	version = "1.3" // TODO ?maybe read this from pom property?
+)
+@RequireCDIExtender
+package org.apache.aries.cdi.extension.mp.config;
+
+import static org.apache.aries.cdi.extension.mp.config.StubExtension.EXTENSION_NAME;
+import static org.osgi.namespace.service.ServiceNamespace.SERVICE_NAMESPACE;
+import static org.osgi.service.cdi.CDIConstants.CDI_EXTENSION_PROPERTY;
+
+import javax.enterprise.inject.spi.Extension;
+
+import org.osgi.annotation.bundle.Capability;
+import org.osgi.service.cdi.annotations.RequireCDIExtender;
diff --git a/pom.xml b/pom.xml
index 1ccf7f5..f567cc4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -63,6 +63,7 @@
 		<module>cdi-extension-el-jsp</module>
 		<module>cdi-extension-http</module>
 		<module>cdi-extension-jndi</module>
+		<module>cdi-extension-mp-config</module>
 		<module>cdi-owb</module>
 		<module>cdi-weld</module>
 		<module>cdi-bom</module>
@@ -371,6 +372,19 @@
 										</ignore>
 									</action>
 								</pluginExecution>
+								<pluginExecution>
+									<pluginExecutionFilter>
+										<groupId>net.bytebuddy</groupId>
+										<artifactId>byte-buddy-maven-plugin</artifactId>
+										<versionRange>[${byte.buddy.version},)</versionRange>
+										<goals>
+											<goal>transform</goal>
+										</goals>
+									</pluginExecutionFilter>
+									<action>
+										<execute />
+									</action>
+								</pluginExecution>
 							</pluginExecutions>
 						</lifecycleMappingMetadata>
 					</configuration>