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

Fix Broken Maven Functional Tests when Using New Metadata Format #660

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -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:
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
}
}
}
Loading