2525import io .quarkus .deployment .builditem .FeatureBuildItem ;
2626import io .quarkus .deployment .builditem .IndexDependencyBuildItem ;
2727import io .quarkus .deployment .builditem .nativeimage .ReflectiveClassBuildItem ;
28+ import io .quarkus .deployment .util .JandexUtil ;
2829import java .util .List ;
2930import java .util .Optional ;
3031import java .util .function .Function ;
3637import org .jboss .jandex .AnnotationValue ;
3738import org .jboss .jandex .ClassInfo ;
3839import org .jboss .jandex .DotName ;
39- import org .jboss .jandex .Type ;
40+ import org .jboss .jandex .IndexView ;
4041import org .jboss .logging .Logger ;
4142
4243class QuarkusExtensionProcessor {
@@ -49,10 +50,6 @@ class QuarkusExtensionProcessor {
4950 private static final DotName CONTROLLER = DotName .createSimple (Controller .class .getName ());
5051 private static final DotName APPLICATION_SCOPED =
5152 DotName .createSimple (ApplicationScoped .class .getName ());
52- private static final Supplier <String > EXCEPTION_SUPPLIER =
53- () -> {
54- throw new IllegalArgumentException ();
55- };
5653
5754 private ExternalConfiguration externalConfiguration ;
5855
@@ -78,7 +75,7 @@ void createConfigurationServiceAndOperator(
7875
7976 final List <ControllerConfiguration > controllerConfigs =
8077 resourceControllers .stream ()
81- .map (ci -> createControllerConfiguration (ci , additionalBeans , reflectionClasses ))
78+ .map (ci -> createControllerConfiguration (ci , additionalBeans , reflectionClasses , index ))
8279 .collect (Collectors .toList ());
8380
8481 final var version = Utils .loadFromProperties ();
@@ -101,17 +98,14 @@ void createConfigurationServiceAndOperator(
10198 private ControllerConfiguration createControllerConfiguration (
10299 ClassInfo info ,
103100 BuildProducer <AdditionalBeanBuildItem > additionalBeans ,
104- BuildProducer <ReflectiveClassBuildItem > reflectionClasses ) {
101+ BuildProducer <ReflectiveClassBuildItem > reflectionClasses ,
102+ IndexView index ) {
105103 // first retrieve the custom resource class
106- final var rcInterface =
107- info .interfaceTypes ().stream ()
108- .filter (t -> t .name ().equals (RESOURCE_CONTROLLER ))
109- .findFirst ()
110- .map (Type ::asParameterizedType )
111- // shouldn't happen since we're only dealing with ResourceController implementors
112- // already
113- .orElseThrow ();
114- final var crType = rcInterface .arguments ().get (0 ).name ().toString ();
104+ final var crType =
105+ JandexUtil .resolveTypeParameters (info .name (), RESOURCE_CONTROLLER , index )
106+ .get (0 )
107+ .name ()
108+ .toString ();
115109
116110 // create ResourceController bean
117111 final var resourceControllerClassName = info .name ().toString ();
@@ -137,7 +131,11 @@ private ControllerConfiguration createControllerConfiguration(
137131 final var crdName = CustomResource .getCRDName (crClass );
138132
139133 // register CR class for introspection
140- reflectionClasses .produce (new ReflectiveClassBuildItem (true , true , crClass ));
134+ reflectionClasses .produce (new ReflectiveClassBuildItem (true , true , crType ));
135+
136+ // register spec and status for introspection
137+ registerForReflection (reflectionClasses , cr .getSpec ());
138+ registerForReflection (reflectionClasses , cr .getStatus ());
141139
142140 // retrieve the Controller annotation if it exists
143141 final var controllerAnnotation = info .classAnnotation (CONTROLLER );
@@ -186,6 +184,17 @@ private ControllerConfiguration createControllerConfiguration(
186184 return configuration ;
187185 }
188186
187+ private void registerForReflection (
188+ BuildProducer <ReflectiveClassBuildItem > reflectionClasses , Object specOrStatus ) {
189+ Optional .ofNullable (specOrStatus )
190+ .map (s -> specOrStatus .getClass ().getCanonicalName ())
191+ .ifPresent (
192+ cn -> {
193+ reflectionClasses .produce (new ReflectiveClassBuildItem (true , true , cn ));
194+ System .out .println ("Registered " + cn );
195+ });
196+ }
197+
189198 private RetryConfiguration retryConfiguration (ExternalControllerConfiguration extConfig ) {
190199 return extConfig == null ? null : RetryConfigurationResolver .resolve (extConfig .retry );
191200 }
0 commit comments