25
25
import io .quarkus .deployment .builditem .FeatureBuildItem ;
26
26
import io .quarkus .deployment .builditem .IndexDependencyBuildItem ;
27
27
import io .quarkus .deployment .builditem .nativeimage .ReflectiveClassBuildItem ;
28
+ import io .quarkus .deployment .util .JandexUtil ;
28
29
import java .util .List ;
29
30
import java .util .Optional ;
30
31
import java .util .function .Function ;
36
37
import org .jboss .jandex .AnnotationValue ;
37
38
import org .jboss .jandex .ClassInfo ;
38
39
import org .jboss .jandex .DotName ;
39
- import org .jboss .jandex .Type ;
40
+ import org .jboss .jandex .IndexView ;
40
41
import org .jboss .logging .Logger ;
41
42
42
43
class QuarkusExtensionProcessor {
@@ -49,10 +50,6 @@ class QuarkusExtensionProcessor {
49
50
private static final DotName CONTROLLER = DotName .createSimple (Controller .class .getName ());
50
51
private static final DotName APPLICATION_SCOPED =
51
52
DotName .createSimple (ApplicationScoped .class .getName ());
52
- private static final Supplier <String > EXCEPTION_SUPPLIER =
53
- () -> {
54
- throw new IllegalArgumentException ();
55
- };
56
53
57
54
private ExternalConfiguration externalConfiguration ;
58
55
@@ -78,7 +75,7 @@ void createConfigurationServiceAndOperator(
78
75
79
76
final List <ControllerConfiguration > controllerConfigs =
80
77
resourceControllers .stream ()
81
- .map (ci -> createControllerConfiguration (ci , additionalBeans , reflectionClasses ))
78
+ .map (ci -> createControllerConfiguration (ci , additionalBeans , reflectionClasses , index ))
82
79
.collect (Collectors .toList ());
83
80
84
81
final var version = Utils .loadFromProperties ();
@@ -101,17 +98,14 @@ void createConfigurationServiceAndOperator(
101
98
private ControllerConfiguration createControllerConfiguration (
102
99
ClassInfo info ,
103
100
BuildProducer <AdditionalBeanBuildItem > additionalBeans ,
104
- BuildProducer <ReflectiveClassBuildItem > reflectionClasses ) {
101
+ BuildProducer <ReflectiveClassBuildItem > reflectionClasses ,
102
+ IndexView index ) {
105
103
// 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 ();
115
109
116
110
// create ResourceController bean
117
111
final var resourceControllerClassName = info .name ().toString ();
@@ -137,7 +131,11 @@ private ControllerConfiguration createControllerConfiguration(
137
131
final var crdName = CustomResource .getCRDName (crClass );
138
132
139
133
// 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 ());
141
139
142
140
// retrieve the Controller annotation if it exists
143
141
final var controllerAnnotation = info .classAnnotation (CONTROLLER );
@@ -186,6 +184,17 @@ private ControllerConfiguration createControllerConfiguration(
186
184
return configuration ;
187
185
}
188
186
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
+
189
198
private RetryConfiguration retryConfiguration (ExternalControllerConfiguration extConfig ) {
190
199
return extConfig == null ? null : RetryConfigurationResolver .resolve (extConfig .retry );
191
200
}
0 commit comments