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

Turn StartupBuildSteps.annotationTransformer() into an AutoAddScopeBuildItem #11708

Merged
merged 1 commit into from
Aug 31, 2020
Merged
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.quarkus.arc.deployment;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.spi.Contextual;
import javax.enterprise.context.spi.CreationalContext;

Expand All @@ -18,8 +17,6 @@
import io.quarkus.arc.deployment.ObserverRegistrationPhaseBuildItem.ObserverConfiguratorBuildItem;
import io.quarkus.arc.impl.CreationalContextImpl;
import io.quarkus.arc.processor.AnnotationStore;
import io.quarkus.arc.processor.Annotations;
import io.quarkus.arc.processor.AnnotationsTransformer;
import io.quarkus.arc.processor.BeanInfo;
import io.quarkus.arc.processor.BuildExtension;
import io.quarkus.arc.processor.BuiltinScope;
Expand Down Expand Up @@ -51,26 +48,13 @@ public class StartupBuildSteps {
private static final Logger LOGGER = Logger.getLogger(StartupBuildSteps.class);

@BuildStep
AnnotationsTransformerBuildItem annotationTransformer(CustomScopeAnnotationsBuildItem customScopes) {
return new AnnotationsTransformerBuildItem(new AnnotationsTransformer() {

@Override
public boolean appliesTo(org.jboss.jandex.AnnotationTarget.Kind kind) {
return kind == org.jboss.jandex.AnnotationTarget.Kind.CLASS;
}

@Override
public void transform(TransformationContext context) {
if (context.isClass() && !customScopes.isScopeDeclaredOn(context.getTarget().asClass())) {
// Class with no built-in scope annotation but with @Scheduled method
if (Annotations.contains(context.getTarget().asClass().classAnnotations(), STARTUP_NAME)) {
LOGGER.debugf("Found @Startup on a class %s with no scope annotations - adding @ApplicationScoped",
context.getTarget());
context.transform().add(ApplicationScoped.class).done();
}
}
}
});
AutoAddScopeBuildItem addScope(CustomScopeAnnotationsBuildItem customScopes) {
// Class with no built-in scope annotation but with @Startup method
return AutoAddScopeBuildItem.builder()
.defaultScope(BuiltinScope.APPLICATION)
.isAnnotatedWith(STARTUP_NAME)
.reason("Found classes containing @Startup annotation.")
.build();
}

@BuildStep
Expand Down