-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ArC: register synthetic injection points in a separate phase
- this fixes the problem where an synthetic injection point from a SyntheticBeanBuiltItem was not considered when detecting unused beans
- Loading branch information
Showing
5 changed files
with
134 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...ment/src/test/java/io/quarkus/arc/test/unused/UnremovableSyntheticInjectionPointTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package io.quarkus.arc.test.unused; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.Vetoed; | ||
|
||
import org.jboss.jandex.ClassType; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.ArcContainer; | ||
import io.quarkus.arc.BeanCreator; | ||
import io.quarkus.arc.InstanceHandle; | ||
import io.quarkus.arc.SyntheticCreationalContext; | ||
import io.quarkus.arc.deployment.SyntheticBeanBuildItem; | ||
import io.quarkus.arc.processor.BuiltinScope; | ||
import io.quarkus.builder.BuildChainBuilder; | ||
import io.quarkus.builder.BuildContext; | ||
import io.quarkus.builder.BuildStep; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class UnremovableSyntheticInjectionPointTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(UnremovableSyntheticInjectionPointTest.class, Alpha.class, Gama.class, GamaCreator.class)) | ||
.addBuildChainCustomizer(buildCustomizer()); | ||
|
||
static Consumer<BuildChainBuilder> buildCustomizer() { | ||
return new Consumer<BuildChainBuilder>() { | ||
|
||
@Override | ||
public void accept(BuildChainBuilder builder) { | ||
builder.addBuildStep(new BuildStep() { | ||
|
||
@Override | ||
public void execute(BuildContext context) { | ||
context.produce(SyntheticBeanBuildItem.configure(Gama.class) | ||
.scope(BuiltinScope.SINGLETON.getInfo()) | ||
.unremovable() | ||
.addInjectionPoint(ClassType.create(Alpha.class)) | ||
.creator(GamaCreator.class) | ||
.done()); | ||
} | ||
}).produces(SyntheticBeanBuildItem.class).build(); | ||
} | ||
}; | ||
} | ||
|
||
@Test | ||
public void testBeans() { | ||
ArcContainer container = Arc.container(); | ||
InstanceHandle<Alpha> alpha = container.instance(Alpha.class); | ||
assertTrue(alpha.isAvailable()); | ||
assertTrue(alpha.get().ping()); | ||
InstanceHandle<Gama> gama = container.instance(Gama.class); | ||
assertTrue(gama.isAvailable()); | ||
assertTrue(gama.get().ping()); | ||
} | ||
|
||
// unused bean injected into a synthetic injection point | ||
@ApplicationScoped | ||
public static class Alpha { | ||
|
||
volatile boolean flag; | ||
|
||
@PostConstruct | ||
void init() { | ||
flag = true; | ||
} | ||
|
||
public boolean ping() { | ||
return flag; | ||
} | ||
|
||
} | ||
|
||
@Vetoed | ||
public static class Gama { | ||
|
||
private final Alpha alpha; | ||
|
||
private Gama(Alpha alpha) { | ||
this.alpha = alpha; | ||
} | ||
|
||
public boolean ping() { | ||
return alpha.ping(); | ||
} | ||
|
||
} | ||
|
||
public static class GamaCreator implements BeanCreator<Gama> { | ||
|
||
@Override | ||
public Gama create(SyntheticCreationalContext<Gama> context) { | ||
return new Gama(context.getInjectedReference(Alpha.class)); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters