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
(cherry picked from commit f36724b)
  • Loading branch information
geoand authored and gsmet committed Sep 6, 2021
1 parent cc59223 commit 96d2742
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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 in specific jars.
*
* The {@code jarFile} property specifies the name of the jar file or a regular expression that can be used to
* match multiple jar files.
* Matching jar files using regular expressions should be done as a last resort.
*
* The {@code resourceName} property specifies the name of the resource file or a regular expression that can be used to
* match multiple resource files.
* For the match to work, the resources need to be part of the matched jar file(s) (see {@code jarFile}).
* Matching resource files using regular expressions should be done as a last resort.
*
* See https://github.com/oracle/graal/pull/3179 for more details.
*/
public final class ExcludeConfigBuildItem extends MultiBuildItem {

private final String jarFile;
private final String resourceName;

public ExcludeConfigBuildItem(String jarFile, String resourceName) {
this.jarFile = jarFile;
this.resourceName = resourceName;
}

public ExcludeConfigBuildItem(String jarFile) {
this(jarFile, "META-INF/native-image/native-image.properties");
}

public String getJarFile() {
return jarFile;
}

public String getResourceName() {
return resourceName;
}
}
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 @@ -700,6 +711,13 @@ public NativeImageInvokerInfo build() {
.collect(Collectors.joining(","));
nativeImageArgs.add("-H:AdditionalSecurityProviders=" + additionalSecurityProviders);
}

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

nativeImageArgs.add(nativeImageName);
Expand Down

0 comments on commit 96d2742

Please sign in to comment.