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 bf298c21d3bf0b..7a85f949723622 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 @@ -1468,4 +1468,139 @@ public void testExternalReloadableArtifacts() throws Exception { .atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES) .until(() -> devModeClient.getHttpResponse("/hello").contains("BONJOUR!")); } + + @Test + public void testThatAptInClasspathWorks() throws MavenInvocationException, IOException { + testDir = initProject("projects/apt-in-classpath", "projects/project-apt-in-classpath"); + run(true); + + // wait until app is compiled and started + await() + .pollDelay(100, TimeUnit.MILLISECONDS) + .atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES) + .until(() -> devModeClient.getHttpResponse("/hello").contains("field/myEntity.field")); + + // make sure annotations go to the right place + File entityMetamodelSourceFile = new File(testDir, "target/generated-sources/annotations/org/acme/MyEntity_.java"); + assertThat(entityMetamodelSourceFile).exists().content().contains("FIELD"); + File entityQuerySourceFile = new File(testDir, "target/generated-sources/annotations/org/acme/QMyEntity.java"); + assertThat(entityQuerySourceFile).exists().content().contains("field"); + File entityMetamodelClassFile = new File(testDir, "target/classes/org/acme/MyEntity_.class"); + assertThat(entityMetamodelClassFile).exists(); + File entityQueryClassFile = new File(testDir, "target/classes/org/acme/QMyEntity.class"); + assertThat(entityQueryClassFile).exists(); + + // Edit the entity to change the field name + File source = new File(testDir, "src/main/java/org/acme/MyEntity.java"); + filter(source, Collections.singletonMap("String field;", "String field2;")); + + // Edit the "Hello" message for the new field. + source = new File(testDir, "src/main/java/org/acme/HelloResource.java"); + filter(source, Collections.singletonMap("return MyEntity_.FIELD+\"/\"+QMyEntity.myEntity.field;", + "return MyEntity_.FIELD2+\"/\"+QMyEntity.myEntity.field2;")); + + // Wait until we get "field2/field2" + await() + .pollDelay(100, TimeUnit.MILLISECONDS) + .atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES) + .until(() -> devModeClient.getHttpResponse("/hello").contains("field2/myEntity.field2")); + + // make sure annotations go to the right place + assertThat(entityMetamodelSourceFile).exists().content().contains("FIELD2"); + assertThat(entityQuerySourceFile).exists().content().contains("field2"); + assertThat(entityMetamodelClassFile).exists(); + assertThat(entityQueryClassFile).exists(); + } + + @Test + public void testThatAptInAnnotationProcessorPathsWorks() throws MavenInvocationException, IOException { + testDir = initProject("projects/apt-in-annotation-processor-paths", + "projects/project-apt-in-annotation-processor-paths"); + run(true); + + // same expectations as the classpath one: two APT plugins + + // wait until app is compiled and started + await() + .pollDelay(100, TimeUnit.MILLISECONDS) + .atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES) + .until(() -> devModeClient.getHttpResponse("/hello").contains("field/myEntity.field")); + + // make sure annotations go to the right place + File entityMetamodelSourceFile = new File(testDir, "target/generated-sources/annotations/org/acme/MyEntity_.java"); + assertThat(entityMetamodelSourceFile).exists().content().contains("FIELD"); + File entityQuerySourceFile = new File(testDir, "target/generated-sources/annotations/org/acme/QMyEntity.java"); + assertThat(entityQuerySourceFile).exists().content().contains("field"); + File entityMetamodelClassFile = new File(testDir, "target/classes/org/acme/MyEntity_.class"); + assertThat(entityMetamodelClassFile).exists(); + File entityQueryClassFile = new File(testDir, "target/classes/org/acme/QMyEntity.class"); + assertThat(entityQueryClassFile).exists(); + + // Edit the entity to change the field name + File source = new File(testDir, "src/main/java/org/acme/MyEntity.java"); + filter(source, Collections.singletonMap("String field;", "String field2;")); + + // Edit the "Hello" message for the new field. + source = new File(testDir, "src/main/java/org/acme/HelloResource.java"); + filter(source, Collections.singletonMap("return MyEntity_.FIELD+\"/\"+QMyEntity.myEntity.field;", + "return MyEntity_.FIELD2+\"/\"+QMyEntity.myEntity.field2;")); + + // Wait until we get "field2/field2" + await() + .pollDelay(100, TimeUnit.MILLISECONDS) + .atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES) + .until(() -> devModeClient.getHttpResponse("/hello").contains("field2/myEntity.field2")); + + // make sure annotations go to the right place + assertThat(entityMetamodelSourceFile).exists().content().contains("FIELD2"); + assertThat(entityQuerySourceFile).exists().content().contains("field2"); + assertThat(entityMetamodelClassFile).exists(); + assertThat(entityQueryClassFile).exists(); + } + + @Test + public void testThatAptInAnnotationProcessorsWorks() throws MavenInvocationException, IOException { + testDir = initProject("projects/apt-in-annotation-processors", + "projects/project-apt-in-annotation-processors"); + run(true); + + // NOT the same expectations as the classpath one: only the Hibernate APT plugin + + // wait until app is compiled and started + await() + .pollDelay(100, TimeUnit.MILLISECONDS) + .atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES) + .until(() -> devModeClient.getHttpResponse("/hello").contains("field")); + + // make sure annotations go to the right place + File entityMetamodelSourceFile = new File(testDir, "target/generated-sources/annotations/org/acme/MyEntity_.java"); + assertThat(entityMetamodelSourceFile).exists().content().contains("FIELD"); + File entityQuerySourceFile = new File(testDir, "target/generated-sources/annotations/org/acme/QMyEntity.java"); + assertThat(entityQuerySourceFile).doesNotExist(); + File entityMetamodelClassFile = new File(testDir, "target/classes/org/acme/MyEntity_.class"); + assertThat(entityMetamodelClassFile).exists(); + File entityQueryClassFile = new File(testDir, "target/classes/org/acme/QMyEntity.class"); + assertThat(entityQueryClassFile).doesNotExist(); + + // Edit the entity to change the field name + File source = new File(testDir, "src/main/java/org/acme/MyEntity.java"); + filter(source, Collections.singletonMap("String field;", "String field2;")); + + // Edit the "Hello" message for the new field. + source = new File(testDir, "src/main/java/org/acme/HelloResource.java"); + filter(source, Collections.singletonMap("return MyEntity_.FIELD;", + "return MyEntity_.FIELD2;")); + + // Wait until we get "field2" + await() + .pollDelay(100, TimeUnit.MILLISECONDS) + .atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES) + .until(() -> devModeClient.getHttpResponse("/hello").contains("field2")); + + // make sure annotations go to the right place + assertThat(entityMetamodelSourceFile).exists().content().contains("FIELD2"); + assertThat(entityQuerySourceFile).doesNotExist(); + assertThat(entityMetamodelClassFile).exists(); + assertThat(entityQueryClassFile).doesNotExist(); + } } diff --git a/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processor-paths/.env b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processor-paths/.env new file mode 100644 index 00000000000000..98fb9ae1398c6c --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processor-paths/.env @@ -0,0 +1 @@ +OTHER_GREETING=Hola \ No newline at end of file diff --git a/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processor-paths/pom.xml b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processor-paths/pom.xml new file mode 100644 index 00000000000000..eb0161c7a53d02 --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processor-paths/pom.xml @@ -0,0 +1,108 @@ + + + 4.0.0 + org.acme + acme + 1.0-SNAPSHOT + + io.quarkus + quarkus-bom + @project.version@ + @project.version@ + ${compiler-plugin.version} + UTF-8 + ${maven.compiler.source} + ${maven.compiler.target} + 5.0.0 + + + + + + \${quarkus.platform.group-id} + \${quarkus.platform.artifact-id} + \${quarkus.platform.version} + pom + import + + + + + + + io.quarkus + quarkus-resteasy-reactive + + + + jakarta.persistence + jakarta.persistence-api + + + com.querydsl + querydsl-jpa + \${querydsl.version} + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + + + maven-compiler-plugin + \${compiler-plugin.version} + + + + org.hibernate.orm + hibernate-jpamodelgen + + + com.querydsl + querydsl-apt + \${querydsl.version} + jakarta + + + + + + io.quarkus + quarkus-maven-plugin + \${quarkus-plugin.version} + + + + generate-code + generate-code-tests + build + + + + + + + + + native + + native + + + + customOutputDir + + target-other + + + + diff --git a/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processor-paths/src/main/java/org/acme/HelloResource.java b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processor-paths/src/main/java/org/acme/HelloResource.java new file mode 100644 index 00000000000000..1dd8b643b6d914 --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processor-paths/src/main/java/org/acme/HelloResource.java @@ -0,0 +1,16 @@ +package org.acme; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("/hello") +public class HelloResource { + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + return MyEntity_.FIELD+"/"+QMyEntity.myEntity.field; + } +} diff --git a/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processor-paths/src/main/java/org/acme/MyEntity.java b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processor-paths/src/main/java/org/acme/MyEntity.java new file mode 100644 index 00000000000000..1b2d9607ecf56e --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processor-paths/src/main/java/org/acme/MyEntity.java @@ -0,0 +1,11 @@ +package org.acme; + +import jakarta.persistence.Id; +import jakarta.persistence.Entity; + +@Entity +public class MyEntity { + public String field; + @Id + public String id; +} diff --git a/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processor-paths/src/main/resources/application.properties b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processor-paths/src/main/resources/application.properties new file mode 100644 index 00000000000000..fa4e0173f6e551 --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processor-paths/src/main/resources/application.properties @@ -0,0 +1,6 @@ +# Configuration file +quarkus.log.level=INFO +quarkus.log.file.enable=false +quarkus.log.console.format=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] (%t) %s%e%n +quarkus.log.file.format=%d{yyyy-MM-dd HH:mm:ss,SSS} %h %N[%i] %-5p [%c{3.}] (%t) %s%e%n +quarkus.log.category."io.quarkus".level=INFO diff --git a/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processor-paths/src/test/java/org/acme/HelloResourceTest.java b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processor-paths/src/test/java/org/acme/HelloResourceTest.java new file mode 100644 index 00000000000000..c2f29e2c9f7114 --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processor-paths/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")); + } + +} diff --git a/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processors/.env b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processors/.env new file mode 100644 index 00000000000000..98fb9ae1398c6c --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processors/.env @@ -0,0 +1 @@ +OTHER_GREETING=Hola \ No newline at end of file diff --git a/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processors/pom.xml b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processors/pom.xml new file mode 100644 index 00000000000000..0e49616e732f9f --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processors/pom.xml @@ -0,0 +1,113 @@ + + + 4.0.0 + org.acme + acme + 1.0-SNAPSHOT + + io.quarkus + quarkus-bom + @project.version@ + @project.version@ + ${compiler-plugin.version} + UTF-8 + ${maven.compiler.source} + ${maven.compiler.target} + 5.0.0 + + + + + + \${quarkus.platform.group-id} + \${quarkus.platform.artifact-id} + \${quarkus.platform.version} + pom + import + + + + + + + io.quarkus + quarkus-resteasy-reactive + + + + jakarta.persistence + jakarta.persistence-api + + + com.querydsl + querydsl-jpa + \${querydsl.version} + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + + + maven-compiler-plugin + \${compiler-plugin.version} + + + + + org.hibernate.orm + hibernate-jpamodelgen + + + com.querydsl + querydsl-apt + \${querydsl.version} + jakarta + + + + + org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor + + + + + io.quarkus + quarkus-maven-plugin + \${quarkus-plugin.version} + + + + generate-code + generate-code-tests + build + + + + + + + + + native + + native + + + + customOutputDir + + target-other + + + + diff --git a/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processors/src/main/java/org/acme/HelloResource.java b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processors/src/main/java/org/acme/HelloResource.java new file mode 100644 index 00000000000000..65c4293d92c306 --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processors/src/main/java/org/acme/HelloResource.java @@ -0,0 +1,16 @@ +package org.acme; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("/hello") +public class HelloResource { + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + return MyEntity_.FIELD; + } +} diff --git a/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processors/src/main/java/org/acme/MyEntity.java b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processors/src/main/java/org/acme/MyEntity.java new file mode 100644 index 00000000000000..1b2d9607ecf56e --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processors/src/main/java/org/acme/MyEntity.java @@ -0,0 +1,11 @@ +package org.acme; + +import jakarta.persistence.Id; +import jakarta.persistence.Entity; + +@Entity +public class MyEntity { + public String field; + @Id + public String id; +} diff --git a/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processors/src/main/resources/application.properties b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processors/src/main/resources/application.properties new file mode 100644 index 00000000000000..fa4e0173f6e551 --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processors/src/main/resources/application.properties @@ -0,0 +1,6 @@ +# Configuration file +quarkus.log.level=INFO +quarkus.log.file.enable=false +quarkus.log.console.format=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] (%t) %s%e%n +quarkus.log.file.format=%d{yyyy-MM-dd HH:mm:ss,SSS} %h %N[%i] %-5p [%c{3.}] (%t) %s%e%n +quarkus.log.category."io.quarkus".level=INFO diff --git a/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processors/src/test/java/org/acme/HelloResourceTest.java b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processors/src/test/java/org/acme/HelloResourceTest.java new file mode 100644 index 00000000000000..c2f29e2c9f7114 --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-annotation-processors/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")); + } + +} diff --git a/integration-tests/maven/src/test/resources-filtered/projects/apt-in-classpath/.env b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-classpath/.env new file mode 100644 index 00000000000000..98fb9ae1398c6c --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-classpath/.env @@ -0,0 +1 @@ +OTHER_GREETING=Hola \ No newline at end of file diff --git a/integration-tests/maven/src/test/resources-filtered/projects/apt-in-classpath/pom.xml b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-classpath/pom.xml new file mode 100644 index 00000000000000..0380cc590d9c3c --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-classpath/pom.xml @@ -0,0 +1,113 @@ + + + 4.0.0 + org.acme + acme + 1.0-SNAPSHOT + + io.quarkus + quarkus-bom + @project.version@ + @project.version@ + ${compiler-plugin.version} + UTF-8 + ${maven.compiler.source} + ${maven.compiler.target} + 5.0.0 + + + + + + \${quarkus.platform.group-id} + \${quarkus.platform.artifact-id} + \${quarkus.platform.version} + pom + import + + + + + + + io.quarkus + quarkus-resteasy-reactive + + + + jakarta.persistence + jakarta.persistence-api + + + + org.antlr + antlr4-runtime + provided + + + org.hibernate.orm + hibernate-jpamodelgen + provided + + + + com.querydsl + querydsl-jpa + \${querydsl.version} + + + com.querydsl + querydsl-apt + \${querydsl.version} + provided + jakarta + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + + + maven-compiler-plugin + \${compiler-plugin.version} + + + io.quarkus + quarkus-maven-plugin + \${quarkus-plugin.version} + + + + generate-code + generate-code-tests + build + + + + + + + + + native + + native + + + + customOutputDir + + target-other + + + + diff --git a/integration-tests/maven/src/test/resources-filtered/projects/apt-in-classpath/src/main/java/org/acme/HelloResource.java b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-classpath/src/main/java/org/acme/HelloResource.java new file mode 100644 index 00000000000000..1dd8b643b6d914 --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-classpath/src/main/java/org/acme/HelloResource.java @@ -0,0 +1,16 @@ +package org.acme; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("/hello") +public class HelloResource { + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + return MyEntity_.FIELD+"/"+QMyEntity.myEntity.field; + } +} diff --git a/integration-tests/maven/src/test/resources-filtered/projects/apt-in-classpath/src/main/java/org/acme/MyEntity.java b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-classpath/src/main/java/org/acme/MyEntity.java new file mode 100644 index 00000000000000..1b2d9607ecf56e --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-classpath/src/main/java/org/acme/MyEntity.java @@ -0,0 +1,11 @@ +package org.acme; + +import jakarta.persistence.Id; +import jakarta.persistence.Entity; + +@Entity +public class MyEntity { + public String field; + @Id + public String id; +} diff --git a/integration-tests/maven/src/test/resources-filtered/projects/apt-in-classpath/src/main/resources/application.properties b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-classpath/src/main/resources/application.properties new file mode 100644 index 00000000000000..fa4e0173f6e551 --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-classpath/src/main/resources/application.properties @@ -0,0 +1,6 @@ +# Configuration file +quarkus.log.level=INFO +quarkus.log.file.enable=false +quarkus.log.console.format=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] (%t) %s%e%n +quarkus.log.file.format=%d{yyyy-MM-dd HH:mm:ss,SSS} %h %N[%i] %-5p [%c{3.}] (%t) %s%e%n +quarkus.log.category."io.quarkus".level=INFO diff --git a/integration-tests/maven/src/test/resources-filtered/projects/apt-in-classpath/src/test/java/org/acme/HelloResourceTest.java b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-classpath/src/test/java/org/acme/HelloResourceTest.java new file mode 100644 index 00000000000000..c2f29e2c9f7114 --- /dev/null +++ b/integration-tests/maven/src/test/resources-filtered/projects/apt-in-classpath/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")); + } + +}