Skip to content

Commit

Permalink
1.7.0.Final quarkus.package.output-directory causes NPE running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aloubyansky committed Aug 26, 2020
1 parent 9d94958 commit 0a876b5
Show file tree
Hide file tree
Showing 8 changed files with 339 additions and 4 deletions.
Expand Up @@ -63,6 +63,28 @@ private void ensureManifestOfJarIsReadableByJarInputStream(File jar) throws IOEx
}
}

@Test
public void testQuarkusPackageOutputDirectory()
throws MavenInvocationException, IOException, InterruptedException {
testDir = initProject("projects/quarkus.package.output-directory");

running = new RunningInvoker(testDir, false);
// we do want to run the tests too
final MavenProcessInvocationResult result = running.execute(Collections.singletonList("package"),
Collections.emptyMap());

assertThat(result.getProcess().waitFor()).isEqualTo(0);

File targetDir = getTargetDir();
List<File> jars = getFilesEndingWith(targetDir, ".jar");
assertThat(jars).hasSize(1);

targetDir = new File(targetDir, "custom-output-dir");
assertThat(targetDir).exists();
jars = getFilesEndingWith(targetDir, ".jar");
assertThat(jars).hasSize(1);
}

@Test
public void testPackageWorksWhenUberjarIsTrue()
throws MavenInvocationException, IOException, InterruptedException {
Expand Down
@@ -0,0 +1,99 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://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>
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- insert managed dependencies here -->
<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>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>\${quarkus-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>prepare</goal>
<goal>prepare-tests</goal>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>\${surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>\${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</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>
@@ -0,0 +1,17 @@
package org.acme;

import javax.inject.Inject;
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";
}
}
@@ -0,0 +1,156 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>acme - 1.0-SNAPSHOT</title>
<style>
h1, h2, h3, h4, h5, h6 {
margin-bottom: 0.5rem;
font-weight: 400;
line-height: 1.5;
}

h1 {
font-size: 2.5rem;
}

h2 {
font-size: 2rem
}

h3 {
font-size: 1.75rem
}

h4 {
font-size: 1.5rem
}

h5 {
font-size: 1.25rem
}

h6 {
font-size: 1rem
}

.lead {
font-weight: 300;
font-size: 2rem;
}

.banner {
font-size: 2.7rem;
margin: 0;
padding: 2rem 1rem;
background-color: #00A1E2;
color: white;
}

body {
margin: 0;
font-family: -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
}

code {
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
font-size: 87.5%;
color: #e83e8c;
word-break: break-word;
}

.left-column {
padding: .75rem;
max-width: 75%;
min-width: 55%;
}

.right-column {
padding: .75rem;
max-width: 25%;
}

.container {
display: flex;
width: 100%;
}

li {
margin: 0.75rem;
}

.right-section {
margin-left: 1rem;
padding-left: 0.5rem;
}

.right-section h3 {
padding-top: 0;
font-weight: 200;
}

.right-section ul {
border-left: 0.3rem solid #00A1E2;
list-style-type: none;
padding-left: 0;
}

</style>
</head>
<body>

<div class="banner lead">
Your new Cloud-Native application is ready!
</div>

<div class="container">
<div class="left-column">
<p class="lead"> Congratulations, you have created a new Quarkus application.</p>

<h2>Why do you see this?</h2>

<p>This page is served by Quarkus. The source is in
<code>src/main/resources/META-INF/resources/index.html</code>.</p>

<h2>What can I do from here?</h2>

<p>If not already done, run the application in <em>dev mode</em> using: <code>mvn compile quarkus:dev</code>.
</p>
<ul>
<li>Add REST resources, Servlets, functions and other services in <code>src/main/java</code>.</li>
<li>Your static assets are located in <code>src/main/resources/META-INF/resources</code>.</li>
<li>Configure your application in <code>src/main/resources/application.properties</code>.
</li>
</ul>

<h2>Do you like Quarkus?</h2>
<p>Go give it a star on <a href="https://github.com/quarkusio/quarkus">GitHub</a>.</p>

<h2>How do I get rid of this page?</h2>
<p>Just delete the <code>src/main/resources/META-INF/resources/index.html</code> file.</p>
</div>
<div class="right-column">
<div class="right-section">
<h3>Application</h3>
<ul>
<li>GroupId: org.acme</li>
<li>ArtifactId: acme</li>
<li>Version: 1.0-SNAPSHOT</li>
<li>Quarkus Version: 999-SNAPSHOT</li>
</ul>
</div>
<div class="right-section">
<h3>Next steps</h3>
<ul>
<!-- the url have been erased on purpose -->
<li><a href="#">Setup your IDE</a></li>
<li><a href="#">Getting started</a></li>
<li><a href="#">Documentation</a></li>
</ul>
</div>
</div>
</div>


</body>
</html>
@@ -0,0 +1,2 @@
# Configuration file
quarkus.package.output-directory=custom-output-dir
@@ -0,0 +1,21 @@
package org.acme;

import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;

@QuarkusTest
public class HelloResourceTest {

@Test
public void testHelloEndpoint() {
given()
.when().get("/hello")
.then()
.statusCode(200)
.body(is("hello"));
}

}
Expand Up @@ -115,7 +115,16 @@ public static Path getAppClassLocationForTestLocation(String testClassLocation)
}
return TEST_TO_MAIN_DIR_FRAGMENTS.entrySet().stream()
.filter(e -> testClassLocation.contains(e.getKey()))
.map(e -> Paths.get(testClassLocation.replace(e.getKey(), e.getValue())))
.map(e -> {
// we should replace only the last occurrence of the fragment
final int i = testClassLocation.lastIndexOf(e.getKey());
final StringBuilder buf = new StringBuilder(testClassLocation.length());
buf.append(testClassLocation.substring(0, i)).append(e.getValue());
if (i + e.getKey().length() + 1 < testClassLocation.length()) {
buf.append(testClassLocation.substring(i + e.getKey().length()));
}
return Paths.get(buf.toString());
})
.findFirst()
.orElseThrow(() -> new IllegalStateException("Unable to translate path for " + testClassLocation));
}
Expand Down
Expand Up @@ -171,18 +171,27 @@ private ExtensionState doJavaStart(ExtensionContext context, Class<? extends Qua
}
}

runnerBuilder.setProjectRoot(Paths.get("").normalize().toAbsolutePath());
final Path projectRoot = Paths.get("").normalize().toAbsolutePath();
runnerBuilder.setProjectRoot(projectRoot);
Path outputDir;
try {
// this should work for both maven and gradle
outputDir = projectRoot.resolve(projectRoot.relativize(testClassLocation).getName(0));
} catch (Exception e) {
// this shouldn't happen since testClassLocation is usually found under the project dir
outputDir = projectRoot;
}
runnerBuilder.setTargetDirectory(outputDir);

rootBuilder.add(appClassLocation);
final Path appResourcesLocation = PathTestHelper.getResourcesForClassesDirOrNull(appClassLocation, "main");
if (appResourcesLocation != null) {
rootBuilder.add(appResourcesLocation);
}

Path root = Paths.get("").normalize().toAbsolutePath();
// If gradle project running directly with IDE
if (System.getProperty(BootstrapConstants.SERIALIZED_APP_MODEL) == null) {
BuildToolHelper.enableGradleAppModel(root, "TEST", QuarkusModelHelper.TEST_REQUIRED_TASKS);
BuildToolHelper.enableGradleAppModel(projectRoot, "TEST", QuarkusModelHelper.TEST_REQUIRED_TASKS);
}

runnerBuilder.setApplicationRoot(rootBuilder.build());
Expand Down

0 comments on commit 0a876b5

Please sign in to comment.