This is an automated email from the ASF dual-hosted git repository.
alien11689 pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/aries.git
The following commit(s) were added to refs/heads/trunk by this push:
new 3f542de19 ARIES-2172: Support jakarta.annotation in
blueprint-maven-plugin
3f542de19 is described below
commit 3f542de1909effe92a30f0efdbd00f2a5c9e384c
Author: Dominik Przybysz <[email protected]>
AuthorDate: Sun Mar 9 07:19:54 2025 +0100
ARIES-2172: Support jakarta.annotation in blueprint-maven-plugin
---
.github/dependabot.yaml | 3 ++
.../blueprint-maven-plugin/pom.xml | 8 ++++-
.../handlers/jakarta/PostConstructHandler.java | 42 ++++++++++++++++++++++
.../plugin/handlers/jakarta/PreDestroyHandler.java | 42 ++++++++++++++++++++++
...es.blueprint.plugin.spi.MethodAnnotationHandler | 2 ++
.../blueprint/plugin/BlueprintFileWriterTest.java | 2 ++
.../plugin/jakarta/SimpleJakartaBean.java | 9 +++++
7 files changed, 107 insertions(+), 1 deletion(-)
diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml
index 6adb31141..5e6bbce78 100644
--- a/.github/dependabot.yaml
+++ b/.github/dependabot.yaml
@@ -31,6 +31,9 @@ updates:
- dependency-name: "biz.aQute.bnd:bnd-maven-plugin"
versions:
- ">=7.0.0" # does not support java 8
+ - dependency-name: "jakarta.annotation:jakarta.annotation-api"
+ versions:
+ - ">=3.0.0" # does not support java 8
- dependency-name: "org.apache.derby:derby"
versions:
- ">=10.15.0" # does not support java 8
diff --git a/blueprint-maven-plugin/blueprint-maven-plugin/pom.xml
b/blueprint-maven-plugin/blueprint-maven-plugin/pom.xml
index a92d87b61..e55a7a8e9 100644
--- a/blueprint-maven-plugin/blueprint-maven-plugin/pom.xml
+++ b/blueprint-maven-plugin/blueprint-maven-plugin/pom.xml
@@ -42,9 +42,10 @@
<blueprint-maven-plugin-pax-cdi-handlers.version>1.0.0</blueprint-maven-plugin-pax-cdi-handlers.version>
<blueprint-maven-plugin-spi.version>1.1.0</blueprint-maven-plugin-spi.version>
<blueprint-maven-plugin-spring-handlers.version>1.0.0</blueprint-maven-plugin-spring-handlers.version>
+ <jakarta.annotation-api.version>2.1.1</jakarta.annotation-api.version>
<jakarta.inject.version>2.0.1</jakarta.inject.version>
-
<javax.enterprise.cdi-api.version>2.0.SP1</javax.enterprise.cdi-api.version>
<javax.annotation-api.version>1.3.2</javax.annotation-api.version>
+
<javax.enterprise.cdi-api.version>2.0.SP1</javax.enterprise.cdi-api.version>
<javax.inject.version>1</javax.inject.version>
<javax.transaction-api.version>1.2</javax.transaction-api.version>
<javax.transaction.cdi-api.version>1.2-b03</javax.transaction.cdi-api.version>
@@ -170,6 +171,11 @@
<artifactId>javax.annotation-api</artifactId>
<version>${javax.annotation-api.version}</version>
</dependency>
+ <dependency>
+ <groupId>jakarta.annotation</groupId>
+ <artifactId>jakarta.annotation-api</artifactId>
+ <version>${jakarta.annotation-api.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.aries.blueprint</groupId>
diff --git
a/blueprint-maven-plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/jakarta/PostConstructHandler.java
b/blueprint-maven-plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/jakarta/PostConstructHandler.java
new file mode 100644
index 000000000..caeffe84f
--- /dev/null
+++
b/blueprint-maven-plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/jakarta/PostConstructHandler.java
@@ -0,0 +1,42 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.blueprint.plugin.handlers.jakarta;
+
+import jakarta.annotation.PostConstruct;
+import org.apache.aries.blueprint.plugin.spi.BeanEnricher;
+import org.apache.aries.blueprint.plugin.spi.ContextEnricher;
+import org.apache.aries.blueprint.plugin.spi.MethodAnnotationHandler;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+public class PostConstructHandler implements
MethodAnnotationHandler<PostConstruct> {
+ @Override
+ public Class<PostConstruct> getAnnotation() {
+ return PostConstruct.class;
+ }
+
+ @Override
+ public void handleMethodAnnotation(Class<?> clazz, List<Method> methods,
ContextEnricher contextEnricher, BeanEnricher beanEnricher) {
+ if (methods.size() > 1) {
+ throw new IllegalArgumentException("There can be only one method
annotated with @PostConstruct in bean");
+ }
+ beanEnricher.addAttribute("init-method", methods.get(0).getName());
+ }
+}
diff --git
a/blueprint-maven-plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/jakarta/PreDestroyHandler.java
b/blueprint-maven-plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/jakarta/PreDestroyHandler.java
new file mode 100644
index 000000000..776777018
--- /dev/null
+++
b/blueprint-maven-plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/jakarta/PreDestroyHandler.java
@@ -0,0 +1,42 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.blueprint.plugin.handlers.jakarta;
+
+import jakarta.annotation.PreDestroy;
+import org.apache.aries.blueprint.plugin.spi.BeanEnricher;
+import org.apache.aries.blueprint.plugin.spi.ContextEnricher;
+import org.apache.aries.blueprint.plugin.spi.MethodAnnotationHandler;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+public class PreDestroyHandler implements MethodAnnotationHandler<PreDestroy> {
+ @Override
+ public Class<PreDestroy> getAnnotation() {
+ return PreDestroy.class;
+ }
+
+ @Override
+ public void handleMethodAnnotation(Class<?> clazz, List<Method> methods,
ContextEnricher contextEnricher, BeanEnricher beanEnricher) {
+ if (methods.size() > 1) {
+ throw new IllegalArgumentException("There can be only one method
annotated with @PreDestroy in bean");
+ }
+ beanEnricher.addAttribute("destroy-method", methods.get(0).getName());
+ }
+}
diff --git
a/blueprint-maven-plugin/blueprint-maven-plugin/src/main/resources/META-INF/services/org.apache.aries.blueprint.plugin.spi.MethodAnnotationHandler
b/blueprint-maven-plugin/blueprint-maven-plugin/src/main/resources/META-INF/services/org.apache.aries.blueprint.plugin.spi.MethodAnnotationHandler
index f8c461b21..3f1677c4f 100644
---
a/blueprint-maven-plugin/blueprint-maven-plugin/src/main/resources/META-INF/services/org.apache.aries.blueprint.plugin.spi.MethodAnnotationHandler
+++
b/blueprint-maven-plugin/blueprint-maven-plugin/src/main/resources/META-INF/services/org.apache.aries.blueprint.plugin.spi.MethodAnnotationHandler
@@ -15,6 +15,8 @@
# limitations under the License.
#
+org.apache.aries.blueprint.plugin.handlers.jakarta.PostConstructHandler
+org.apache.aries.blueprint.plugin.handlers.jakarta.PreDestroyHandler
org.apache.aries.blueprint.plugin.handlers.javax.PostConstructHandler
org.apache.aries.blueprint.plugin.handlers.javax.PreDestroyHandler
org.apache.aries.blueprint.plugin.handlers.javax.JavaxTransactionFactory
diff --git
a/blueprint-maven-plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/BlueprintFileWriterTest.java
b/blueprint-maven-plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/BlueprintFileWriterTest.java
index 8beef909c..f4dae170c 100644
---
a/blueprint-maven-plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/BlueprintFileWriterTest.java
+++
b/blueprint-maven-plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/BlueprintFileWriterTest.java
@@ -1406,6 +1406,8 @@ public class BlueprintFileWriterTest {
public void testGenerateBeanWithJakartaAnnotatedBeans() throws Exception {
Node simpleJakartaBean = getBeanById("simpleJakartaBean");
assertXpathEquals(simpleJakartaBean, "@class",
SimpleJakartaBean.class.getName());
+ assertXpathEquals(simpleJakartaBean, "@init-method", "setup");
+ assertXpathEquals(simpleJakartaBean, "@destroy-method", "cleanup");
Node unnamedJakartaBean = getBeanById("unnamedJakartaBean");
assertXpathEquals(unnamedJakartaBean, "@class",
UnnamedJakartaBean.class.getName());
diff --git
a/blueprint-maven-plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/jakarta/SimpleJakartaBean.java
b/blueprint-maven-plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/jakarta/SimpleJakartaBean.java
index 54c63ae86..a3537aba0 100644
---
a/blueprint-maven-plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/jakarta/SimpleJakartaBean.java
+++
b/blueprint-maven-plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/jakarta/SimpleJakartaBean.java
@@ -18,8 +18,17 @@
*/
package org.apache.aries.blueprint.plugin.jakarta;
+import jakarta.annotation.PostConstruct;
+import jakarta.annotation.PreDestroy;
import jakarta.inject.Singleton;
@Singleton
public class SimpleJakartaBean {
+ @PostConstruct
+ public void setup() {
+ }
+
+ @PreDestroy
+ public void cleanup() {
+ }
}