Skip to content

Commit 49b2cc5

Browse files
committed
ARIES-2172: Support jakarta.enterprise.cdi-api in blueprint-maven-plugin
1 parent c805a95 commit 49b2cc5

File tree

7 files changed

+124
-0
lines changed

7 files changed

+124
-0
lines changed

.github/dependabot.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ updates:
3434
- dependency-name: "jakarta.annotation:jakarta.annotation-api"
3535
versions:
3636
- ">=3.0.0" # does not support java 8
37+
- dependency-name: "jakarta.enterprise:jakarta.enterprise.cdi-api"
38+
versions:
39+
- ">=4.0.0" # does not support java 8
3740
- dependency-name: "javax.enterprise:cdi-api"
3841
versions:
3942
- ">2.0.SP1" # 2.0-PFD2 is considered as newer, but is older

blueprint-maven-plugin/blueprint-maven-plugin/pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<blueprint-maven-plugin-spi.version>1.1.0</blueprint-maven-plugin-spi.version>
4444
<blueprint-maven-plugin-spring-handlers.version>1.0.0</blueprint-maven-plugin-spring-handlers.version>
4545
<jakarta.annotation-api.version>2.1.1</jakarta.annotation-api.version>
46+
<jakarta.enterprise.cdi-api.version>3.0.1</jakarta.enterprise.cdi-api.version>
4647
<jakarta.inject.version>2.0.1</jakarta.inject.version>
4748
<javax.annotation-api.version>1.3.2</javax.annotation-api.version>
4849
<javax.enterprise.cdi-api.version>2.0.SP1</javax.enterprise.cdi-api.version>
@@ -156,6 +157,11 @@
156157
<artifactId>cdi-api</artifactId>
157158
<version>${javax.enterprise.cdi-api.version}</version>
158159
</dependency>
160+
<dependency>
161+
<groupId>jakarta.enterprise</groupId>
162+
<artifactId>jakarta.enterprise.cdi-api</artifactId>
163+
<version>${jakarta.enterprise.cdi-api.version}</version>
164+
</dependency>
159165
<dependency>
160166
<groupId>javax.persistence</groupId>
161167
<artifactId>persistence-api</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.aries.blueprint.plugin.handlers.jakarta;
20+
21+
import jakarta.enterprise.inject.Produces;
22+
import org.apache.aries.blueprint.plugin.spi.FactoryMethodFinder;
23+
24+
public class ProducesHandler implements FactoryMethodFinder<Produces> {
25+
@Override
26+
public Class<Produces> getAnnotation() {
27+
return Produces.class;
28+
}
29+
}

blueprint-maven-plugin/blueprint-maven-plugin/src/main/resources/META-INF/services/org.apache.aries.blueprint.plugin.spi.FactoryMethodFinder

+1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
# limitations under the License.
1616
#
1717

18+
org.apache.aries.blueprint.plugin.handlers.jakarta.ProducesHandler
1819
org.apache.aries.blueprint.plugin.handlers.javax.ProducesHandler
1920
org.apache.aries.blueprint.plugin.handlers.blueprint.bean.BeanHandler

blueprint-maven-plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/BlueprintFileWriterTest.java

+21
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
import static org.junit.Assert.assertNotNull;
4949

5050
import com.google.common.collect.Sets;
51+
import org.apache.aries.blueprint.plugin.jakarta.JakartaFactoryBean;
5152
import org.apache.aries.blueprint.plugin.jakarta.NamedJakartaBean;
53+
import org.apache.aries.blueprint.plugin.jakarta.ProducedBean;
5254
import org.apache.aries.blueprint.plugin.jakarta.SimpleJakartaBean;
5355
import org.apache.aries.blueprint.plugin.jakarta.SimpleJakartaBeanUsage;
5456
import org.apache.aries.blueprint.plugin.jakarta.SimpleJakartaBeanUsageViaField;
@@ -1430,6 +1432,25 @@ public void testGenerateBeanWithJakartaAnnotatedBeans() throws Exception {
14301432
assertXpathEquals(injectingBeanViaFields, "property[@name='c']/@ref", "test-named-jakarta-bean");
14311433
}
14321434

1435+
@Test
1436+
public void testJakartaProducesNamedBeans() throws Exception {
1437+
Node producer = getBeanById("jakartaFactoryBean");
1438+
assertXpathEquals(producer, "@class", JakartaFactoryBean.class.getName());
1439+
1440+
Node bean1 = getBeanById("producedBean");
1441+
assertXpathEquals(bean1, "@class", ProducedBean.class.getName());
1442+
assertXpathEquals(bean1, "@factory-ref", "jakartaFactoryBean");
1443+
assertXpathEquals(bean1, "@factory-method", "create");
1444+
1445+
Node bean2 = getBeanById("namedProducedBean");
1446+
assertXpathEquals(bean2, "@class", ProducedBean.class.getName());
1447+
assertXpathEquals(bean2, "@factory-ref", "jakartaFactoryBean");
1448+
assertXpathEquals(bean2, "@factory-method", "createBeanWithParameters");
1449+
assertXpathEquals(bean2, "argument[1]/@ref", "myBean1");
1450+
assertXpathEquals(bean2, "argument[2]/@value", "100");
1451+
assertXpathEquals(bean2, "argument[3]/@ref", "refServiceC");
1452+
}
1453+
14331454
private void assertXpathDoesNotExist(Node node, String xpathExpression) throws XPathExpressionException {
14341455
assertXpathEquals(node, "count(" + xpathExpression + ")", "0");
14351456
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.aries.blueprint.plugin.jakarta;
20+
21+
import jakarta.enterprise.inject.Produces;
22+
import jakarta.inject.Named;
23+
import jakarta.inject.Singleton;
24+
import org.apache.aries.blueprint.annotation.config.ConfigProperty;
25+
import org.apache.aries.blueprint.annotation.service.Reference;
26+
import org.apache.aries.blueprint.plugin.test.MyBean1;
27+
import org.apache.aries.blueprint.plugin.test.interfaces.ServiceC;
28+
29+
@Singleton
30+
public class JakartaFactoryBean {
31+
32+
@Produces
33+
public ProducedBean create() {
34+
return new ProducedBean();
35+
}
36+
37+
@Produces
38+
@Named("namedProducedBean")
39+
public ProducedBean createBeanWithParameters(MyBean1 myBean1, @ConfigProperty("100") int bla, @Reference @Named("refServiceC") ServiceC myReference) {
40+
return new ProducedBean();
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.aries.blueprint.plugin.jakarta;
20+
21+
public class ProducedBean {
22+
}

0 commit comments

Comments
 (0)