Skip to content

Commit

Permalink
feat: scaffold new Kotlin projects in a more idiomatic way (#584)
Browse files Browse the repository at this point in the history
Also added an integration test that verifies that `ftl init kotlin`
works.
  • Loading branch information
alecthomas authored Nov 10, 2023
1 parent 40525ee commit 0cb45f2
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 13 deletions.
1 change: 1 addition & 0 deletions Procfile.integration
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions cmd/ftl/cmd_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>ftl</groupId>
<artifactId>ftl-module-{{ .Name | camel | lower }}</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
22 changes: 12 additions & 10 deletions kotlin-runtime/scaffolding/pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>ftl</groupId>
<artifactId>ftl-module-{{ .Name | camel | lower }}</artifactId>

<groupId>{{ .GroupID }}</groupId>
<artifactId>{{ .ArtifactID }}</artifactId>
<version>1.0-SNAPSHOT</version>

<packaging>pom</packaging>

<modules>
<module>ftl-module-{{ .Name | camel | lower }}</module>
</modules>

<properties>
<ftl.version>1.0-SNAPSHOT</ftl.version>
<java.version>11</java.version>
Expand All @@ -27,11 +34,6 @@
<artifactId>ftl-runtime</artifactId>
<version>${ftl.version}</version>
</dependency>
<dependency>
<groupId>xyz.block</groupId>
<artifactId>ftl-generator</artifactId>
<version>${ftl.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
15 changes: 14 additions & 1 deletion scripts/integration-tests
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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!"

0 comments on commit 0cb45f2

Please sign in to comment.