diff --git a/native-maven-plugin/src/functionalTest/groovy/org/graalvm/buildtools/maven/JavaApplicationWithAgentFunctionalTest.groovy b/native-maven-plugin/src/functionalTest/groovy/org/graalvm/buildtools/maven/JavaApplicationWithAgentFunctionalTest.groovy index 282e25be..85d5329c 100644 --- a/native-maven-plugin/src/functionalTest/groovy/org/graalvm/buildtools/maven/JavaApplicationWithAgentFunctionalTest.groovy +++ b/native-maven-plugin/src/functionalTest/groovy/org/graalvm/buildtools/maven/JavaApplicationWithAgentFunctionalTest.groovy @@ -41,11 +41,31 @@ package org.graalvm.buildtools.maven +import org.graalvm.buildtools.utils.NativeImageUtils import spock.lang.Issue -import spock.lang.Unroll class JavaApplicationWithAgentFunctionalTest extends AbstractGraalVMMavenFunctionalTest { + def getCurrentJDKVersion() { + return NativeImageUtils.getMajorJDKVersion(GraalVMSupport.getGraalVMHomeVersionString()) + } + + def metadataInSingleConfigFile() { + return getCurrentJDKVersion() >= 23 + } + + def metadataExistsAt(String path) { + if (metadataInSingleConfigFile()) { + return file("${path}/reachability-metadata.json").exists() + } + + boolean allFilesExist = ['jni', 'proxy', 'reflect', 'resource', 'serialization'].every { name -> + file("${path}/${name}-config.json").exists() + } + + return allFilesExist + } + @Issue("https://github.com/graalvm/native-build-tools/issues/179") def "agent is used for JVM tests when native image tests are skipped via -DskipNativeTests"() { given: @@ -60,11 +80,10 @@ class JavaApplicationWithAgentFunctionalTest extends AbstractGraalVMMavenFunctio // Agent is used with Surefire outputContains '-agentlib:native-image-agent=' + and: // Agent generates files - ['jni', 'proxy', 'reflect', 'resource', 'serialization'].each { name -> - assert file("target/native/agent-output/test/${name}-config.json").exists() - } + metadataExistsAt("target/native/agent-output/test/") and: // Surefire / JVM tests run diff --git a/native-maven-plugin/src/testFixtures/groovy/org/graalvm/buildtools/maven/GraalVMSupport.groovy b/native-maven-plugin/src/testFixtures/groovy/org/graalvm/buildtools/maven/GraalVMSupport.groovy new file mode 100644 index 00000000..1b7215fd --- /dev/null +++ b/native-maven-plugin/src/testFixtures/groovy/org/graalvm/buildtools/maven/GraalVMSupport.groovy @@ -0,0 +1,33 @@ +package org.graalvm.buildtools.maven + +class GraalVMSupport { + + static String getJavaHomeVersionString() { + String javaHomeLocation = System.getenv("JAVA_HOME") + return extractVersionString(javaHomeLocation) + } + + static String getGraalVMHomeVersionString() { + String graalvmHomeLocation = System.getenv("GRAALVM_HOME") + return extractVersionString(graalvmHomeLocation) + } + + private static String extractVersionString(String location) { + def sout = new StringBuilder(), serr = new StringBuilder() + String command = getSystemBasedCommand(location); + def proc = command.execute() + proc.consumeProcessOutput(sout, serr) + proc.waitForOrKill(1000) + assert serr.toString().isEmpty() + + return sout.toString() + } + + private static String getSystemBasedCommand(String location) { + if (System.getProperty("os.name", "unknown").contains("Windows")) { + return location + '\\bin\\native-image.cmd --version' + } else { + return location + '/bin/native-image --version' + } + } +}