From 0cb45f22e9fe068ed860ff1ca2e1955170c99e82 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Fri, 10 Nov 2023 22:01:06 +1100 Subject: [PATCH] feat: scaffold new Kotlin projects in a more idiomatic way (#584) Also added an integration test that verifies that `ftl init kotlin` works. --- Procfile.integration | 1 + cmd/ftl/cmd_init.go | 6 +++-- .../ftl.toml | 0 .../ftl-module-{{ .Name | lower }}/pom.xml | 9 ++++++++ .../{{ .Name | camel }}.kt | 0 kotlin-runtime/scaffolding/pom.xml | 22 ++++++++++--------- scripts/integration-tests | 15 ++++++++++++- 7 files changed, 40 insertions(+), 13 deletions(-) rename kotlin-runtime/scaffolding/{ => ftl-module-{{ .Name | lower }}}/ftl.toml (100%) create mode 100644 kotlin-runtime/scaffolding/ftl-module-{{ .Name | lower }}/pom.xml rename kotlin-runtime/scaffolding/{ => ftl-module-{{ .Name | lower }}}/src/main/kotlin/ftl/{{ .Name | camel | lower }}/{{ .Name | camel }}.kt (100%) diff --git a/Procfile.integration b/Procfile.integration index 62f55f6384..03a1bd20d0 100644 --- a/Procfile.integration +++ b/Procfile.integration @@ -1,3 +1,4 @@ controller: build/release/ftl-controller --key C01H5BRT09Y07547SETZ4HWRA09 --bind http://localhost:8892 runner0: build/release/ftl-runner --key R01H5BTS6ABP1EHGZSAGJMBV50A --language go --language kotlin --bind http://localhost:8894 --template-dir build/template --deployment-dir build/runner0 runner1: build/release/ftl-runner --key R01H5BTSGKQ8AZ9S22N9N1SM9HV --language go --language kotlin --bind http://localhost:8895 --template-dir build/template --deployment-dir build/runner1 +runner2: build/release/ftl-runner --key R01H8DD0Z5GRT3QP1MBARC4TW08 --language go --language kotlin --bind http://localhost:8896 --template-dir build/template --deployment-dir build/runner2 diff --git a/cmd/ftl/cmd_init.go b/cmd/ftl/cmd_init.go index 1982580adf..e48001c077 100644 --- a/cmd/ftl/cmd_init.go +++ b/cmd/ftl/cmd_init.go @@ -31,8 +31,10 @@ func (i initGoCmd) Run(parent *initCmd) error { } type initKotlinCmd struct { - Dir string `arg:"" default:"." help:"Directory to initialize the module in."` - Name string `short:"n" help:"Name of the FTL module (defaults to name of directory)."` + GroupID string `short:"g" help:"Base Maven group ID (defaults to \"ftl\")." default:"ftl"` + ArtifactID string `short:"a" help:"Base Maven artifact ID (defaults to \"ftl\")." default:"ftl"` + Name string `short:"n" help:"Name of the FTL module (defaults to name of directory)."` + Dir string `arg:"" default:"." help:"Directory to initialize the module in."` } func (i *initKotlinCmd) Run(parent *initCmd) error { diff --git a/kotlin-runtime/scaffolding/ftl.toml b/kotlin-runtime/scaffolding/ftl-module-{{ .Name | lower }}/ftl.toml similarity index 100% rename from kotlin-runtime/scaffolding/ftl.toml rename to kotlin-runtime/scaffolding/ftl-module-{{ .Name | lower }}/ftl.toml diff --git a/kotlin-runtime/scaffolding/ftl-module-{{ .Name | lower }}/pom.xml b/kotlin-runtime/scaffolding/ftl-module-{{ .Name | lower }}/pom.xml new file mode 100644 index 0000000000..de80aa3c16 --- /dev/null +++ b/kotlin-runtime/scaffolding/ftl-module-{{ .Name | lower }}/pom.xml @@ -0,0 +1,9 @@ + + + 4.0.0 + ftl + ftl-module-{{ .Name | camel | lower }} + 1.0-SNAPSHOT + \ No newline at end of file diff --git a/kotlin-runtime/scaffolding/src/main/kotlin/ftl/{{ .Name | camel | lower }}/{{ .Name | camel }}.kt b/kotlin-runtime/scaffolding/ftl-module-{{ .Name | lower }}/src/main/kotlin/ftl/{{ .Name | camel | lower }}/{{ .Name | camel }}.kt similarity index 100% rename from kotlin-runtime/scaffolding/src/main/kotlin/ftl/{{ .Name | camel | lower }}/{{ .Name | camel }}.kt rename to kotlin-runtime/scaffolding/ftl-module-{{ .Name | lower }}/src/main/kotlin/ftl/{{ .Name | camel | lower }}/{{ .Name | camel }}.kt diff --git a/kotlin-runtime/scaffolding/pom.xml b/kotlin-runtime/scaffolding/pom.xml index 4068a27bd7..42d0dd3d5d 100644 --- a/kotlin-runtime/scaffolding/pom.xml +++ b/kotlin-runtime/scaffolding/pom.xml @@ -1,12 +1,19 @@ - + - 4.0.0 - ftl - ftl-module-{{ .Name | camel | lower }} + + {{ .GroupID }} + {{ .ArtifactID }} 1.0-SNAPSHOT + pom + + + ftl-module-{{ .Name | camel | lower }} + + 1.0-SNAPSHOT 11 @@ -27,11 +34,6 @@ ftl-runtime ${ftl.version} - - xyz.block - ftl-generator - ${ftl.version} - diff --git a/scripts/integration-tests b/scripts/integration-tests index 443c83f981..dee5eff0ee 100755 --- a/scripts/integration-tests +++ b/scripts/integration-tests @@ -57,6 +57,15 @@ deploy_echo_kotlin() ( ftl deploy target ) +deploy_fresh_kotlin() ( + info "Deploying newly initialised Kotlin module" + rm -rf build/echo2 + ftl init kotlin -n echo2 build/echo2 + cd build/echo2 + mvn compile + ftl deploy target +) + deploy_time_go() ( info "Deploying time" cd examples @@ -66,7 +75,7 @@ deploy_time_go() ( ) wait_for_deploys() { - wait_for "deployments to come up" 'ftl status | jq -r ".routes[].module" | sort | paste -sd " " - | grep -q "echo time"' + wait_for "deployments to come up" 'ftl status | jq -r ".routes[].module" | sort | paste -sd " " - | grep -q "echo echo2 time"' } build_release @@ -76,10 +85,14 @@ start_cluster # Cluster is up, start interacting with it. deploy_time_go deploy_echo_kotlin +deploy_fresh_kotlin wait_for_deploys info "Calling echo" message="$(ftl call echo.echo '{"name": "Alice"}' | jq -r .message)" [[ "$message" =~ "Hello, Alice! The time is " ]] || error "Unexpected response from echo: $message" + +message="$(ftl call echo2.echo '{"name": "Alice"}' | jq -r .message)" +[[ "$message" =~ "Hello, Alice!" ]] || error "Unexpected response from echo2: $message" info "Success!"