Skip to content

Commit

Permalink
Silence noisy tests
Browse files Browse the repository at this point in the history
Fix docs
Make sure that GraalVM java executable gets used when attaching the agent
Add implementation dependency on svm.jar

Signed-off-by: Lazar Mitrović <lazar.mitrovic@oracle.com>
  • Loading branch information
lazar-mitrovic committed Aug 4, 2022
1 parent 805e218 commit 4f205d5
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 18 deletions.
5 changes: 3 additions & 2 deletions docs/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ If you are using alternative build systems, see <<alternative-build-systems.adoc

[[changelog]]
== Changelog

=== Release 0.9.13

=== Gradle plugin
==== Gradle plugin
* Reverted a change in the `NativeImagePlugin` that removed publicly accessible constants. This should prevent breakage of external plugins.

=== JUnit testing support
==== JUnit testing support
* Adapted the JUnit automatic metadata registration to changes in annotation handling on newer native image versions.

=== Release 0.9.12
Expand Down
1 change: 1 addition & 0 deletions native-maven-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ dependencies {
implementation(libs.utils)
implementation(libs.jackson.databind)
implementation(libs.jvmReachabilityMetadata)
implementation(libs.graalvm.svm)

compileOnly(libs.maven.pluginApi)
compileOnly(libs.maven.core)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class JavaApplicationWithAgentFunctionalTest extends AbstractGraalVMMavenFunctio
when:
// Run Maven in debug mode (-X) in order to capture the command line arguments
// used to launch Surefire with the agent.
mvn '-X', '-Pnative', 'test', '-DskipNativeTests'
mvnDebug '-Pnative', 'test', '-DskipNativeTests'

then:
// Agent is used with Surefire
Expand Down Expand Up @@ -85,7 +85,7 @@ class JavaApplicationWithAgentFunctionalTest extends AbstractGraalVMMavenFunctio
when:
// Run Maven in debug mode (-X) in order to capture the command line arguments
// used to launch Surefire with the agent.
mvn '-X', '-Pnative', 'test'
mvnDebug '-Pnative', 'test'

then:
outputContains """
Expand Down Expand Up @@ -162,7 +162,7 @@ class JavaApplicationWithAgentFunctionalTest extends AbstractGraalVMMavenFunctio
when:
// Run Maven in debug mode (-X) in order to capture the command line arguments
// used to launch Surefire with the agent.
mvn '-X', '-Pnative', '-DagentOptions=periodic-config', 'test'
mvnDebug '-Pnative', '-DagentOptions=periodic-config', 'test'

then:
outputContains """
Expand Down Expand Up @@ -214,7 +214,7 @@ class JavaApplicationWithAgentFunctionalTest extends AbstractGraalVMMavenFunctio
withSample("java-application-with-reflection")

when:
mvn '-X', '-Pnative', '-DskipTests=true', '-DskipNativeBuild=true', 'package', 'exec:exec@java-agent'
mvnDebug '-Pnative', '-DskipTests=true', '-DskipNativeBuild=true', 'package', 'exec:exec@java-agent'

then:
['jni', 'proxy', 'reflect', 'resource', 'serialization'].each { name ->
Expand Down Expand Up @@ -246,7 +246,7 @@ class JavaApplicationWithAgentFunctionalTest extends AbstractGraalVMMavenFunctio
withSample("java-application-with-reflection")

when:
mvn '-X', '-Pnative', '-Dagent=false', '-DskipTests=true', '-DskipNativeBuild=true', 'package', 'exec:exec@java-agent'
mvnDebug '-Pnative', '-Dagent=false', '-DskipTests=true', '-DskipNativeBuild=true', 'package', 'exec:exec@java-agent'

then:
outputDoesNotContain '-agentlib:native-image-agent'
Expand All @@ -263,7 +263,7 @@ class JavaApplicationWithAgentFunctionalTest extends AbstractGraalVMMavenFunctio
withSample("java-application-with-reflection")

when:
mvn '-X', '-Pnative', '-DagentOptions=periodic-config', '-DskipTests=true', '-DskipNativeBuild=true', 'package', 'exec:exec@java-agent'
mvnDebug '-Pnative', '-DagentOptions=periodic-config', '-DskipTests=true', '-DskipNativeBuild=true', 'package', 'exec:exec@java-agent'

then:
['jni', 'proxy', 'reflect', 'resource', 'serialization'].each { name ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class NativeExtension extends AbstractMavenLifecycleParticipant implement
private static final String JUNIT_PLATFORM_LISTENERS_UID_TRACKING_OUTPUT_DIR = "junit.platform.listeners.uid.tracking.output.dir";
private static final String NATIVEIMAGE_IMAGECODE = "org.graalvm.nativeimage.imagecode";

private Logger logger;
private static Logger logger;

@Override
public void enableLogging(Logger logger) {
Expand Down Expand Up @@ -318,6 +318,12 @@ private static void configureAgentForSurefire(Plugin surefirePlugin, String agen
Xpp3Dom argLine = new Xpp3Dom("argLine");
argLine.setValue(agentArgument);
configuration.addChild(argLine);
Xpp3Dom jvm = findOrAppend(configuration, "jvm");
try {
jvm.setValue(Utils.getNativeImage(logger).getParent().resolve("java").toString());
} catch (MojoExecutionException e) {
throw new RuntimeException(e);
}
});
}

Expand Down
6 changes: 6 additions & 0 deletions native-maven-plugin/src/seeding-build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.jupiter.version>5.8.1</junit.jupiter.version>
<graalvm.version>22.0.0</graalvm.version>
<mainClass>org.graalvm.demo.Application</mainClass>
</properties>

Expand All @@ -62,6 +63,11 @@
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>svm</artifactId>
<version>${graalvm.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,61 @@ abstract class AbstractGraalVMMavenFunctionalTest extends Specification {
}

void mvn(List<String> args) {
mvn(args as String[])
Map<String, String> systemProperties = [
"org.apache.http" : "off",
"org.apache.http.wire" : "off",
].collectEntries { key, value ->
["org.slf4j.simpleLogger.log.${key}".toString(), value]
}
mvn(args, systemProperties)
}

void mvn(String... args) {
System.out.println("Running copy of maven project `" + testOrigin + "` with `" + args + "`");
mvn(args.toList())
}

void mvn(List<String> args, Map<String, String> systemProperties) {
System.out.println("Running copy of maven project `" + testOrigin + "` with " + args);
var resultingSystemProperties = [
"common.repo.uri": System.getProperty("common.repo.uri"),
"seed.repo.uri": System.getProperty("seed.repo.uri"),
"maven.repo.local": testDirectory.resolve("local-repo").toFile().absolutePath
]
resultingSystemProperties.putAll(systemProperties)

result = executor.execute(
testDirectory.toFile(),
[
"org.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener": "warn",
"common.repo.uri": System.getProperty("common.repo.uri"),
"seed.repo.uri": System.getProperty("seed.repo.uri"),
"maven.repo.local": testDirectory.resolve("local-repo").toFile().absolutePath
],
resultingSystemProperties,
[*injectedSystemProperties,
*args],
new File(System.getProperty("maven.settings"))
)
System.out.println("Exit code is ${result.exitCode}")

}

void mvnDebug(String... args) {
Map<String, String> systemProperties = [
"org.apache.http" : "off",
"org.apache.http.wire" : "off",
"org.apache.maven.cli.transfer.Slf4jMavenTransferListener" : "warn",
"org.eclipse.aether.internal.impl.DefaultTransporterProvider" : "error",
"org.eclipse.aether.internal.impl.DefaultRepositoryConnectorProvider": "error",
"org.eclipse.aether.internal.impl.TrackingFileManager" : "error",
"org.eclipse.aether.internal.impl.DefaultArtifactResolver" : "error",
"org.codehaus.plexus.PlexusContainer" : "error",
"org.apache.maven.plugin.internal.DefaultPluginDependenciesResolver" : "error",
"org.apache.maven.shared.filtering.DefaultMavenFileFilter" : "error",
"org.codehaus.mojo.exec.ExecMojo" : "debug",
// This is THE logger we need for checking java execution
"org.apache.maven.lifecycle.internal.LifecycleDebugLogger" : "error"
].collectEntries { key, value ->
["org.slf4j.simpleLogger.log.${key}".toString(), value]
}

ArrayList<String> resultingArgs = args.toList()
resultingArgs.add(0, "-X")
mvn(resultingArgs, systemProperties)
}

boolean isDidNotCrash() {
Expand Down
9 changes: 8 additions & 1 deletion samples/java-application-with-custom-packaging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@
<micronaut.version>3.3.4</micronaut.version>
<exec.mainClass>org.graalvm.demo.Application</exec.mainClass>
<micronaut.runtime>netty</micronaut.runtime>
<maven.native.plugin.version>0.9.13-SNAPSHOT</maven.native.plugin.version>
<maven.native.plugin.version>0.9.14-SNAPSHOT</maven.native.plugin.version>
</properties>


<repositories>
<repository>
<id>central</id>
Expand Down Expand Up @@ -141,6 +142,12 @@
<artifactId>micronaut-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>${maven.native.plugin.version}</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down

0 comments on commit 4f205d5

Please sign in to comment.