From 6ee3281627f1937faac71b0952c2df4316bbe70b Mon Sep 17 00:00:00 2001 From: Edgar Espina Date: Sun, 15 Sep 2024 17:21:33 -0300 Subject: [PATCH] jooby-apt: turn off Route.setMvcMethod and Route.setReturnType by default - fix #3529 --- docs/asciidoc/mvc-api.adoc | 5 +++++ jooby/src/main/java/io/jooby/Route.java | 3 ++- .../src/main/java/io/jooby/internal/apt/MvcContext.java | 4 ++-- .../jooby-apt/src/test/java/tests/ModuleCompilerTest.java | 4 ++-- modules/jooby-apt/src/test/java/tests/i1814/Issue1814.java | 4 +++- modules/jooby-apt/src/test/java/tests/i2629/Issue2629.java | 3 ++- modules/jooby-apt/src/test/java/tests/i2629/Issue2629b.java | 4 +++- modules/jooby-apt/src/test/java/tests/i3490/Issue3490.java | 3 ++- 8 files changed, 21 insertions(+), 9 deletions(-) diff --git a/docs/asciidoc/mvc-api.adoc b/docs/asciidoc/mvc-api.adoc index e6ec6248f4..baed97d098 100644 --- a/docs/asciidoc/mvc-api.adoc +++ b/docs/asciidoc/mvc-api.adoc @@ -912,6 +912,11 @@ on them (mostly annotations processors). |string |[] |Add custom handler mapping. + +|jooby.mvcMethod +|boolean +|false +|Set the Route.mvcMethod when true. |=== ==== Setting options diff --git a/jooby/src/main/java/io/jooby/Route.java b/jooby/src/main/java/io/jooby/Route.java index 79a45968d4..6d320ae57b 100644 --- a/jooby/src/main/java/io/jooby/Route.java +++ b/jooby/src/main/java/io/jooby/Route.java @@ -1041,7 +1041,8 @@ public boolean isTransactional(boolean defaultValue) { } /** - * Method for MVC/Controller. Not available for lambda routes. + * Method for MVC/Controller available when jooby.mvcMethod processor option is set + * to true. Not available for lambda routes. * * @return Method for MVC/Controller. Not available for lambda routes. */ diff --git a/modules/jooby-apt/src/main/java/io/jooby/internal/apt/MvcContext.java b/modules/jooby-apt/src/main/java/io/jooby/internal/apt/MvcContext.java index 0ca1d61a0a..1ab605191c 100644 --- a/modules/jooby-apt/src/main/java/io/jooby/internal/apt/MvcContext.java +++ b/modules/jooby-apt/src/main/java/io/jooby/internal/apt/MvcContext.java @@ -44,8 +44,8 @@ public MvcContext( this.output = output; this.debug = Options.boolOpt(processingEnvironment, Options.DEBUG, false); this.incremental = Options.boolOpt(processingEnvironment, Options.INCREMENTAL, true); - this.returnType = Options.boolOpt(processingEnvironment, Options.RETURN_TYPE, true); - this.mvcMethod = Options.boolOpt(processingEnvironment, Options.MVC_METHOD, true); + this.returnType = Options.boolOpt(processingEnvironment, Options.RETURN_TYPE, false); + this.mvcMethod = Options.boolOpt(processingEnvironment, Options.MVC_METHOD, false); this.services = Options.boolOpt(processingEnvironment, Options.SERVICES, true); this.routerPrefix = Options.string(processingEnvironment, Options.ROUTER_PREFIX, ""); this.routerSuffix = Options.string(processingEnvironment, Options.ROUTER_SUFFIX, "_"); diff --git a/modules/jooby-apt/src/test/java/tests/ModuleCompilerTest.java b/modules/jooby-apt/src/test/java/tests/ModuleCompilerTest.java index 405f8d4b5d..f7071fbb0d 100644 --- a/modules/jooby-apt/src/test/java/tests/ModuleCompilerTest.java +++ b/modules/jooby-apt/src/test/java/tests/ModuleCompilerTest.java @@ -81,7 +81,7 @@ public void arrayRoute() throws Exception { @Test public void routes() throws Exception { - new ProcessorRunner(new Routes()) + new ProcessorRunner(new Routes(), Map.of("jooby.returnType", true)) .withRouter( app -> { MockRouter router = new MockRouter(app); @@ -263,7 +263,7 @@ public void noTopLevel() throws Exception { @Test public void setPrimitiveReturnType() throws Exception { - new ProcessorRunner(new PrimitiveReturnType()) + new ProcessorRunner(new PrimitiveReturnType(), Map.of("jooby.returnType", true)) .withRouter( app -> { Route route = app.getRoutes().get(0); diff --git a/modules/jooby-apt/src/test/java/tests/i1814/Issue1814.java b/modules/jooby-apt/src/test/java/tests/i1814/Issue1814.java index be419cf8fd..80d55acbdd 100644 --- a/modules/jooby-apt/src/test/java/tests/i1814/Issue1814.java +++ b/modules/jooby-apt/src/test/java/tests/i1814/Issue1814.java @@ -7,6 +7,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.Map; + import org.junit.jupiter.api.Test; import io.jooby.apt.ProcessorRunner; @@ -17,7 +19,7 @@ public class Issue1814 { @Test public void shouldIgnoreWildcardResponseType() throws Exception { - new ProcessorRunner(new C1814()) + new ProcessorRunner(new C1814(), Map.of("jooby.returnType", true)) .withRouter( app -> { MockRouter router = new MockRouter(app); diff --git a/modules/jooby-apt/src/test/java/tests/i2629/Issue2629.java b/modules/jooby-apt/src/test/java/tests/i2629/Issue2629.java index 90bf7f8cda..75e4a8aca6 100644 --- a/modules/jooby-apt/src/test/java/tests/i2629/Issue2629.java +++ b/modules/jooby-apt/src/test/java/tests/i2629/Issue2629.java @@ -9,6 +9,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.List; +import java.util.Map; import org.junit.jupiter.api.Test; @@ -20,7 +21,7 @@ public class Issue2629 { @Test public void shouldSetMvcMethod() throws Exception { - new ProcessorRunner(new C2629()) + new ProcessorRunner(new C2629(), Map.of("jooby.mvcMethod", true)) .withRouter( app -> { MockRouter router = new MockRouter(app); diff --git a/modules/jooby-apt/src/test/java/tests/i2629/Issue2629b.java b/modules/jooby-apt/src/test/java/tests/i2629/Issue2629b.java index 95823c3a5c..8afb134b32 100644 --- a/modules/jooby-apt/src/test/java/tests/i2629/Issue2629b.java +++ b/modules/jooby-apt/src/test/java/tests/i2629/Issue2629b.java @@ -8,6 +8,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import java.util.Map; + import org.junit.jupiter.api.Test; import io.jooby.apt.ProcessorRunner; @@ -18,7 +20,7 @@ public class Issue2629b { @Test public void shouldSetMvcMethod() throws Exception { - new ProcessorRunner(new C2629b()) + new ProcessorRunner(new C2629b(), Map.of("jooby.mvcMethod", true)) .withRouter( app -> { MockRouter router = new MockRouter(app); diff --git a/modules/jooby-apt/src/test/java/tests/i3490/Issue3490.java b/modules/jooby-apt/src/test/java/tests/i3490/Issue3490.java index b868a7ccbb..62e6d2c3ec 100644 --- a/modules/jooby-apt/src/test/java/tests/i3490/Issue3490.java +++ b/modules/jooby-apt/src/test/java/tests/i3490/Issue3490.java @@ -8,6 +8,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; +import java.util.Map; import org.junit.jupiter.api.Test; @@ -17,7 +18,7 @@ public class Issue3490 { @Test public void shouldNotGeneratePrimitiveOnKotlinGenerics() throws IOException { - new ProcessorRunner(new C3490()) + new ProcessorRunner(new C3490(), Map.of("jooby.returnType", true)) .withSourceCode( true, source -> {