package io.quarkus.runtime;

import java.io.InputStream;
import java.lang.reflect.Method;

import io.quarkus.runtime.util.ClassPathUtils;

/**
 * Helper method that is invoked from generated bytecode during image processing
 */
public class ResourceHelper {

    public static void registerResources(String resource) {
        try {
            Class<?> resourcesClass = Class.forName("com.oracle.svm.core.jdk.Resources");
            Method register = resourcesClass.getDeclaredMethod("registerResource", String.class, InputStream.class);
            ClassPathUtils.consumeAsStreams(ResourceHelper.class.getClassLoader(), resource, in -> {
                try {
                    register.invoke(null, resource, in);
                } catch (Exception e) {
                    throw new RuntimeException("Failed to register resource " + resource, e);
                }
            });
        } catch (Exception e) {
            throw new RuntimeException("Failed to load resource " + resource, e);
        }
    }

}

@@ -84,16 +84,50 @@
 ethod;%0A%0A
+import org.graalvm.home.Version;%0A%0A
 import i
@@ -165,16 +165,16 @@
 hUtils;%0A
-
 %0A/**%0A * 
@@ -346,38 +346,1053 @@
 urce) %7B%0A        
-try %7B%0A
+Version currentGraalVmVersion = Version.getCurrent();%0A        if (currentGraalVmVersion.compareTo(22, 3) %3E= 0) %7B%0A            // Use the public API RuntimeResourceAccess with GraalVM %3E= 22.3%0A            // TODO: Remove reflective access once support for GraalVM %3C 22.3 gets dropped and directly invoke%0A            // RuntimeResourceAccess.addResource(ClassLoader.getSystemClassLoader().getUnnamedModule(), resource);%0A            try %7B%0A                Class%3C?%3E runtimeResourceSupportClass = Class.forName(%22org.graalvm.nativeimage.hosted.RuntimeResourceAccess%22);%0A                Method addResource = runtimeResourceSupportClass.getDeclaredMethod(%22addResource%22, Module.class, String.class);%0A                addResource.invoke(null, ClassLoader.getSystemClassLoader().getUnnamedModule(), resource);%0A            %7D catch (Exception e) %7B%0A                throw new RuntimeException(%22Failed to load resource %22 + resource, e);%0A            %7D%0A        %7D else %7B%0A            // Use internal API with GraalVM %3C 22.3%0A            try %7B%0A    
             Clas
@@ -1461,24 +1461,28 @@
 esources%22);%0A
+    
             
@@ -1594,24 +1594,28 @@
             
+ 
+   
 ClassPathUti
@@ -1699,32 +1699,36 @@
                 
+    
 try %7B%0A          
@@ -1737,16 +1737,20 @@
         
+ 
+   
 register
@@ -1786,32 +1786,36 @@
                 
+    
 %7D catch (Excepti
@@ -1834,32 +1834,36 @@
                 
+ 
+   
 throw new Runtim
@@ -1928,34 +1928,42 @@
                 
-%7D%0A
+    %7D%0A    
             %7D);%0A
@@ -1962,16 +1962,20 @@
     %7D);%0A
+    
         
@@ -2002,32 +2002,36 @@
 ) %7B%0A            
+  
+  
 throw new Runtim
@@ -2076,32 +2076,46 @@
 + resource, e);%0A
+            %7D%0A
         %7D%0A    %7D%0A

Stop depending on com.oracle.svm.core.jdk.Resources#registerResource