Replace CDI Portable Extension in Quarkiverse Plugin

76 views
Skip to first unread message

Melloware

unread,
Aug 27, 2022, 2:38:35 PM8/27/22
to Quarkus Development mailing list
Hello!  I am adding the Quarkus OmniFaces support however it has an annotation called @Eager which will eagerly load a bean on Startup like...

@Eager
@ApplicationScoped
@Named
public class ShowcaseCacheProvider {

However as you know CDI portable extensions are not supported so I need to rewrite this extension to be "Quarkified" in my plugin.  


Any hints or example code to look at to basically do this same functionality in the Quarkus plugin would be great!

Thanks,
   Mello

George Gastaldi

unread,
Aug 27, 2022, 2:44:05 PM8/27/22
to mellow...@gmail.com, Quarkus Development mailing list

--
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/quarkus-dev/83c6f3d9-e6d6-4301-9e14-7e15754577f6n%40googlegroups.com.

Melloware

unread,
Aug 27, 2022, 2:48:47 PM8/27/22
to George Gastaldi, Quarkus Development mailing list

Excellent I think I can just find a way to map all those Eager beans to the Quarkus Startup type!

George Gastaldi

unread,
Aug 27, 2022, 2:55:12 PM8/27/22
to Melloware, Quarkus Development mailing list

Melloware

unread,
Aug 27, 2022, 3:44:21 PM8/27/22
to George Gastaldi, Quarkus Development mailing list

You are my hero that did the trick!

@BuildStep
AnnotationsTransformerBuildItem transformBeanScope(BeanArchiveIndexBuildItem index,
        CustomScopeAnnotationsBuildItem scopes) {
    return new AnnotationsTransformerBuildItem(new AnnotationsTransformer() {
        @Override
        public boolean appliesTo(AnnotationTarget.Kind kind) {
            return kind == org.jboss.jandex.AnnotationTarget.Kind.CLASS;
        }

        @Override
        public void transform(AnnotationsTransformer.TransformationContext ctx) {
            if (ctx.isClass()) {
                ClassInfo clazz = ctx.getTarget().asClass();
                Map<DotName, List<AnnotationInstance>> annotations = clazz.annotationsMap();
                if (annotations.containsKey(OMNIFACES_STARTUP)) {
                    LOGGER.infof("OmniFaces found @%s annotations on a class %s - adding @ApplicationScoped",
                            OMNIFACES_STARTUP, ctx.getTarget());
                    ctx.transform().add(ApplicationScoped.class).done();
                }
                if (annotations.containsKey(OMNIFACES_EAGER) || annotations.containsKey(OMNIFACES_STARTUP)) {
                    LOGGER.infof("OmniFaces found @Eager annotations on a class %s - adding @io.quarkus.runtime.Startup",
                            ctx.getTarget());
                    ctx.transform().add(io.quarkus.runtime.Startup.class).done();
                }
            }
        }
    });
}

On 8/27/2022 2:54 PM, George Gastaldi wrote:

Reply all
Reply to author
Forward
0 new messages