diff --git a/devtools/maven/src/main/java/io/quarkus/maven/QuarkusBootstrapMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/QuarkusBootstrapMojo.java index 1af17c8a29623..84dde86e3ad01 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/QuarkusBootstrapMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/QuarkusBootstrapMojo.java @@ -3,6 +3,7 @@ import java.io.File; import java.util.List; +import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -47,6 +48,9 @@ public abstract class QuarkusBootstrapMojo extends AbstractMojo { @Parameter(defaultValue = "${project}", readonly = true, required = true) private MavenProject project; + @Parameter(defaultValue = "${session}", readonly = true) + private MavenSession session; + @Parameter(defaultValue = "${project.build.directory}") private File buildDir; @@ -125,6 +129,10 @@ protected MavenProject mavenProject() { return project; } + public MavenSession mavenSession() { + return session; + } + protected File buildDir() { return buildDir; } diff --git a/devtools/maven/src/main/java/io/quarkus/maven/QuarkusBootstrapProvider.java b/devtools/maven/src/main/java/io/quarkus/maven/QuarkusBootstrapProvider.java index c827cd3f450b3..1717e65b7f3b6 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/QuarkusBootstrapProvider.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/QuarkusBootstrapProvider.java @@ -1,5 +1,8 @@ package io.quarkus.maven; +import static io.smallrye.common.expression.Expression.Flag.LENIENT_SYNTAX; +import static io.smallrye.common.expression.Expression.Flag.NO_TRIM; + import java.io.Closeable; import java.io.File; import java.io.IOException; @@ -25,6 +28,7 @@ import io.quarkus.bootstrap.model.PathsCollection; import io.quarkus.bootstrap.resolver.maven.BootstrapMavenException; import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver; +import io.smallrye.common.expression.Expression; @Component(role = QuarkusBootstrapProvider.class, instantiationStrategy = "singleton") public class QuarkusBootstrapProvider implements Closeable { @@ -163,6 +167,22 @@ protected QuarkusBootstrap bootstrapQuarkus(QuarkusBootstrapMojo mojo) throws Mo effectiveProperties.putIfAbsent("quarkus.application.name", mojo.mavenProject().getArtifactId()); effectiveProperties.putIfAbsent("quarkus.application.version", mojo.mavenProject().getVersion()); + // Add other properties that may be required for expansion + for (Object value : effectiveProperties.values()) { + for (String reference : Expression.compile((String) value, LENIENT_SYNTAX, NO_TRIM).getReferencedStrings()) { + String referenceValue = mojo.mavenSession().getUserProperties().getProperty(reference); + if (referenceValue != null) { + effectiveProperties.setProperty(reference, referenceValue); + continue; + } + + referenceValue = projectProperties.getProperty(reference); + if (referenceValue != null) { + effectiveProperties.setProperty(reference, referenceValue); + } + } + } + QuarkusBootstrap.Builder builder = QuarkusBootstrap.builder() .setAppArtifact(projectArtifact(mojo)) .setMavenArtifactResolver(artifactResolver(mojo)) diff --git a/integration-tests/maven/src/test/java/io/quarkus/maven/it/DevMojoIT.java b/integration-tests/maven/src/test/java/io/quarkus/maven/it/DevMojoIT.java index eb3bf674d8369..cd1611ab19758 100644 --- a/integration-tests/maven/src/test/java/io/quarkus/maven/it/DevMojoIT.java +++ b/integration-tests/maven/src/test/java/io/quarkus/maven/it/DevMojoIT.java @@ -1028,4 +1028,12 @@ public void testThatGenerateCodeGoalIsNotTriggeredIfNotConfigured() throws IOExc assertThat(running.log()).contains("Copying 1 resource"); // maven-resource-plugin assertThat(running.log()).contains("Compiling 2 source files"); // maven-compiler-plugin } + + @Test + public void testPropertyExpansion() throws IOException, MavenInvocationException { + testDir = initProject("projects/property-expansion"); + runAndCheck(); + assertThat(DevModeTestUtils.getHttpResponse("/app/hello/")).isEqualTo("hello"); + assertThat(DevModeTestUtils.getHttpResponse("/app/hello/applicationName")).isEqualTo("myapp"); + } } diff --git a/integration-tests/maven/src/test/resources/projects/property-expansion/pom.xml b/integration-tests/maven/src/test/resources/projects/property-expansion/pom.xml new file mode 100644 index 0000000000000..988a9ecb6ff89 --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/property-expansion/pom.xml @@ -0,0 +1,103 @@ + + + 4.0.0 + org.acme + acme + 1.0-SNAPSHOT + + io.quarkus + quarkus-bom + @project.version@ + @project.version@ + 1.8 + UTF-8 + 1.8 + + myapp + ${expansion.application.name} + + tag + ${expansion.image.tag} + + + + + + ${quarkus.platform.group-id} + ${quarkus.platform.artifact-id} + ${quarkus.platform.version} + pom + import + + + + + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-container-image-docker + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.2.0 + + + regex-property + validate + + regex-property + + + expansion.image.tag + tag + tag + tag + false + + + + + + io.quarkus + quarkus-maven-plugin + ${quarkus-plugin.version} + + + + generate-code + generate-code-tests + build + + + + + + + + + native + + native + + + + diff --git a/integration-tests/maven/src/test/resources/projects/property-expansion/src/main/java/org/acme/HelloResource.java b/integration-tests/maven/src/test/resources/projects/property-expansion/src/main/java/org/acme/HelloResource.java new file mode 100644 index 0000000000000..b59ceab007ad7 --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/property-expansion/src/main/java/org/acme/HelloResource.java @@ -0,0 +1,27 @@ +package org.acme; + +import org.eclipse.microprofile.config.inject.ConfigProperty; + +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") +@Produces(MediaType.TEXT_PLAIN) +public class HelloResource { + @GET + public String hello() { + return "hello"; + } + + @ConfigProperty(name = "quarkus.application.name") + String applicationName; + + @GET + @Path("/applicationName") + public String applicationName() { + return applicationName; + } +} diff --git a/integration-tests/maven/src/test/resources/projects/property-expansion/src/main/java/org/acme/MyApplication.java b/integration-tests/maven/src/test/resources/projects/property-expansion/src/main/java/org/acme/MyApplication.java new file mode 100644 index 0000000000000..2b41cd0385afb --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/property-expansion/src/main/java/org/acme/MyApplication.java @@ -0,0 +1,9 @@ +package org.acme; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +@ApplicationPath("/app") +public class MyApplication extends Application { + +} diff --git a/integration-tests/maven/src/test/resources/projects/property-expansion/src/main/resources/META-INF/resources/index.html b/integration-tests/maven/src/test/resources/projects/property-expansion/src/main/resources/META-INF/resources/index.html new file mode 100644 index 0000000000000..c09bb5c96b869 --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/property-expansion/src/main/resources/META-INF/resources/index.html @@ -0,0 +1,156 @@ + + + + + acme - 1.0-SNAPSHOT + + + + + + +
+
+

Congratulations, you have created a new Quarkus application.

+ +

Why do you see this?

+ +

This page is served by Quarkus. The source is in + src/main/resources/META-INF/resources/index.html.

+ +

What can I do from here?

+ +

If not already done, run the application in dev mode using: mvn compile quarkus:dev. +

+ + +

Do you like Quarkus?

+

Go give it a star on GitHub.

+ +

How do I get rid of this page?

+

Just delete the src/main/resources/META-INF/resources/index.html file.

+
+
+
+

Application

+
    +
  • GroupId: org.acme
  • +
  • ArtifactId: acme
  • +
  • Version: 1.0-SNAPSHOT
  • +
  • Quarkus Version: 999-SNAPSHOT
  • +
+
+
+

Next steps

+ +
+
+
+ + + + \ No newline at end of file diff --git a/integration-tests/maven/src/test/resources/projects/property-expansion/src/test/java/org/acme/HelloResourceTest.java b/integration-tests/maven/src/test/resources/projects/property-expansion/src/test/java/org/acme/HelloResourceTest.java new file mode 100644 index 0000000000000..c2f29e2c9f711 --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/property-expansion/src/test/java/org/acme/HelloResourceTest.java @@ -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("/app/hello") + .then() + .statusCode(200) + .body(is("hello")); + } + +}