Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARIES-2172: Support jakarta.enterprise.cdi-api in blueprint-maven-plugin #554

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ updates:
- dependency-name: "jakarta.annotation:jakarta.annotation-api"
versions:
- ">=3.0.0" # does not support java 8
- dependency-name: "jakarta.enterprise:jakarta.enterprise.cdi-api"
versions:
- ">=4.0.0" # does not support java 8
- dependency-name: "javax.enterprise:cdi-api"
versions:
- ">2.0.SP1" # 2.0-PFD2 is considered as newer, but is older
Expand Down
6 changes: 6 additions & 0 deletions blueprint-maven-plugin/blueprint-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<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.enterprise.cdi-api.version>3.0.1</jakarta.enterprise.cdi-api.version>
<jakarta.inject.version>2.0.1</jakarta.inject.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>
Expand Down Expand Up @@ -156,6 +157,11 @@
<artifactId>cdi-api</artifactId>
<version>${javax.enterprise.cdi-api.version}</version>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<version>${jakarta.enterprise.cdi-api.version}</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* 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.enterprise.inject.Produces;
import org.apache.aries.blueprint.plugin.spi.FactoryMethodFinder;

public class ProducesHandler implements FactoryMethodFinder<Produces> {
@Override
public Class<Produces> getAnnotation() {
return Produces.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
# limitations under the License.
#

org.apache.aries.blueprint.plugin.handlers.jakarta.ProducesHandler
org.apache.aries.blueprint.plugin.handlers.javax.ProducesHandler
org.apache.aries.blueprint.plugin.handlers.blueprint.bean.BeanHandler
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
import static org.junit.Assert.assertNotNull;

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

@Test
public void testJakartaProducesNamedBeans() throws Exception {
Node producer = getBeanById("jakartaFactoryBean");
assertXpathEquals(producer, "@class", JakartaFactoryBean.class.getName());

Node bean1 = getBeanById("producedBean");
assertXpathEquals(bean1, "@class", ProducedBean.class.getName());
assertXpathEquals(bean1, "@factory-ref", "jakartaFactoryBean");
assertXpathEquals(bean1, "@factory-method", "create");

Node bean2 = getBeanById("namedProducedBean");
assertXpathEquals(bean2, "@class", ProducedBean.class.getName());
assertXpathEquals(bean2, "@factory-ref", "jakartaFactoryBean");
assertXpathEquals(bean2, "@factory-method", "createBeanWithParameters");
assertXpathEquals(bean2, "argument[1]/@ref", "myBean1");
assertXpathEquals(bean2, "argument[2]/@value", "100");
assertXpathEquals(bean2, "argument[3]/@ref", "refServiceC");
}

private void assertXpathDoesNotExist(Node node, String xpathExpression) throws XPathExpressionException {
assertXpathEquals(node, "count(" + xpathExpression + ")", "0");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.jakarta;

import jakarta.enterprise.inject.Produces;
import jakarta.inject.Named;
import jakarta.inject.Singleton;
import org.apache.aries.blueprint.annotation.config.ConfigProperty;
import org.apache.aries.blueprint.annotation.service.Reference;
import org.apache.aries.blueprint.plugin.test.MyBean1;
import org.apache.aries.blueprint.plugin.test.interfaces.ServiceC;

@Singleton
public class JakartaFactoryBean {

@Produces
public ProducedBean create() {
return new ProducedBean();
}

@Produces
@Named("namedProducedBean")
public ProducedBean createBeanWithParameters(MyBean1 myBean1, @ConfigProperty("100") int bla, @Reference @Named("refServiceC") ServiceC myReference) {
return new ProducedBean();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* 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.jakarta;

public class ProducedBean {
}