Skip to content

Commit

Permalink
Merge pull request #11708 from manovotn/issue11700
Browse files Browse the repository at this point in the history
Turn StartupBuildSteps.annotationTransformer() into an AutoAddScopeBuildItem
  • Loading branch information
gsmet authored Aug 31, 2020
2 parents 9cae703 + 0c1d7e3 commit 02c274c
Showing 1 changed file with 7 additions and 23 deletions.
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

0 comments on commit 02c274c

Please sign in to comment.