From 10590d058e238a07479f42cc6075c88c40cc7b99 Mon Sep 17 00:00:00 2001 From: Auri Munoz Date: Wed, 7 Oct 2020 13:46:59 +0200 Subject: [PATCH] feat: add codestart spring-web refactor: resteasy not needed here, quarkus-spring-web already depends on it. --- .../spring-web-example/base/README.md | 5 + .../META-INF/resources/spring.tpl.qute.html | 154 ++++++++++++++++++ .../examples/spring-web-example/codestart.yml | 16 ++ .../{resource.class-name}.tpl.qute.java | 15 ++ ...ative{resource.class-name}IT.tpl.qute.java | 9 + .../{resource.class-name}Test.tpl.qute.java | 21 +++ .../{resource.class-name}.tpl.qute.kt | 14 ++ .../Native{resource.class-name}IT.tpl.qute.kt | 6 + .../{resource.class-name}Test.tpl.qute.kt | 20 +++ .../{resource.class-name}.tpl.qute.scala | 12 ++ ...tive{resource.class-name}IT.tpl.qute.scala | 6 + .../{resource.class-name}Test.tpl.qute.scala | 20 +++ .../resources/META-INF/quarkus-extension.yaml | 1 + .../codestarts/QuarkusCodestartData.java | 4 + .../codestarts/QuarkusCodestartRunIT.java | 13 ++ 15 files changed, 316 insertions(+) create mode 100644 devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/base/README.md create mode 100644 devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/base/src/main/resources/META-INF/resources/spring.tpl.qute.html create mode 100644 devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/codestart.yml create mode 100644 devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/java/src/main/java/{package-name.dir}/{resource.class-name}.tpl.qute.java create mode 100644 devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/java/src/native-test/java/{package-name.dir}/Native{resource.class-name}IT.tpl.qute.java create mode 100644 devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/java/src/test/java/{package-name.dir}/{resource.class-name}Test.tpl.qute.java create mode 100644 devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/kotlin/src/main/kotlin/{package-name.dir}/{resource.class-name}.tpl.qute.kt create mode 100644 devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/kotlin/src/native-test/kotlin/{package-name.dir}/Native{resource.class-name}IT.tpl.qute.kt create mode 100644 devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/kotlin/src/test/kotlin/{package-name.dir}/{resource.class-name}Test.tpl.qute.kt create mode 100644 devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/scala/src/main/scala/{package-name.dir}/{resource.class-name}.tpl.qute.scala create mode 100644 devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/scala/src/native-test/scala/{package-name.dir}/Native{resource.class-name}IT.tpl.qute.scala create mode 100644 devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/scala/src/test/scala/{package-name.dir}/{resource.class-name}Test.tpl.qute.scala diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/base/README.md b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/base/README.md new file mode 100644 index 0000000000000..54f816d501286 --- /dev/null +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/base/README.md @@ -0,0 +1,5 @@ +# Spring Web + +Guide: https://quarkus.io/guides/spring-web + + diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/base/src/main/resources/META-INF/resources/spring.tpl.qute.html b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/base/src/main/resources/META-INF/resources/spring.tpl.qute.html new file mode 100644 index 0000000000000..96055ea138a69 --- /dev/null +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/base/src/main/resources/META-INF/resources/spring.tpl.qute.html @@ -0,0 +1,154 @@ + + + + + {project.artifact-id} - {project.version} + + + + + + +
+
+

Congratulations, you have created a new Quarkus application with Spring Web.

+ +

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: {buildtool.cmd.dev}. +

+
    +
  • Open the example "/hello" endpoint
  • +
  • Add REST resources, Servlets, functions and other services in {language.dir.code}.
  • +
  • Your static assets are located in src/main/resources/META-INF/resources.
  • +
  • Configure your application in src/main/resources/{config.file-name}. +
  • +
+ +

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: {project.group-id}
  • +
  • ArtifactId: {project.artifact-id}
  • +
  • Version: {project.version}
  • +
  • Quarkus Version: {quarkus.version}
  • +
+
+ +
+
+ + \ No newline at end of file diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/codestart.yml b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/codestart.yml new file mode 100644 index 0000000000000..0ed97979df74d --- /dev/null +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/codestart.yml @@ -0,0 +1,16 @@ +name: spring-web-example +ref: spring-web +type: code +tags: example +language: + base: + data: + resource: + class-name: ExampleController + path: "/springweb/hello" + response: "hello" + package-name: org.acme.spring.web + dependencies: + - io.quarkus:quarkus-spring-web + test-dependencies: + - io.rest-assured:rest-assured diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/java/src/main/java/{package-name.dir}/{resource.class-name}.tpl.qute.java b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/java/src/main/java/{package-name.dir}/{resource.class-name}.tpl.qute.java new file mode 100644 index 0000000000000..00ba35e9a7397 --- /dev/null +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/java/src/main/java/{package-name.dir}/{resource.class-name}.tpl.qute.java @@ -0,0 +1,15 @@ +package {package-name}; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("{resource.path}") +public class {resource.class-name} { + + @GetMapping + public String hello() { + return "{resource.response}"; + } +} diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/java/src/native-test/java/{package-name.dir}/Native{resource.class-name}IT.tpl.qute.java b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/java/src/native-test/java/{package-name.dir}/Native{resource.class-name}IT.tpl.qute.java new file mode 100644 index 0000000000000..8c54cc543b42f --- /dev/null +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/java/src/native-test/java/{package-name.dir}/Native{resource.class-name}IT.tpl.qute.java @@ -0,0 +1,9 @@ +package {package-name}; + +import io.quarkus.test.junit.NativeImageTest; + +@NativeImageTest +public class Native{resource.class-name}IT extends {resource.class-name}Test { + + // Execute the same tests but in native mode. +} \ No newline at end of file diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/java/src/test/java/{package-name.dir}/{resource.class-name}Test.tpl.qute.java b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/java/src/test/java/{package-name.dir}/{resource.class-name}Test.tpl.qute.java new file mode 100644 index 0000000000000..0dfcaaf81c355 --- /dev/null +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/java/src/test/java/{package-name.dir}/{resource.class-name}Test.tpl.qute.java @@ -0,0 +1,21 @@ +package {package-name}; + +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 {resource.class-name}Test { + + @Test + public void testHelloEndpoint() { + given() + .when().get("{resource.path}") + .then() + .statusCode(200) + .body(is("{resource.response}")); + } + +} \ No newline at end of file diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/kotlin/src/main/kotlin/{package-name.dir}/{resource.class-name}.tpl.qute.kt b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/kotlin/src/main/kotlin/{package-name.dir}/{resource.class-name}.tpl.qute.kt new file mode 100644 index 0000000000000..22ac45c764198 --- /dev/null +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/kotlin/src/main/kotlin/{package-name.dir}/{resource.class-name}.tpl.qute.kt @@ -0,0 +1,14 @@ +package {package-name} + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + +@RestController +@RequestMapping("{resource.path}") +class {resource.class-name} { + + @GetMapping + fun hello() = "{resource.response}" +} \ No newline at end of file diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/kotlin/src/native-test/kotlin/{package-name.dir}/Native{resource.class-name}IT.tpl.qute.kt b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/kotlin/src/native-test/kotlin/{package-name.dir}/Native{resource.class-name}IT.tpl.qute.kt new file mode 100644 index 0000000000000..e4d92d1565b50 --- /dev/null +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/kotlin/src/native-test/kotlin/{package-name.dir}/Native{resource.class-name}IT.tpl.qute.kt @@ -0,0 +1,6 @@ +package {package-name} + +import io.quarkus.test.junit.NativeImageTest + +@NativeImageTest +class Native{resource.class-name}IT : {resource.class-name}Test() \ No newline at end of file diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/kotlin/src/test/kotlin/{package-name.dir}/{resource.class-name}Test.tpl.qute.kt b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/kotlin/src/test/kotlin/{package-name.dir}/{resource.class-name}Test.tpl.qute.kt new file mode 100644 index 0000000000000..e130d90936ea7 --- /dev/null +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/kotlin/src/test/kotlin/{package-name.dir}/{resource.class-name}Test.tpl.qute.kt @@ -0,0 +1,20 @@ +package {package-name} + +import io.quarkus.test.junit.QuarkusTest +import io.restassured.RestAssured.given +import org.hamcrest.CoreMatchers.`is` +import org.junit.jupiter.api.Test + +@QuarkusTest +class {resource.class-name}Test { + + @Test + fun testHelloEndpoint() { + given() + .`when`().get("{resource.path}") + .then() + .statusCode(200) + .body(`is`("{resource.response}")) + } + +} \ No newline at end of file diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/scala/src/main/scala/{package-name.dir}/{resource.class-name}.tpl.qute.scala b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/scala/src/main/scala/{package-name.dir}/{resource.class-name}.tpl.qute.scala new file mode 100644 index 0000000000000..84a2e57b6c75c --- /dev/null +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/scala/src/main/scala/{package-name.dir}/{resource.class-name}.tpl.qute.scala @@ -0,0 +1,12 @@ +package {package-name}; + +import org.springframework.web.bind.annotation.\{GetMapping, RequestMapping, RestController} + + +@RestController +@RequestMapping(Array[String]("{resource.path}")) +class {resource.class-name} { + + @GetMapping + def hello() = "{resource.response}" +} \ No newline at end of file diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/scala/src/native-test/scala/{package-name.dir}/Native{resource.class-name}IT.tpl.qute.scala b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/scala/src/native-test/scala/{package-name.dir}/Native{resource.class-name}IT.tpl.qute.scala new file mode 100644 index 0000000000000..04622a9647ada --- /dev/null +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/scala/src/native-test/scala/{package-name.dir}/Native{resource.class-name}IT.tpl.qute.scala @@ -0,0 +1,6 @@ +package {package-name} + +import io.quarkus.test.junit.NativeImageTest + +@NativeImageTest +class Native{resource.class-name}IT extends {resource.class-name}Test \ No newline at end of file diff --git a/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/scala/src/test/scala/{package-name.dir}/{resource.class-name}Test.tpl.qute.scala b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/scala/src/test/scala/{package-name.dir}/{resource.class-name}Test.tpl.qute.scala new file mode 100644 index 0000000000000..1ac6d66c15948 --- /dev/null +++ b/devtools/platform-descriptor-json/src/main/resources/codestarts/quarkus/core/examples/spring-web-example/scala/src/test/scala/{package-name.dir}/{resource.class-name}Test.tpl.qute.scala @@ -0,0 +1,20 @@ +package {package-name} + +import io.quarkus.test.junit.QuarkusTest +import io.restassured.RestAssured.given +import org.hamcrest.CoreMatchers.`is` +import org.junit.jupiter.api.Test + +@QuarkusTest +class {resource.class-name}Test { + + @Test + def testHelloEndpoint() = { + given() + .`when`().get("{resource.path}") + .then() + .statusCode(200) + .body(`is`("{resource.response}")) + } + +} \ No newline at end of file diff --git a/extensions/spring-web/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/spring-web/runtime/src/main/resources/META-INF/quarkus-extension.yaml index 4cfecc3dc96cf..c7ac7ceb408ce 100644 --- a/extensions/spring-web/runtime/src/main/resources/META-INF/quarkus-extension.yaml +++ b/extensions/spring-web/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -8,3 +8,4 @@ metadata: categories: - "compatibility" status: "preview" + codestart: "spring-web" diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/QuarkusCodestartData.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/QuarkusCodestartData.java index 443fce570eb16..68c6cd79d51cc 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/QuarkusCodestartData.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/QuarkusCodestartData.java @@ -32,6 +32,10 @@ public enum DataKey { RESTEASY_EXAMPLE_PACKAGE_NAME("resteasy-example.package-name"), RESTEASY_EXAMPLE_RESOURCE_CLASS_NAME("resteasy-example.resource.class-name"), + SPRING_WEB_EXAMPLE_RESOURCE_PATH("spring-web-example.resource.path"), + SPRING_WEB_EXAMPLE_PACKAGE_NAME("spring-web-example.package-name"), + SPRING_WEB_EXAMPLE_RESOURCE_CLASS_NAME("spring-web-example.resource.class-name"), + COMMANDMODE_EXAMPLE_PACKAGE_NAME("commandmode-example.package-name"), COMMANDMODE_EXAMPLE_RESOURCE_CLASS_NAME("commandmode-example.main.class-name"), diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/QuarkusCodestartRunIT.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/QuarkusCodestartRunIT.java index 45d2a701bc9af..0f86a60776f48 100644 --- a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/QuarkusCodestartRunIT.java +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/QuarkusCodestartRunIT.java @@ -106,6 +106,19 @@ public void generateCustomizedRESTEasyProjectRun() throws Exception { genName(buildTool, language, codestarts) + "-customized"); } + @Test + public void generateCustomizedSpringWebProjectRun() throws Exception { + final HashMap data = new HashMap<>(); + data.put(DataKey.SPRING_WEB_EXAMPLE_PACKAGE_NAME.getKey(), "com.test.spring.web"); + data.put(DataKey.SPRING_WEB_EXAMPLE_RESOURCE_CLASS_NAME.getKey(), "SpringWebEndpoint"); + data.put(DataKey.SPRING_WEB_EXAMPLE_RESOURCE_PATH.getKey(), "/springweb"); + final String buildTool = "maven"; + final String language = "java"; + final List codestarts = Collections.singletonList("spring-web-example"); + generateProjectRunTests(buildTool, language, codestarts, data, + genName(buildTool, language, codestarts) + "-customized"); + } + @Test public void generateCustomizedCommandModeProjectRun() throws Exception { final HashMap data = new HashMap<>();