|
13 | 13 | import jakarta.inject.Singleton; |
14 | 14 |
|
15 | 15 | import org.jboss.jandex.DotName; |
| 16 | +import org.jboss.jandex.Type; |
16 | 17 | import org.jboss.logging.Logger; |
17 | 18 |
|
18 | 19 | import io.javaoperatorsdk.operator.api.config.ConfigurationService; |
|
34 | 35 | import io.quarkus.deployment.annotations.Record; |
35 | 36 | import io.quarkus.deployment.builditem.*; |
36 | 37 | import io.quarkus.deployment.builditem.nativeimage.ForceNonWeakReflectiveClassBuildItem; |
37 | | -import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; |
| 38 | +import io.quarkus.deployment.builditem.nativeimage.ReflectiveHierarchyBuildItem; |
38 | 39 | import io.quarkus.deployment.metrics.MetricsCapabilityBuildItem; |
39 | 40 | import io.quarkus.gizmo.AssignableResultHandle; |
40 | 41 | import io.quarkus.gizmo.MethodCreator; |
@@ -180,10 +181,34 @@ AnnotationConfigurablesBuildItem gatherAnnotationConfigurables( |
180 | 181 | return new AnnotationConfigurablesBuildItem(configurableInfos); |
181 | 182 | } |
182 | 183 |
|
| 184 | + /** |
| 185 | + * Gathers the CustomResource implementations that are not part of the application index because they are part of an |
| 186 | + * external, reusable module for example. |
| 187 | + * |
| 188 | + * Note that this will be obsolete once <a href="https://github.com/quarkusio/quarkus/pull/38586">Quarkus #38586</a> is |
| 189 | + * usable |
| 190 | + * |
| 191 | + * @param combinedIndexBuildItem |
| 192 | + * @param applicationIndexBuildItem |
| 193 | + * @param reflectiveClassProducer |
| 194 | + */ |
| 195 | + @BuildStep |
| 196 | + void gatherOutOfAppCustomResourceImplementations(CombinedIndexBuildItem combinedIndexBuildItem, |
| 197 | + ApplicationIndexBuildItem applicationIndexBuildItem, |
| 198 | + BuildProducer<QOSDKReflectiveClassBuildItem> reflectiveClassProducer) { |
| 199 | + final var combinedIndex = combinedIndexBuildItem.getIndex(); |
| 200 | + final var appIndex = applicationIndexBuildItem.getIndex(); |
| 201 | + |
| 202 | + // only add the CRs found in the combined index that were not already in the application one since Quarkus should already handle these |
| 203 | + final var crsFromCombined = combinedIndex.getAllKnownSubclasses(Constants.CUSTOM_RESOURCE); |
| 204 | + crsFromCombined.removeAll(appIndex.getAllKnownSubclasses(Constants.CUSTOM_RESOURCE)); |
| 205 | + crsFromCombined.forEach(ci -> reflectiveClassProducer.produce(new QOSDKReflectiveClassBuildItem(ci.name().toString()))); |
| 206 | + } |
| 207 | + |
183 | 208 | @BuildStep |
184 | 209 | void registerClassesForReflection( |
185 | 210 | List<QOSDKReflectiveClassBuildItem> toRegister, |
186 | | - BuildProducer<ReflectiveClassBuildItem> reflectionClasses, |
| 211 | + BuildProducer<ReflectiveHierarchyBuildItem> reflectionClasses, |
187 | 212 | BuildProducer<ForceNonWeakReflectiveClassBuildItem> forcedReflectionClasses) { |
188 | 213 | final var toRegisterSet = toRegister.stream() |
189 | 214 | .flatMap(QOSDKReflectiveClassBuildItem::classNamesToRegisterForReflectionStream) |
@@ -236,11 +261,13 @@ void initializeRuntimeNamespacesFromBuildTimeValues( |
236 | 261 |
|
237 | 262 | } |
238 | 263 |
|
239 | | - private void registerAssociatedClassesForReflection(BuildProducer<ReflectiveClassBuildItem> reflectionClasses, |
| 264 | + private void registerAssociatedClassesForReflection(BuildProducer<ReflectiveHierarchyBuildItem> reflectionClasses, |
240 | 265 | BuildProducer<ForceNonWeakReflectiveClassBuildItem> forcedReflectionClasses, |
241 | 266 | Set<String> classNamesToRegister) { |
| 267 | + // todo: use builder API when/if https://github.com/quarkusio/quarkus/pull/38679 is available |
242 | 268 | classNamesToRegister.forEach(cn -> { |
243 | | - reflectionClasses.produce(ReflectiveClassBuildItem.builder(cn).methods().fields().build()); |
| 269 | + reflectionClasses.produce(new ReflectiveHierarchyBuildItem.Builder() |
| 270 | + .type(Type.create(DotName.createSimple(cn), Type.Kind.CLASS)).build()); |
244 | 271 | forcedReflectionClasses.produce( |
245 | 272 | new ForceNonWeakReflectiveClassBuildItem(cn)); |
246 | 273 | log.infov("Registered ''{0}'' for reflection", cn); |
|
0 commit comments