-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5895 from jaikiran/qk-5880
java.library.path should be configurable when launching the application's native image
- Loading branch information
Showing
4 changed files
with
184 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
integration-tests/maven/src/test/java/io/quarkus/maven/it/NativeImageIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package io.quarkus.maven.it; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
import java.io.File; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Assumptions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.maven.it.verifier.MavenProcessInvocationResult; | ||
import io.quarkus.maven.it.verifier.RunningInvoker; | ||
|
||
/** | ||
* | ||
*/ | ||
public class NativeImageIT extends MojoTestBase { | ||
|
||
/** | ||
* Tests that the {@code java.library.path} can be overridden/configurable by passing the system property | ||
* when launching the generated application's native image. | ||
* | ||
* @throws Exception | ||
*/ | ||
@Test | ||
public void testJavaLibraryPathAtRuntime() throws Exception { | ||
final File testDir = initProject("projects/native-image-app", "projects/native-image-app-output"); | ||
final RunningInvoker running = new RunningInvoker(testDir, false); | ||
|
||
// trigger mvn package -Pnative -Dquarkus.ssl.native=true | ||
final String[] mvnArgs = new String[] { "package", "-DskipTests", "-Pnative", "-Dquarkus.ssl.native=true" }; | ||
final MavenProcessInvocationResult result = running.execute(Arrays.asList(mvnArgs), Collections.emptyMap()); | ||
await().atMost(5, TimeUnit.MINUTES).until(() -> result.getProcess() != null && !result.getProcess().isAlive()); | ||
final String processLog = running.log(); | ||
try { | ||
assertThat(processLog).containsIgnoringCase("BUILD SUCCESS"); | ||
} catch (AssertionError ae) { | ||
// skip this test (instead of failing), if the native-image command wasn't available. | ||
// Bit brittle to rely on the log message, but it's OK in the context of this test | ||
Assumptions.assumeFalse(processLog.contains("Cannot find the `native-image"), | ||
"Skipping test since native-image tool isn't available"); | ||
// native-image command was available but the build failed for some reason, throw the original error | ||
throw ae; | ||
} finally { | ||
running.stop(); | ||
} | ||
|
||
// now that the native image is built, run it | ||
final Path nativeImageRunner = testDir.toPath().toAbsolutePath().resolve(Paths.get("target/acme-1.0-SNAPSHOT-runner")); | ||
final Path tmpDir = Files.createTempDirectory("native-image-test"); | ||
tmpDir.toFile().deleteOnExit(); | ||
final Process nativeImageRunWithAdditionalLibPath = runNativeImage(nativeImageRunner, | ||
new String[] { "-Djava.library.path=" + tmpDir.toString() }); | ||
try { | ||
final String response = getHttpResponse("/hello/javaLibraryPath"); | ||
Assertions.assertTrue(response.contains(tmpDir.toString()), | ||
"Response " + response + " for java.library.path was expected to contain the " + tmpDir + ", but didn't"); | ||
} finally { | ||
nativeImageRunWithAdditionalLibPath.destroy(); | ||
} | ||
|
||
} | ||
|
||
private static Process runNativeImage(final Path nativeImageRunnerFile, final String[] params) throws Exception { | ||
final List<String> commands = new ArrayList<>(); | ||
commands.add(nativeImageRunnerFile.toString()); | ||
if (params != null) { | ||
commands.addAll(Arrays.asList(params)); | ||
} | ||
final ProcessBuilder processBuilder = new ProcessBuilder(commands.toArray(new String[0])); | ||
processBuilder.inheritIO(); | ||
return processBuilder.start(); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
integration-tests/maven/src/test/resources/projects/native-image-app/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?xml version="1.0"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.acme</groupId> | ||
<artifactId>acme</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<properties> | ||
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id> | ||
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id> | ||
<quarkus.platform.version>@project.version@</quarkus.platform.version> | ||
<quarkus-plugin.version>@project.version@</quarkus-plugin.version> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>${quarkus.platform.group-id}</groupId> | ||
<artifactId>${quarkus.platform.artifact-id}</artifactId> | ||
<version>${quarkus.platform.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<dependencies> | ||
<!-- insert test dependencies here --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy</artifactId> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-maven-plugin</artifactId> | ||
<version>${quarkus-plugin.version}</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>build</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<profiles> | ||
<profile> | ||
<id>native</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-maven-plugin</artifactId> | ||
<version>${quarkus-plugin.version}</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>native-image</goal> | ||
</goals> | ||
<configuration> | ||
<enableHttpUrlHandler>true</enableHttpUrlHandler> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
24 changes: 24 additions & 0 deletions
24
...en/src/test/resources/projects/native-image-app/src/main/java/org/acme/HelloResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.acme; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
@Path("/hello") | ||
public class HelloResource { | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String hello() { | ||
return "hello"; | ||
} | ||
|
||
@GET | ||
@Path("/javaLibraryPath") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String javaLibraryPath() { | ||
return System.getProperty("java.library.path"); | ||
} | ||
|
||
} |