Skip to content

Commit

Permalink
Add the ability for extensions to exclude GraalVM config from jars
Browse files Browse the repository at this point in the history
Resolves: quarkusio#17482
  • Loading branch information
geoand committed Aug 25, 2021
1 parent 9fc6d6d commit 47716ed
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.quarkus.deployment.builditem.nativeimage;

import io.quarkus.builder.item.MultiBuildItem;

/**
* A build item that allows extension to configure the native-image compiler to effectively
* ignore certain configuration files by specifying a value that determines the name of the excluded
* configuration files in specific jars.
* See https://github.com/oracle/graal/pull/3179 for more details.
*/
public final class ExcludeConfigBuildItem extends MultiBuildItem {

private final String value;

public ExcludeConfigBuildItem(String value) {
this.value = value;
}

public String getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.quarkus.bootstrap.model.AppDependency;
import io.quarkus.bootstrap.util.IoUtils;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.nativeimage.ExcludeConfigBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageSecurityProviderBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageSystemPropertyBuildItem;
import io.quarkus.deployment.pkg.NativeConfig;
Expand Down Expand Up @@ -81,7 +82,8 @@ ArtifactResultBuildItem nativeSourcesResult(NativeConfig nativeConfig,
NativeImageSourceJarBuildItem nativeImageSourceJarBuildItem,
OutputTargetBuildItem outputTargetBuildItem,
PackageConfig packageConfig,
List<NativeImageSystemPropertyBuildItem> nativeImageProperties) {
List<NativeImageSystemPropertyBuildItem> nativeImageProperties,
List<ExcludeConfigBuildItem> excludeConfigs) {

Path outputDir;
try {
Expand All @@ -100,6 +102,7 @@ ArtifactResultBuildItem nativeSourcesResult(NativeConfig nativeConfig,
.setNativeConfig(nativeConfig)
.setOutputTargetBuildItem(outputTargetBuildItem)
.setNativeImageProperties(nativeImageProperties)
.setExcludeConfigs(excludeConfigs)
.setOutputDir(outputDir)
.setRunnerJarName(runnerJar.getFileName().toString())
// the path to native-image is not known now, it is only known at the time the native-sources will be consumed
Expand Down Expand Up @@ -130,6 +133,7 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, NativeImageSourceJa
PackageConfig packageConfig,
CurateOutcomeBuildItem curateOutcomeBuildItem,
List<NativeImageSystemPropertyBuildItem> nativeImageProperties,
List<ExcludeConfigBuildItem> excludeConfigs,
List<NativeImageSecurityProviderBuildItem> nativeImageSecurityProviders,
Optional<ProcessInheritIODisabled> processInheritIODisabled) {
if (nativeConfig.debug.enabled) {
Expand Down Expand Up @@ -187,6 +191,7 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, NativeImageSourceJa
.setNativeConfig(nativeConfig)
.setOutputTargetBuildItem(outputTargetBuildItem)
.setNativeImageProperties(nativeImageProperties)
.setExcludeConfigs(excludeConfigs)
.setNativeImageSecurityProviders(nativeImageSecurityProviders)
.setOutputDir(outputDir)
.setRunnerJarName(runnerJarName)
Expand Down Expand Up @@ -477,6 +482,7 @@ static class Builder {
private NativeConfig nativeConfig;
private OutputTargetBuildItem outputTargetBuildItem;
private List<NativeImageSystemPropertyBuildItem> nativeImageProperties;
private List<ExcludeConfigBuildItem> excludeConfigs;
private List<NativeImageSecurityProviderBuildItem> nativeImageSecurityProviders;
private Path outputDir;
private String runnerJarName;
Expand All @@ -500,6 +506,11 @@ public Builder setNativeImageProperties(List<NativeImageSystemPropertyBuildItem>
return this;
}

public Builder setExcludeConfigs(List<ExcludeConfigBuildItem> excludeConfigs) {
this.excludeConfigs = excludeConfigs;
return this;
}

public Builder setNativeImageSecurityProviders(
List<NativeImageSecurityProviderBuildItem> nativeImageSecurityProviders) {
this.nativeImageSecurityProviders = nativeImageSecurityProviders;
Expand Down Expand Up @@ -694,12 +705,18 @@ public NativeImageInvokerInfo build() {
nativeImageArgs.add("-H:-ParseOnce");

// AdditionalSecurityProviders
if (nativeImageSecurityProviders != null && !nativeImageSecurityProviders.isEmpty()) {
if (!nativeImageSecurityProviders.isEmpty()) {
String additionalSecurityProviders = nativeImageSecurityProviders.stream()
.map(p -> p.getSecurityProvider())
.map(NativeImageSecurityProviderBuildItem::getSecurityProvider)
.collect(Collectors.joining(","));
nativeImageArgs.add("-H:AdditionalSecurityProviders=" + additionalSecurityProviders);
}

// Add --exclude-config options
for (ExcludeConfigBuildItem excludeConfig : excludeConfigs) {
nativeImageArgs.add("--exclude-config");
nativeImageArgs.add(excludeConfig.getValue());
}
}

nativeImageArgs.add(nativeImageName);
Expand Down

0 comments on commit 47716ed

Please sign in to comment.