0

what i am trying to do is to build an Quarkus extention that will change some annotations at quarkus application

so I used AnnotationTransformerBuildItem.

package com.tawfeek.greeting.extension.deployment;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.AnnotationsTransformerBuildItem;
import io.quarkus.arc.processor.AnnotationsTransformer;
import io.quarkus.builder.item.MultiBuildItem;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.recording.RecorderContext;
import io.quarkus.deployment.steps.ClassTransformingBuildStep;

import io.quarkus.runtime.annotations.Recorder;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.DotName;
import org.jboss.jandex.MethodInfo;

import java.util.function.Predicate;

import static io.quarkus.arc.ComponentsProvider.LOG;


class GreetingExtensionProcessor {

    private static final String FEATURE = "greeting-extension";

    @BuildStep
    FeatureBuildItem feature() {
        return new FeatureBuildItem(FEATURE);
    }



    @BuildStep
    AnnotationsTransformerBuildItem transform() {

        return new AnnotationsTransformerBuildItem(new AnnotationsTransformer() {
            @Override
            public boolean appliesTo(AnnotationTarget.Kind kind) {
                return kind == AnnotationTarget.Kind.METHOD;
            }
            @Override
            public void transform(TransformationContext context) {
                MethodInfo methodInfo = context.getTarget().asMethod();
                if (methodInfo.hasAnnotation("jakarta.ws.rs.GET")) {
                    // Remove the existing @GET annotation
                    context.transform()
                            .remove(annotationInstance -> annotationInstance.name()
                                    .equals(DotName.createSimple("jakarta.ws.rs.GET"))).done();
                    // Add the @POST annotation
                    context.transform().add(DotName.createSimple("jakarta.ws.rs.POST")).done();
                    System.out.println("method "+methodInfo.name()+" is change from get to post");
                }
            }
        });
    }



}

the problem is that when add the code to the app and run it. the result is it print that it change the method method hello is change from get to post put actually it still using get not post when testing using postman

I expect there is a configuration for the quarkus extension to affect the beans Methods and it then work correctly

  • There are two classes in Quarkus named `AnnotationsTransformerBuildItem`. Make sure you don't use the one from ArC and do use the one from RESTEasy Reactive. – Ladicek Aug 10 '23 at 19:52
  • can you give me the doc @Ladicek or the full name of the class to import after adding rest easy reactive to the project because I Can't reach on the internet – tawfeek shalash Aug 11 '23 at 16:01

0 Answers0