Repository: quarkusio/quarkus
Issue: List of AWT runtime initialized classes not observable for other extensions

### Describe the bug

In Quarkiverse CXF we are performing some special actions at build time based on whether SOAP service interfaces reference build time initiliazed classes. To do that, we observe `RuntimeInitializedClassBuildItem` and `RuntimeInitializedPackageBuildItem`. 

`java.awt.Image` is a prime example for passing binary content to WebServices, however our Processor, it is not able to find out that `quarkus-awt` is actually setting it for runtime init, because it does so via GraalVM Features.

I wonder whether `io.quarkus.awt.runtime.graal.AwtFeature` and `DarwinAwtFeature` could be transformed to a Quarkus BuildStep producing some `RuntimeInitializedPackageBuildItem` s?


Changed files:
extensions/awt/deployment/src/main/java/io/quarkus/awt/deployment/AwtProcessor.java
extensions/awt/runtime/src/main/java/io/quarkus/awt/runtime/graal/AwtFeature.java

diff --git a/extensions/awt/deployment/src/main/java/io/quarkus/awt/deployment/AwtProcessor.java b/extensions/awt/deployment/src/main/java/io/quarkus/awt/deployment/AwtProcessor.java
index 091b3084502..df7c1571466 100644
--- a/extensions/awt/deployment/src/main/java/io/quarkus/awt/deployment/AwtProcessor.java
+++ b/extensions/awt/deployment/src/main/java/io/quarkus/awt/deployment/AwtProcessor.java
@@ -2,7 +2,8 @@
 
 import static io.quarkus.deployment.builditem.nativeimage.UnsupportedOSBuildItem.Os.WINDOWS;
 
-import io.quarkus.awt.runtime.graal.AwtFeature;
+import java.util.stream.Stream;
+
 import io.quarkus.awt.runtime.graal.DarwinAwtFeature;
 import io.quarkus.deployment.Feature;
 import io.quarkus.deployment.annotations.BuildProducer;
@@ -13,6 +14,7 @@
 import io.quarkus.deployment.builditem.nativeimage.NativeImageResourcePatternsBuildItem;
 import io.quarkus.deployment.builditem.nativeimage.NativeMinimalJavaVersionBuildItem;
 import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedPackageBuildItem;
 import io.quarkus.deployment.builditem.nativeimage.UnsupportedOSBuildItem;
 import io.quarkus.deployment.pkg.steps.NativeBuild;
 import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild;
@@ -26,7 +28,6 @@ FeatureBuildItem feature() {
 
     @BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
     void nativeImageFeatures(BuildProducer<NativeImageFeatureBuildItem> nativeImageFeatures) {
-        nativeImageFeatures.produce(new NativeImageFeatureBuildItem(AwtFeature.class));
         nativeImageFeatures.produce(new NativeImageFeatureBuildItem(DarwinAwtFeature.class));
     }
 
@@ -197,4 +198,21 @@ JniRuntimeAccessBuildItem setupJava2DClasses() {
                 "sun.java2d.SunGraphics2D",
                 "sun.java2d.SurfaceData");
     }
+
+    @BuildStep
+    void runtimeInitializedClasses(BuildProducer<RuntimeInitializedPackageBuildItem> runtimeInitilizedPackages) {
+        /*
+         * Note that this initialization is not enough if user wants to deserialize actual images
+         * (e.g. from XML). AWT Extension must be loaded for decoding JDK supported image formats.
+         */
+        Stream.of("com.sun.imageio",
+                "java.awt",
+                "javax.imageio",
+                "sun.awt",
+                "sun.font",
+                "sun.java2d")
+                .map(RuntimeInitializedPackageBuildItem::new)
+                .forEach(runtimeInitilizedPackages::produce);
+    }
+
 }
diff --git a/extensions/awt/runtime/src/main/java/io/quarkus/awt/runtime/graal/AwtFeature.java b/extensions/awt/runtime/src/main/java/io/quarkus/awt/runtime/graal/AwtFeature.java
deleted file mode 100644
index 34b8606751d..00000000000
--- a/extensions/awt/runtime/src/main/java/io/quarkus/awt/runtime/graal/AwtFeature.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package io.quarkus.awt.runtime.graal;
-
-import org.graalvm.nativeimage.hosted.Feature;
-import org.graalvm.nativeimage.hosted.RuntimeClassInitialization;
-
-/**
- * Note that this initialization is not enough if user wants to deserialize actual images
- * (e.g. from XML). AWT Extension must be loaded for decoding JDK supported image formats.
- */
-public class AwtFeature implements Feature {
-    @Override
-    public void afterRegistration(AfterRegistrationAccess access) {
-        // Quarkus run time init for AWT
-        RuntimeClassInitialization.initializeAtRunTime(
-                "com.sun.imageio",
-                "java.awt",
-                "javax.imageio",
-                "sun.awt",
-                "sun.font",
-                "sun.java2d");
-    }
-}