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

Remove jdk.internal.io.JdkConsoleProvider service providers from ServiceCatalog in a similar way to GraalVM's ServiceLoaderFeature which Quarkus disables by default #44650

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,11 @@ public NativeImageInvokerInfo build() {
for (NativeImageFeatureBuildItem nativeImageFeature : nativeImageFeatures) {
featuresList.add(nativeImageFeature.getQualifiedName());
}
if (!nativeConfig.autoServiceLoaderRegistration()) {
featuresList.add("io.quarkus.runtime.graal.SkipConsoleServiceProvidersFeature");
// required by the feature
nativeImageArgs.add("-J--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk=ALL-UNNAMED");
}
nativeImageArgs.add("--features=" + String.join(",", featuresList));

if (nativeConfig.debug().enabled()) {
Expand Down
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);
}
}

}
Loading