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

Added @Startup to DiameterService #46

Merged
merged 1 commit into from
Sep 23, 2024
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
Expand Up @@ -5,6 +5,7 @@
import io.quarkiverse.diameter.runtime.DiameterRecorder;
import io.quarkiverse.diameter.runtime.DiameterRunTimeConfig;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.AnnotationsTransformerBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.arc.processor.DotNames;
import io.quarkus.deployment.annotations.BuildProducer;
Expand All @@ -16,11 +17,13 @@
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.runtime.Startup;
import io.quarkus.tls.TlsRegistryBuildItem;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Default;
import jakarta.interceptor.Interceptor;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTransformation;
import org.jboss.jandex.DotName;
import org.jdiameter.api.Configuration;
import org.jdiameter.api.Stack;
Expand Down Expand Up @@ -78,7 +81,7 @@ NativeImageResourceBuildItem nativeImageResourceBuildItem()
return new NativeImageResourceBuildItem("META-INF/jdiameter-client.xsd",
"META-INF/jdiameter-server.xsd",
"META-INF/version.properties",
"META-INF/dictionary.xml");
"dictionary.xml");
}

@BuildStep
Expand Down Expand Up @@ -200,20 +203,26 @@ public ServiceStartBuildItem generateDiameterConfiguration(DiameterRecorder reco
}

@BuildStep
public void declareDiameterServicesAsBean(CombinedIndexBuildItem index, BuildProducer<AdditionalBeanBuildItem> additionalBeans)
public void declareDiameterServicesAsBean(CombinedIndexBuildItem index,
BuildProducer<AdditionalBeanBuildItem> additionalBeans,
BuildProducer<AnnotationsTransformerBuildItem> transformer)
{
List<String> diameterServices = index.getIndex()
.getKnownClasses()
.stream()
.filter(ci -> ci.hasAnnotation(DiameterService.class) && !ci.hasAnnotation(Interceptor.class))
.map(ci -> ci.name().toString())
.collect(Collectors.toList());
.stream()
.filter(ci -> ci.hasAnnotation(DiameterService.class) && !ci.hasAnnotation(Interceptor.class))
.map(ci -> ci.name().toString())
.collect(Collectors.toList());

additionalBeans.produce(new AdditionalBeanBuildItem.Builder()
.addBeanClasses(diameterServices)
.setUnremovable()
.setDefaultScope(DotNames.SINGLETON)
.build());

transformer.produce( new AnnotationsTransformerBuildItem(AnnotationTransformation.forClasses()
.whenClass(c -> diameterServices.contains(c.name().toString()))
.transform(c -> c.add(AnnotationInstance.builder(Startup.class).build()))));
}

private static <T> SyntheticBeanBuildItem.ExtendedBeanConfigurator createSyntheticBean(String clientName, Class<T> type, DotName exposedType, boolean isDefaultConfig)
Expand Down