Skip to content

Commit

Permalink
Do not reset quarkus.package.uber-jar system property after each boot…
Browse files Browse the repository at this point in the history
…strap goal when the uberJar Maven plugin parameter is configured
  • Loading branch information
aloubyansky committed Dec 3, 2020
1 parent ff9c6f0 commit 051a616
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 19 deletions.
5 changes: 0 additions & 5 deletions devtools/maven/src/main/java/io/quarkus/maven/BuildMojo.java
Expand Up @@ -77,7 +77,6 @@ protected boolean beforeExecute() throws MojoExecutionException {
@Override
protected void doExecute() throws MojoExecutionException {

boolean clear = false;
try {
try (CuratedApplication curatedApplication = bootstrapApplication()) {

Expand Down Expand Up @@ -110,10 +109,6 @@ protected void doExecute() throws MojoExecutionException {
}
} catch (Exception e) {
throw new MojoExecutionException("Failed to build quarkus application", e);
} finally {
if (clear) {
System.clearProperty(QUARKUS_PACKAGE_UBER_JAR);
}
}
}

Expand Down
Expand Up @@ -76,21 +76,13 @@ public abstract class QuarkusBootstrapMojo extends AbstractMojo {
private String[] ignoredEntries;

private AppArtifactKey projectId;
private boolean clearUberJarProp;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (!beforeExecute()) {
return;
}
try {
doExecute();
} finally {
if (clearUberJarProp) {
System.clearProperty(BuildMojo.QUARKUS_PACKAGE_UBER_JAR);
clearUberJarProp = false;
}
}
doExecute();
}

@Override
Expand All @@ -99,10 +91,6 @@ public void setLog(Log log) {
MojoLogger.delegate = log;
}

protected void clearUberJarProp() {
this.clearUberJarProp = true;
}

/**
* This callback allows to evaluate whether this mojo should be executed, skipped or fail.
*
Expand Down
Expand Up @@ -161,7 +161,6 @@ protected QuarkusBootstrap bootstrapQuarkus(QuarkusBootstrapMojo mojo) throws Mo
}
if (mojo.uberJar() && System.getProperty(BuildMojo.QUARKUS_PACKAGE_UBER_JAR) == null) {
System.setProperty(BuildMojo.QUARKUS_PACKAGE_UBER_JAR, "true");
mojo.clearUberJarProp();
}
effectiveProperties.putIfAbsent("quarkus.application.name", mojo.mavenProject().getArtifactId());
effectiveProperties.putIfAbsent("quarkus.application.version", mojo.mavenProject().getVersion());
Expand Down
Expand Up @@ -34,6 +34,18 @@ public class PackageIT extends MojoTestBase {
private RunningInvoker running;
private File testDir;

@Test
public void testUberJarMavenPluginConfiguration()
throws MavenInvocationException, IOException, InterruptedException {
testDir = initProject("projects/uberjar-maven-plugin-config");
running = new RunningInvoker(testDir, false);
final MavenProcessInvocationResult result = running.execute(Collections.singletonList("package"),
Collections.emptyMap());
assertThat(result.getProcess().waitFor()).isEqualTo(0);

verifyUberJar();
}

@Test
public void testPackageWorksWhenUberjarIsFalse()
throws MavenInvocationException, IOException, InterruptedException {
Expand Down Expand Up @@ -126,6 +138,10 @@ private void createAndVerifyUberJar() throws IOException, MavenInvocationExcepti
Collections.emptyMap(), p);
assertThat(result.getProcess().waitFor()).isEqualTo(0);

verifyUberJar();
}

private void verifyUberJar() throws IOException {
final File targetDir = getTargetDir();
List<File> jars = getFilesEndingWith(targetDir, ".jar");
assertThat(jars).hasSize(1);
Expand Down
@@ -0,0 +1,93 @@
<?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>
</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>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</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>generate-code</goal>
<goal>generate-code-tests</goal>
<goal>build</goal>
</goals>
<configuration>
<uberJar>true</uberJar>
</configuration>
</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>
@@ -0,0 +1,16 @@
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";
}
}

0 comments on commit 051a616

Please sign in to comment.