Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add graalvm-reachability-metadata for minio-java #1446

Open
dpalmmna opened this issue Apr 27, 2023 · 2 comments
Open

Add graalvm-reachability-metadata for minio-java #1446

dpalmmna opened this issue Apr 27, 2023 · 2 comments

Comments

@dpalmmna
Copy link

To use minio in a graalvm native application the reachability metadata could be added to https://github.com/oracle/graalvm-reachability-metadata for all users to use in native mode for optimised applications in cloud microservices.

@balamurugana
Copy link
Member

Feel free to send a PR

@rcomblen
Copy link

For those landing here and using Spring Boot, here is a quick solution (working with Spring Boot 3.3.3), that allows me to put and get objects. Didn't test further features.

Add this class (@Slf4j comes from Lombok):

@Slf4j
public class MinioRuntimeHintsRegistrar implements RuntimeHintsRegistrar {


    List<String> packagesToScan = List.of(
            "io.minio",
            "org.simpleframework.xml.core"
    );

    private final BindingReflectionHintsRegistrar bindingReflectionHintsRegistrar = new BindingReflectionHintsRegistrar();


    @Override
    public void registerHints(RuntimeHints hint, ClassLoader classLoader) {
        for (String packageName : packagesToScan) {
            registerPackage(hint, packageName);
        }
    }

    private void registerPackage(RuntimeHints hint, String packageName) {
        Reflections reflections = new Reflections(packageName, new SubTypesScanner(false));
        Set<Class<?>> allTypes = reflections.getSubTypesOf(Object.class);
        log.info("Found " + allTypes.size() + " classes for package " + packageName);
        allTypes.stream().map(it -> it.getName()).sorted().forEach(it -> log.info("Registering " + it));
        allTypes.forEach(type -> {
            // Reusing behavior of @RegisterReflectionForBinding annotation
            bindingReflectionHintsRegistrar.registerReflectionHints(hint.reflection(), type);
        });
        reflections.getSubTypesOf(Serializable.class).stream().filter(it -> it.getCanonicalName() != null).forEach(type -> hint.serialization().registerType(type));
    }
}

And register it on a configuration class using

@ImportRuntimeHints(MinioRuntimeHintsRegistrar.class)

You'll need this dependency on your classpath:

<dependency>
  <groupId>org.reflections</groupId>
  <artifactId>reflections</artifactId>
  <version>0.10.2</version>
</dependency>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants