Skip to content

Commit 8fcddbf

Browse files
Merge branch 'master' into fix-path-whitespaces-args
2 parents 5a86516 + 2c8c2a7 commit 8fcddbf

File tree

15 files changed

+177
-240
lines changed

15 files changed

+177
-240
lines changed

common/junit-platform-native/src/main/java/org/graalvm/junit/platform/config/platform/PlatformConfigProvider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ public void onLoad(NativeImageConfiguration config) {
6060
"org.junit.platform.engine.UniqueIdFormat",
6161
"org.junit.platform.commons.util.ReflectionUtils",
6262
// https://github.com/graalvm/native-build-tools/issues/300
63-
"org.junit.platform.reporting.open.xml.OpenTestReportGeneratingListener"
63+
"org.junit.platform.reporting.open.xml.OpenTestReportGeneratingListener",
64+
// https://github.com/graalvm/native-build-tools/issues/602
65+
"org.junit.platform.commons.util.LruCache"
6466
);
6567

6668
if (getMajorJDKVersion() >= 21) {

common/utils/src/main/java/org/graalvm/buildtools/agent/AgentConfiguration.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,21 @@
4040
*/
4141
package org.graalvm.buildtools.agent;
4242

43+
import java.io.File;
44+
import java.io.IOException;
45+
import java.io.InputStream;
4346
import java.io.Serializable;
47+
import java.nio.file.CopyOption;
48+
import java.nio.file.Files;
49+
import java.nio.file.Path;
50+
import java.nio.file.StandardCopyOption;
4451
import java.util.ArrayList;
4552
import java.util.Collection;
4653
import java.util.List;
4754

4855
public class AgentConfiguration implements Serializable {
4956

57+
private static final String DEFAULT_ACCESS_FILTER_FILE = "/access-filter.json";
5058
private final Collection<String> callerFilterFiles;
5159
private final Collection<String> accessFilterFiles;
5260
private final Boolean builtinCallerFilter;
@@ -88,6 +96,7 @@ public AgentConfiguration(Collection<String> callerFilterFiles,
8896
}
8997

9098
public List<String> getAgentCommandLine() {
99+
addDefaultAccessFilter();
91100
List<String> cmdLine = new ArrayList<>(agentMode.getAgentCommandLine());
92101
appendOptionToValues("caller-filter-file=", callerFilterFiles, cmdLine);
93102
appendOptionToValues("access-filter-file=", accessFilterFiles, cmdLine);
@@ -127,4 +136,34 @@ private void addToCmd(String option, Boolean value, List<String> cmdLine) {
127136
}
128137
}
129138

139+
private void addDefaultAccessFilter() {
140+
if (accessFilterFiles == null) {
141+
// this could only happen if we instantiated disabled agent configuration
142+
return;
143+
}
144+
145+
String tempDir = System.getProperty("java.io.tmpdir");
146+
Path agentDir = Path.of(tempDir).resolve("agent-config");
147+
Path accessFilterFile = agentDir.resolve("access-filter.json");
148+
if (Files.exists(accessFilterFile)) {
149+
accessFilterFiles.add(accessFilterFile.toString());
150+
return;
151+
}
152+
153+
try(InputStream accessFilter = AgentConfiguration.class.getResourceAsStream(DEFAULT_ACCESS_FILTER_FILE)) {
154+
if (accessFilter != null) {
155+
if (!Files.exists(agentDir)) {
156+
Files.createDirectory(agentDir);
157+
}
158+
159+
Files.copy(accessFilter, accessFilterFile, StandardCopyOption.REPLACE_EXISTING);
160+
accessFilterFiles.add(accessFilterFile.toString());
161+
} else {
162+
throw new IOException("Cannot find access-filter.json on default location: " + DEFAULT_ACCESS_FILTER_FILE);
163+
}
164+
} catch (IOException e) {
165+
throw new RuntimeException("Cannot add default access-filter.json" ,e);
166+
}
167+
}
168+
130169
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"rules": [
3+
{
4+
"includeClasses": "**"
5+
},
6+
{
7+
"excludeClasses": "org.gradle.**"
8+
},
9+
{
10+
"excludeClasses": "org.junit.**"
11+
}
12+
]
13+
}

docs/src/docs/asciidoc/index.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ If you are using alternative build systems, see <<alternative-build-systems.adoc
2222
=== Release 0.10.3
2323

2424
- Remove usage of macro from merger tool initialization and throw better error if executable does not exist
25+
- Add support for the new reachability-metadata.json config file
26+
- Remove custom post-processing task for filtering config files entries and use access-filter.json instead
2527

2628
==== Gradle plugin
2729

docs/src/docs/asciidoc/maven-plugin.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ Build Configuration]. It is also possible to customize the plugin within a
173173
<useArgFile>true</useArgFile>
174174
----
175175
`<quickBuild>`::
176-
If you want to build the image using https://blogs.oracle.com/java/post/graalvm-enterprise-221--faster-smarter-leaner[quick build mode], supply the following in the configuration of the plugin (alternatively set the `GRAALVM_QUICK_BUILD` environment variable to `true`):
176+
If you want to build the image using https://www.graalvm.org/latest/reference-manual/native-image/overview/BuildOutput/#qbm-use-quick-build-mode-for-faster-builds[quick build mode], supply the following in the configuration of the plugin (alternatively set the `GRAALVM_QUICK_BUILD` environment variable to `true`):
177177
[source,xml]
178178
----
179179
<quickBuild>true</quickBuild>

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[versions]
22
# Project versions
33
nativeBuildTools = "0.10.3-SNAPSHOT"
4-
metadataRepository = "0.3.8"
4+
metadataRepository = "0.3.9"
55

66
# External dependencies
77
spock = "2.1-groovy-3.0"

native-gradle-plugin/src/functionalTest/groovy/org/graalvm/buildtools/gradle/JavaApplicationWithAgentFunctionalTest.groovy

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,32 @@
4242
package org.graalvm.buildtools.gradle
4343

4444
import org.graalvm.buildtools.gradle.fixtures.AbstractFunctionalTest
45+
import org.graalvm.buildtools.gradle.fixtures.GraalVMSupport
46+
import org.graalvm.buildtools.utils.NativeImageUtils
4547
import spock.lang.Unroll
4648

4749
class JavaApplicationWithAgentFunctionalTest extends AbstractFunctionalTest {
4850

51+
def getCurrentJDKVersion() {
52+
return NativeImageUtils.getMajorJDKVersion(GraalVMSupport.getGraalVMHomeVersionString())
53+
}
54+
55+
def metadataInSingleConfigFile() {
56+
return getCurrentJDKVersion() >= 23
57+
}
58+
59+
def metadataExistsAt(String path) {
60+
if (metadataInSingleConfigFile()) {
61+
return file("${path}/reachability-metadata.json").exists()
62+
}
63+
64+
boolean allFilesExist = ['jni', 'proxy', 'reflect', 'resource', 'serialization'].every { name ->
65+
file("${path}/${name}-config.json").exists()
66+
}
67+
68+
return allFilesExist
69+
}
70+
4971
@Unroll("agent is not passed and the application fails with JUnit Platform #junitVersion")
5072
def "agent is not passed"() {
5173
given:
@@ -94,18 +116,13 @@ class JavaApplicationWithAgentFunctionalTest extends AbstractFunctionalTest {
94116
""".trim()
95117

96118
and:
97-
['jni', 'proxy', 'reflect', 'resource', 'serialization'].each { name ->
98-
assert file("build/native/agent-output/test/${name}-config.json").exists()
99-
}
119+
assert metadataExistsAt("build/native/agent-output/test")
100120

101121
when:
102122
run 'metadataCopy'
103123

104124
then:
105-
['jni', 'proxy', 'reflect', 'resource', 'serialization'].each { name ->
106-
assert file("build/native/metadataCopyTest/${name}-config.json").exists()
107-
}
108-
125+
assert metadataExistsAt("build/native/metadataCopyTest")
109126

110127
where:
111128
junitVersion = System.getProperty('versions.junit')
@@ -125,7 +142,11 @@ class JavaApplicationWithAgentFunctionalTest extends AbstractFunctionalTest {
125142
}
126143

127144
and:
128-
assert file("build/native/agent-output/test/reflect-config.json").text.contains("\"condition\"")
145+
if (metadataInSingleConfigFile()) {
146+
assert file("build/native/agent-output/test/reachability-metadata.json").text.contains("\"condition\"")
147+
} else {
148+
assert file("build/native/agent-output/test/reflect-config.json").text.contains("\"condition\"")
149+
}
129150

130151
where:
131152
junitVersion = System.getProperty('versions.junit')
@@ -148,22 +169,26 @@ class JavaApplicationWithAgentFunctionalTest extends AbstractFunctionalTest {
148169
}
149170

150171
and:
151-
['jni', 'proxy', 'reflect', 'resource', 'serialization'].each { name ->
152-
assert file("build/native/agent-output/run/${name}-config.json").exists()
153-
}
172+
assert metadataExistsAt("build/native/agent-output/run")
154173

155174
when:
156-
run'metadataCopy', '--task', 'run', '--dir', metadata_dir
175+
run 'metadataCopy', '--task', 'run', '--dir', metadata_dir
157176

158177
then:
159-
['jni', 'proxy', 'reflect', 'resource', 'serialization'].each { name ->
160-
assert file("${metadata_dir}/${name}-config.json").exists()
161-
}
178+
assert metadataExistsAt(metadata_dir)
162179

163180
and:
164-
var reflect_config = file("${metadata_dir}/reflect-config.json")
165-
var reflect_config_contents = reflect_config.text
166-
assert reflect_config_contents.contains("DummyClass") && reflect_config_contents.contains("org.graalvm.demo.Message")
181+
if (metadataInSingleConfigFile()) {
182+
var reachabilityMetadata = file("${metadata_dir}/reachability-metadata.json")
183+
var reachabilityMetadataContents = reachabilityMetadata.text
184+
println reachabilityMetadataContents
185+
assert reachabilityMetadataContents.contains("DummyClass"), reachabilityMetadataContents
186+
assert reachabilityMetadataContents.contains("org.graalvm.demo.Message"), reachabilityMetadataContents
187+
} else {
188+
var reflect_config = file("${metadata_dir}/reflect-config.json")
189+
var reflect_config_contents = reflect_config.text
190+
assert reflect_config_contents.contains("DummyClass") && reflect_config_contents.contains("org.graalvm.demo.Message")
191+
}
167192

168193
when:
169194
run 'nativeRun'
@@ -190,9 +215,7 @@ class JavaApplicationWithAgentFunctionalTest extends AbstractFunctionalTest {
190215
}
191216

192217
and:
193-
['jni', 'proxy', 'reflect', 'resource', 'serialization'].each { name ->
194-
assert file("build/native/agent-output/run/${name}-config.json").exists()
195-
}
218+
assert metadataExistsAt("build/native/agent-output/run")
196219

197220
when:
198221
run'run', '-Pagent', '--configuration-cache', '--rerun-tasks'

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/NativeImagePlugin.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
import org.graalvm.buildtools.gradle.tasks.NativeRunTask;
6565
import org.graalvm.buildtools.gradle.tasks.actions.CleanupAgentFilesAction;
6666
import org.graalvm.buildtools.gradle.tasks.actions.MergeAgentFilesAction;
67-
import org.graalvm.buildtools.gradle.tasks.actions.ProcessGeneratedGraalResourceFilesAction;
6867
import org.graalvm.buildtools.utils.SharedConstants;
6968
import org.graalvm.reachability.DirectoryConfiguration;
7069
import org.gradle.api.Action;
@@ -871,11 +870,6 @@ public void execute(@Nonnull Task task) {
871870
execOperations));
872871

873872
taskToInstrument.doLast(new CleanupAgentFilesAction(mergeInputDirs, fileOperations));
874-
875-
taskToInstrument.doLast(new ProcessGeneratedGraalResourceFilesAction(
876-
outputDir,
877-
graalExtension.getAgent().getFilterableEntries()
878-
));
879873
}
880874

881875
private static void injectTestPluginDependencies(Project project, Property<Boolean> testSupportEnabled) {

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/internal/DefaultGraalVmExtension.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import org.gradle.jvm.toolchain.JavaToolchainService;
5656

5757
import javax.inject.Inject;
58-
import java.util.Arrays;
5958

6059
public abstract class DefaultGraalVmExtension implements GraalVMExtension {
6160
private final transient NamedDomainObjectContainer<NativeImageOptions> nativeImages;
@@ -79,7 +78,6 @@ public DefaultGraalVmExtension(NamedDomainObjectContainer<NativeImageOptions> na
7978
agentOpts.getEnabled().convention(false);
8079
agentOpts.getModes().getConditional().getParallel().convention(true);
8180
agentOpts.getMetadataCopy().getMergeWithExisting().convention(false);
82-
agentOpts.getFilterableEntries().convention(Arrays.asList("org.gradle.", "org.junit."));
8381
agentOpts.getBuiltinHeuristicFilter().convention(true);
8482
agentOpts.getBuiltinCallerFilter().convention(true);
8583
agentOpts.getEnableExperimentalPredefinedClasses().convention(false);

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/internal/NativeImageExecutableLocator.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -91,29 +91,29 @@ public static File findNativeImageExecutable(Property<JavaLauncher> javaLauncher
9191
executablePath = metadata.getInstallationPath().file("bin/" + NATIVE_IMAGE_EXE).getAsFile();
9292
}
9393

94-
try {
95-
if (!executablePath.exists()) {
96-
logger.log("Native Image executable wasn't found. We will now try to download it. ");
97-
File graalVmHomeGuess = executablePath.getParentFile();
98-
99-
File guPath = graalVmHomeGuess.toPath().resolve(GU_EXE).toFile();
100-
if (!guPath.exists()) {
101-
throw new GradleException("'" + GU_EXE + "' at '" + guPath + "' tool wasn't found. This probably means that JDK at isn't a GraalVM distribution.");
102-
}
103-
ExecResult res = execOperations.exec(spec -> {
104-
spec.args("install", "native-image");
105-
spec.setExecutable(Paths.get(graalVmHomeGuess.getAbsolutePath(), GU_EXE));
106-
});
107-
if (res.getExitValue() != 0) {
108-
throw new GradleException("Native Image executable wasn't found, and '" + GU_EXE + "' tool failed to install it.");
109-
}
110-
diagnostics.withGuInstall();
94+
File graalVmHomeGuess = executablePath.getParentFile();
95+
File guPath = graalVmHomeGuess.toPath().resolve(GU_EXE).toFile();
96+
if (guPath.exists() && !executablePath.exists()) {
97+
logger.log("Native Image executable wasn't found. We will now try to download it. ");
98+
99+
ExecResult res = execOperations.exec(spec -> {
100+
spec.args("install", "native-image");
101+
spec.setExecutable(Paths.get(graalVmHomeGuess.getAbsolutePath(), GU_EXE));
102+
});
103+
if (res.getExitValue() != 0) {
104+
throw new GradleException("Native Image executable wasn't found, and '" + GU_EXE + "' tool failed to install it.\n" +
105+
"Make sure to declare the GRAALVM_HOME or JAVA_HOME environment variable or install GraalVM with " +
106+
"native-image in a standard location recognized by Gradle Java toolchain support");
111107
}
112-
} catch (GradleException e) {
113-
throw new GradleException("Determining GraalVM installation failed with message: " + e.getMessage() + "\n\n"
114-
+ "Make sure to declare the GRAALVM_HOME environment variable or install GraalVM with " +
115-
"native-image in a standard location recognized by Gradle Java toolchain support");
108+
diagnostics.withGuInstall();
116109
}
110+
111+
if (!executablePath.exists()) {
112+
throw new GradleException(executablePath + " wasn't found. This probably means that JDK isn't a GraalVM distribution.\n" +
113+
"Make sure to declare the GRAALVM_HOME or JAVA_HOME environment variable or install GraalVM with" +
114+
"native-image in a standard location recognized by Gradle Java toolchain support");
115+
}
116+
117117
diagnostics.withExecutablePath(executablePath);
118118
return executablePath;
119119
}

0 commit comments

Comments
 (0)