Skip to content
Merged
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
4 changes: 4 additions & 0 deletions docs/src/docs/asciidoc/changelog.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ This version introduces a breaking change: the plugin now requires Java 17 to ru

- Added experimental support for layered images

=== Maven plugin

- Added support for running integration tests via maven-failsafe-plugin

== Release 0.10.6

=== Gradle plugin
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.graalvm.buildtools.maven;

class IntegrationTest extends AbstractGraalVMMavenFunctionalTest {
def "run integration tests with failsafe plugin"() {
withSample("integration-test")

when:
mvn '-Pnative', 'verify'

then:
buildSucceeded
file("target/failsafe-reports").exists()
file("target/failsafe-reports/org.graalvm.demo.CalculatorTestIT.txt").readLines().any(line -> line.contains("Tests run: 6, Failures: 0, Errors: 0, Skipped: 0"))
outputContains "[junit-platform-native] Running in 'test listener' mode"
outputContains """
[ 3 containers found ]
[ 0 containers skipped ]
[ 3 containers started ]
[ 0 containers aborted ]
[ 3 containers successful ]
[ 0 containers failed ]
[ 6 tests found ]
[ 0 tests skipped ]
[ 6 tests started ]
[ 0 tests aborted ]
[ 6 tests successful ]
[ 0 tests failed ]
""".trim()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,16 @@ public void afterProjectsRead(MavenSession session) {
}

// Test configuration
withPlugin(build, "maven-surefire-plugin", surefirePlugin -> {
configureJunitListener(surefirePlugin, testIdsDir);
if (agent.isEnabled()) {
List<String> agentOptions = agent.getAgentCommandLine();
configureAgentForSurefire(surefirePlugin, buildAgentArgument(target, Context.test, agentOptions));
}
});
List<String> plugins = List.of("maven-surefire-plugin", "maven-failsafe-plugin");
for (String pluginName : plugins) {
withPlugin(build, pluginName, plugin -> {
configureJunitListener(plugin, testIdsDir);
if (agent.isEnabled()) {
List<String> agentOptions = agent.getAgentCommandLine();
configureAgentForPlugin(plugin, buildAgentArgument(target, Context.test, agentOptions));
}
});
}

// Main configuration
if (agent.isEnabled()) {
Expand Down Expand Up @@ -202,8 +205,8 @@ private static void withPlugin(Build build, String artifactId, Consumer<? super
.ifPresent(consumer);
}

private static void configureAgentForSurefire(Plugin surefirePlugin, String agentArgument) {
updatePluginConfiguration(surefirePlugin, (exec, configuration) -> {
private static void configureAgentForPlugin(Plugin plugin, String agentArgument) {
updatePluginConfiguration(plugin, (exec, configuration) -> {
Xpp3Dom systemProperties = findOrAppend(configuration, "systemProperties");
Xpp3Dom agent = findOrAppend(systemProperties, NATIVEIMAGE_IMAGECODE);
agent.setValue("agent");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import org.eclipse.aether.resolution.DependencyRequest;
import org.eclipse.aether.resolution.DependencyResolutionException;
import org.eclipse.aether.resolution.DependencyResult;
import org.graalvm.buildtools.utils.FileUtils;
import org.graalvm.buildtools.utils.JUnitUtils;
import org.graalvm.buildtools.utils.NativeImageConfigurationUtils;

Expand All @@ -75,8 +74,8 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -178,32 +177,36 @@ public void execute() throws MojoExecutionException {
}

private void configureEnvironment() {
// inherit from surefire mojo
Plugin plugin = project.getPlugin("org.apache.maven.plugins:maven-surefire-plugin");
if (plugin != null) {
List<Plugin> plugins = new ArrayList<>();

Plugin surefire = project.getPlugin("org.apache.maven.plugins:maven-surefire-plugin");
if (surefire != null) {
plugins.add(surefire);
}

Plugin failsafe = project.getPlugin("org.apache.maven.plugins:maven-failsafe-plugin");
if (failsafe != null) {
plugins.add(failsafe);
}

for (Plugin plugin : plugins) {
Object configuration = plugin.getConfiguration();
if (configuration instanceof Xpp3Dom) {
Xpp3Dom dom = (Xpp3Dom) configuration;
Xpp3Dom environmentVariables = dom.getChild("environmentVariables");
if (environmentVariables != null) {
Xpp3Dom[] children = environmentVariables.getChildren();
if (environment == null) {
environment = new HashMap<>(children.length);
}
for (Xpp3Dom child : children) {
environment.put(child.getName(), child.getValue());
}
}
Xpp3Dom systemProps = dom.getChild("systemPropertyVariables");
if (systemProps != null) {
Xpp3Dom[] children = systemProps.getChildren();
if (systemProperties == null) {
systemProperties = new HashMap<>(children.length);
}
for (Xpp3Dom child : children) {
systemProperties.put(child.getName(), child.getValue());
}
}
applyPluginProperties(dom.getChild("environmentVariables"), environment);
applyPluginProperties(dom.getChild("systemPropertyVariables"), systemProperties);
}
}
}

private void applyPluginProperties(Xpp3Dom pluginProperty, Map<String, String> values) {
if (pluginProperty != null) {
Xpp3Dom[] children = pluginProperty.getChildren();
if (values == null) {
values = new HashMap<>(children.length);
}
for (Xpp3Dom child : children) {
values.put(child.getName(), child.getValue());
}
}
}
Expand Down
106 changes: 106 additions & 0 deletions samples/integration-test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.

The Universal Permissive License (UPL), Version 1.0

Subject to the condition set forth below, permission is hereby granted to any
person obtaining a copy of this software, associated documentation and/or
data (collectively the "Software"), free of charge and under any and all
copyright rights in the Software, and any and all patent rights owned or
freely licensable by each licensor hereunder covering either (i) the
unmodified Software as contributed to or provided by such licensor, or (ii)
the Larger Works (as defined below), to deal in both

(a) the Software, and

(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
one is included with the Software each a "Larger Work" to which the Software
is contributed by such licensors),

without restriction, including without limitation the rights to copy, create
derivative works of, display, perform, and distribute the Software and make,
use, sell, offer for sale, import, export, have made, and have sold the
Software and the Larger Work(s), and to sublicense the foregoing rights on
either these or other terms.

This license is subject to the following condition:

The above copyright notice and either this complete permission notice or at a
minimum a reference to the UPL must be included in all copies or substantial
portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.graalvm.buildtools.examples</groupId>
<artifactId>maven</artifactId>
<version>1.0.0-SNAPSHOT</version>

<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.jupiter.version>5.13.0</junit.jupiter.version>
<native.maven.plugin.version>0.11.0-SNAPSHOT</native.maven.plugin.version>
<junit.platform.native.version>0.11.0-SNAPSHOT</junit.platform.native.version>
</properties>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>native</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.5.3</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>${native.maven.plugin.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<id>test-native</id>
<goals>
<goal>test</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.graalvm.demo;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

class CalculatorTestIT {

private int add(int a, int b) {
return a + b;
}

@Test
@DisplayName("1 + 1 = 2")
void addsTwoNumbers() {
assertEquals(2, add(1, 1), "1 + 1 should equal 2");
}

@Test
@DisplayName("1 + 2 = 3")
void addsTwoNumbers2() {
assertEquals(3, add(1, 2), "1 + 2 should equal 3");
}

@ParameterizedTest(name = "{0} + {1} = {2}")
@CsvSource({
"0, 1, 1",
"1, 2, 3",
"49, 51, 100",
"1, 100, 101"
})
void add(int first, int second, int expectedResult) {
assertEquals(expectedResult, add(first, second),
() -> first + " + " + second + " should equal " + expectedResult);
}
}
Loading