Skip to content

Commit 58398b9

Browse files
committed
Arc - consider @decorator to be bean defining annotation. Add automated test.
1 parent aee6916 commit 58398b9

File tree

8 files changed

+129
-1
lines changed

8 files changed

+129
-1
lines changed

build-parent/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@
277277
<artifactId>quarkus-arc-test-supplement</artifactId>
278278
<version>${project.version}</version>
279279
</dependency>
280+
<dependency>
281+
<groupId>io.quarkus</groupId>
282+
<artifactId>quarkus-arc-test-supplement-decorator</artifactId>
283+
<version>${project.version}</version>
284+
</dependency>
280285
<dependency>
281286
<groupId>org.assertj</groupId>
282287
<artifactId>assertj-core</artifactId>

extensions/arc/deployment/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
<artifactId>quarkus-arc-test-supplement</artifactId>
5050
<scope>test</scope>
5151
</dependency>
52+
<dependency>
53+
<groupId>io.quarkus</groupId>
54+
<artifactId>quarkus-arc-test-supplement-decorator</artifactId>
55+
<scope>test</scope>
56+
</dependency>
5257
<!-- Used to test wrong @Singleton detection -->
5358
<dependency>
5459
<groupId>jakarta.ejb</groupId>

extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/BeanArchiveProcessor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,14 @@ private IndexView buildApplicationIndex(ArcConfig config, ApplicationArchivesBui
149149
.map(bda -> new BeanDefiningAnnotation(bda.getName(), bda.getDefaultScope()))
150150
.collect(Collectors.toList()), stereotypes);
151151
beanDefiningAnnotations.addAll(customScopes.getCustomScopeNames());
152-
// Also include archives that are not bean archives but contain scopes, qualifiers or interceptor bindings
152+
// Also include archives that are not bean archives but contain scopes, qualifiers,
153+
// interceptor bindings, interceptors or decorators
153154
beanDefiningAnnotations.add(DotNames.SCOPE);
154155
beanDefiningAnnotations.add(DotNames.NORMAL_SCOPE);
155156
beanDefiningAnnotations.add(DotNames.QUALIFIER);
156157
beanDefiningAnnotations.add(DotNames.INTERCEPTOR_BINDING);
158+
beanDefiningAnnotations.add(DotNames.DECORATOR);
159+
beanDefiningAnnotations.add(DotNames.INTERCEPTOR);
157160

158161
boolean rootIsAlwaysBeanArchive = !config.strictCompatibility();
159162
Collection<ApplicationArchive> candidateArchives = applicationArchivesBuildItem.getApplicationArchives();
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package io.quarkus.arc.test.decorator;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.util.List;
6+
7+
import jakarta.enterprise.context.Dependent;
8+
import jakarta.inject.Inject;
9+
10+
import org.junit.jupiter.api.Test;
11+
import org.junit.jupiter.api.extension.RegisterExtension;
12+
13+
import io.quarkus.arc.test.supplement.decorator.SomeInterface;
14+
import io.quarkus.builder.Version;
15+
import io.quarkus.maven.dependency.Dependency;
16+
import io.quarkus.test.QuarkusUnitTest;
17+
18+
public class DecoratorAsBeanDefiningAnnotationTest {
19+
20+
// The test has a CDI bean in the application and a decorator in a second archive that has no other CDI items.
21+
// The idea is to test that @Decorator is a bean defining annotation and will be picked up.
22+
23+
@RegisterExtension
24+
static final QuarkusUnitTest config = new QuarkusUnitTest()
25+
.withApplicationRoot(jar -> jar.addClass(SomeBean.class))
26+
// we need a non-application archive, so cannot use `withAdditionalDependency()`
27+
.setForcedDependencies(
28+
List.of(Dependency.of("io.quarkus", "quarkus-arc-test-supplement-decorator", Version.getVersion())));
29+
30+
@Inject
31+
SomeBean bean;
32+
33+
@Test
34+
public void test() {
35+
assertEquals("Delegated: SomeBean", bean.ping());
36+
}
37+
38+
@Dependent
39+
public static class SomeBean implements SomeInterface {
40+
41+
@Override
42+
public String ping() {
43+
return SomeBean.class.getSimpleName();
44+
}
45+
}
46+
}

extensions/arc/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<module>deployment</module>
1818
<module>runtime</module>
1919
<module>test-supplement</module>
20+
<module>test-supplement-decorator</module>
2021
</modules>
2122

2223
</project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>quarkus-arc-parent</artifactId>
7+
<groupId>io.quarkus</groupId>
8+
<version>999-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>quarkus-arc-test-supplement-decorator</artifactId>
13+
<name>Quarkus - ArC - Test Supplement Decorator</name>
14+
<description>Supplement archive for ArC tests</description>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>jakarta.enterprise</groupId>
19+
<artifactId>jakarta.enterprise.cdi-api</artifactId>
20+
</dependency>
21+
</dependencies>
22+
23+
<build>
24+
<plugins>
25+
<plugin>
26+
<groupId>io.smallrye</groupId>
27+
<artifactId>jandex-maven-plugin</artifactId>
28+
<executions>
29+
<execution>
30+
<id>make-index</id>
31+
<goals>
32+
<goal>jandex</goal>
33+
</goals>
34+
</execution>
35+
</executions>
36+
</plugin>
37+
</plugins>
38+
</build>
39+
40+
</project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.quarkus.arc.test.supplement.decorator;
2+
3+
import jakarta.annotation.Priority;
4+
import jakarta.decorator.Decorator;
5+
import jakarta.decorator.Delegate;
6+
import jakarta.inject.Inject;
7+
8+
@Decorator
9+
@Priority(10)
10+
public class SomeDecorator implements SomeInterface {
11+
12+
@Inject
13+
@Delegate
14+
SomeInterface delegate;
15+
16+
@Override
17+
public String ping() {
18+
return "Delegated: " + delegate.ping();
19+
}
20+
21+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.quarkus.arc.test.supplement.decorator;
2+
3+
public interface SomeInterface {
4+
5+
String ping();
6+
7+
}

0 commit comments

Comments
 (0)