-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove console-related service providers from ServiceCatalog
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
core/runtime/src/main/java/io/quarkus/runtime/graal/SkipConsoleServiceProvidersFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.quarkus.runtime.graal; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.graalvm.nativeimage.hosted.Feature; | ||
|
||
/** | ||
* Removes {@code jdk.internal.io.JdkConsoleProvider} service providers from the {@code ServiceCatalog} in a similar way to | ||
* GraalVM's {@code ServiceLoaderFeature} which Quarkus disables by default. | ||
*/ | ||
public class SkipConsoleServiceProvidersFeature implements Feature { | ||
static final HashMap<String, Set<String>> omittedServiceProviders; | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Skip unsupported console service providers when quarkus.native.auto-service-loader-registration is false"; | ||
} | ||
|
||
static { | ||
omittedServiceProviders = new HashMap<>(1); | ||
omittedServiceProviders.put("jdk.internal.io.JdkConsoleProvider", | ||
new HashSet<>(Arrays.asList("jdk.jshell.execution.impl.ConsoleImpl$ConsoleProviderImpl", | ||
"jdk.internal.org.jline.JdkConsoleProviderImpl"))); | ||
} | ||
|
||
@Override | ||
public void beforeAnalysis(BeforeAnalysisAccess access) { | ||
Class<?> serviceCatalogSupport; | ||
Method singleton; | ||
Method removeServices; | ||
try { | ||
serviceCatalogSupport = Class.forName("com.oracle.svm.core.jdk.ServiceCatalogSupport"); | ||
singleton = serviceCatalogSupport.getDeclaredMethod("singleton"); | ||
removeServices = serviceCatalogSupport.getDeclaredMethod("removeServicesFromServicesCatalog", String.class, | ||
Set.class); | ||
var result = singleton.invoke(null); | ||
omittedServiceProviders.forEach((key, value) -> { | ||
try { | ||
removeServices.invoke(result, key, value); | ||
} catch (IllegalAccessException | InvocationTargetException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
} |