Skip to content

Commit

Permalink
♻️ Refactor PluginsScanner to support native image build
Browse files Browse the repository at this point in the history
  • Loading branch information
ujibang committed Feb 13, 2024
1 parent 4fcdffa commit def5111
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public static void init(URL[] jars) {
}
}

public static boolean isInitialized() {
return SINGLETON != null;
}

private final URLClassLoader pluginsClassLoader;

private PluginsClassloader(URL[] jars) throws IOException {
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/org/restheart/plugins/PluginsScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public class PluginsScanner {
RuntimeClassGraph rtcg = null;

if (NativeImageBuildTimeChecker.isBuildTime()) {
if (!PluginsClassloader.isInitialized()) {
PluginsClassloader.init(new URL[0]);
}
classGraph = new ClassGraph().disableModuleScanning() // added for GraalVM
.disableDirScanning() // added for GraalVM
.disableNestedJarScanning() // added for GraalVM
Expand Down
4 changes: 3 additions & 1 deletion core/src/test/java/org/restheart/plugins/PluginsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ public void validProviders() {
}

private static MockedStatic<PluginsScanner> mockPluginsScanner(List<PluginDescriptor> providerDescriptors) {
PluginsClassloader.init(new URL[0]);
if (!PluginsClassloader.isInitialized()) {
PluginsClassloader.init(new URL[0]);
}
var scanner = mockStatic(PluginsScanner.class);
scanner.when(PluginsScanner::providers).thenReturn(providerDescriptors);
return scanner;
Expand Down

0 comments on commit def5111

Please sign in to comment.