Skip to content

Commit

Permalink
feat: Extract Java and Kotlin runtimes into seperate artifacts. (#2380)
Browse files Browse the repository at this point in the history
At present the only difference is code gen and some dependencies.
  • Loading branch information
stuartwdouglas authored Aug 15, 2024
1 parent 34e9734 commit ebb66ad
Show file tree
Hide file tree
Showing 96 changed files with 981 additions and 399 deletions.
4 changes: 2 additions & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ clean:
rm -rf frontend/node_modules
find . -name '*.zip' -exec rm {} \;
mvn -f kotlin-runtime/ftl-runtime clean
mvn -f java-runtime/ftl-runtime clean
mvn -f jvm-runtime/ftl-runtime clean

# Live rebuild the ftl binary whenever source changes.
live-rebuild:
Expand Down Expand Up @@ -66,7 +66,7 @@ build-backend:
just build ftl ftl-controller ftl-runner

build-java *args:
mvn -f java-runtime/ftl-runtime install {{args}}
mvn -f jvm-runtime/ftl-runtime install {{args}}

export DATABASE_URL := "postgres://postgres:secret@localhost:15432/ftl?sslmode=disable"

Expand Down
2 changes: 1 addition & 1 deletion backend/controller/cronjobs/testdata/java/cron/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<dependencies>
<dependency>
<groupId>xyz.block</groupId>
<groupId>xyz.block.ftl</groupId>
<artifactId>ftl-java-runtime</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion backend/controller/leases/testdata/java/leases/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<dependencies>
<dependency>
<groupId>xyz.block</groupId>
<groupId>xyz.block.ftl</groupId>
<artifactId>ftl-java-runtime</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion backend/controller/pubsub/testdata/java/publisher/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<dependencies>
<dependency>
<groupId>xyz.block</groupId>
<groupId>xyz.block.ftl</groupId>
<artifactId>ftl-java-runtime</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion backend/controller/pubsub/testdata/java/subscriber/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<dependencies>
<dependency>
<groupId>xyz.block</groupId>
<groupId>xyz.block.ftl</groupId>
<artifactId>ftl-java-runtime</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion examples/kotlin/echo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<dependencies>
<dependency>
<groupId>xyz.block</groupId>
<groupId>xyz.block.ftl</groupId>
<artifactId>ftl-java-runtime</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion examples/kotlin/time/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<dependencies>
<dependency>
<groupId>xyz.block</groupId>
<groupId>xyz.block.ftl</groupId>
<artifactId>ftl-java-runtime</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion integration/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func run(t *testing.T, actionsOrOptions ...ActionOrOption) {
err = ftlexec.Command(ctx, log.Debug, rootDir, "just", "build", "ftl").RunBuffered(ctx)
assert.NoError(t, err)
if opts.requireJava || slices.Contains(opts.languages, "java") {
err = ftlexec.Command(ctx, log.Debug, rootDir, "just", "build-java", "-DskipTests").RunBuffered(ctx)
err = ftlexec.Command(ctx, log.Debug, rootDir, "just", "build-java", "-DskipTests", "-B").RunBuffered(ctx)
assert.NoError(t, err)
}
})
Expand Down

This file was deleted.

This file was deleted.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>xyz.block</groupId>
<artifactId>ftl-java-runtime-parent</artifactId>
<groupId>xyz.block.ftl</groupId>
<artifactId>ftl-jvm-runtime-common-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>ftl-java-runtime-deployment</artifactId>
<artifactId>ftl-jvm-runtime-deployment</artifactId>
<name>Ftl Java Runtime - Deployment</name>

<dependencies>
Expand All @@ -25,13 +25,8 @@
</dependency>

<dependency>
<groupId>com.squareup</groupId>
<artifactId>javapoet</artifactId>
</dependency>

<dependency>
<groupId>xyz.block</groupId>
<artifactId>ftl-java-runtime</artifactId>
<groupId>xyz.block.ftl</groupId>
<artifactId>ftl-jvm-runtime</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package xyz.block.ftl.deployment;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import org.eclipse.microprofile.config.Config;

import io.quarkus.bootstrap.prebuild.CodeGenException;
import io.quarkus.deployment.CodeGenContext;
import io.quarkus.deployment.CodeGenProvider;
import xyz.block.ftl.v1.schema.Data;
import xyz.block.ftl.v1.schema.Enum;
import xyz.block.ftl.v1.schema.Module;
import xyz.block.ftl.v1.schema.Topic;
import xyz.block.ftl.v1.schema.Type;
import xyz.block.ftl.v1.schema.Verb;

public abstract class JVMCodeGenerator implements CodeGenProvider {

public static final String PACKAGE_PREFIX = "ftl.";

@Override
public String providerId() {
return "ftl-clients";
}

@Override
public String inputDirectory() {
return "ftl-module-schema";
}

@Override
public boolean trigger(CodeGenContext context) throws CodeGenException {
if (!Files.isDirectory(context.inputDir())) {
return false;
}
List<Module> modules = new ArrayList<>();
Map<DeclRef, Type> typeAliasMap = new HashMap<>();
try (Stream<Path> pathStream = Files.list(context.inputDir())) {
for (var file : pathStream.toList()) {
String fileName = file.getFileName().toString();
if (!fileName.endsWith(".pb")) {
continue;
}
var module = Module.parseFrom(Files.readAllBytes(file));
for (var decl : module.getDeclsList()) {
if (decl.hasTypeAlias()) {
var data = decl.getTypeAlias();
typeAliasMap.put(new DeclRef(module.getName(), data.getName()), data.getType());
}
}
modules.add(module);
}
} catch (IOException e) {
throw new CodeGenException(e);
}
try {
for (var module : modules) {
String packageName = PACKAGE_PREFIX + module.getName();
for (var decl : module.getDeclsList()) {
if (decl.hasVerb()) {
var verb = decl.getVerb();
if (!verb.getExport()) {
continue;
}
generateVerb(module, verb, packageName, typeAliasMap, context.outDir());
} else if (decl.hasData()) {
var data = decl.getData();
if (!data.getExport()) {
continue;
}
generateDataObject(module, data, packageName, typeAliasMap, context.outDir());

} else if (decl.hasEnum()) {
var data = decl.getEnum();
if (!data.getExport()) {
continue;
}
generateEnum(module, data, packageName, typeAliasMap, context.outDir());
} else if (decl.hasTopic()) {
var data = decl.getTopic();
if (!data.getExport()) {
continue;
}
generateTopicSubscription(module, data, packageName, typeAliasMap, context.outDir());
}
}
}

} catch (Exception e) {
throw new CodeGenException(e);
}
return true;
}

protected abstract void generateTopicSubscription(Module module, Topic data, String packageName,
Map<DeclRef, Type> typeAliasMap, Path outputDir) throws IOException;

protected abstract void generateEnum(Module module, Enum data, String packageName, Map<DeclRef, Type> typeAliasMap,
Path outputDir) throws IOException;

protected abstract void generateDataObject(Module module, Data data, String packageName, Map<DeclRef, Type> typeAliasMap,
Path outputDir) throws IOException;

protected abstract void generateVerb(Module module, Verb verb, String packageName, Map<DeclRef, Type> typeAliasMap,
Path outputDir) throws IOException;

@Override
public boolean shouldRun(Path sourceDir, Config config) {
return true;
}

public record DeclRef(String module, String name) {
}

protected static String className(String in) {
return Character.toUpperCase(in.charAt(0)) + in.substring(1);
}

}
20 changes: 20 additions & 0 deletions jvm-runtime/ftl-runtime/common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ftl-jvm-runtime-parent</artifactId>
<groupId>xyz.block.ftl</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>ftl-jvm-runtime-common-parent</artifactId>
<name>FTL Java Runtime - Common Parent</name>
<packaging>pom</packaging>
<modules>
<module>deployment</module>
<module>runtime</module>
</modules>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>xyz.block</groupId>
<artifactId>ftl-java-runtime-parent</artifactId>
<groupId>xyz.block.ftl</groupId>
<artifactId>ftl-jvm-runtime-common-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>ftl-java-runtime</artifactId>
<artifactId>ftl-jvm-runtime</artifactId>
<name>Ftl Java Runtime - Runtime</name>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: FTL JVM Common Runtime
#description: Do something useful.
metadata:
# keywords:
# - ftl-java-runtime
# guide: ... # To create and publish this guide, see https://github.com/quarkiverse/quarkiverse/wiki#documenting-your-extension
# categories:
# - "miscellaneous"
# status: "preview"
49 changes: 49 additions & 0 deletions jvm-runtime/ftl-runtime/java/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>xyz.block.ftl</groupId>
<artifactId>ftl-java-runtime-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>ftl-java-runtime-deployment</artifactId>
<name>Ftl Java Runtime - Deployment</name>

<dependencies>
<dependency>
<groupId>xyz.block.ftl</groupId>
<artifactId>ftl-java-runtime</artifactId>
</dependency>
<dependency>
<groupId>xyz.block.ftl</groupId>
<artifactId>ftl-jvm-runtime-deployment</artifactId>
</dependency>
<dependency>
<groupId>com.squareup</groupId>
<artifactId>javapoet</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading

0 comments on commit ebb66ad

Please sign in to comment.