Skip to content

Commit

Permalink
fix: alway use correct module name in JVM (#2456)
Browse files Browse the repository at this point in the history
fixes: 2396
  • Loading branch information
stuartwdouglas authored Aug 20, 2024
1 parent 06f6a92 commit 147a98c
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 38 deletions.
1 change: 0 additions & 1 deletion internal/buildengine/build_java.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func buildJavaModule(ctx context.Context, module Module) error {
}
logger.Infof("Using build command '%s'", module.Config.Build)
command := exec.Command(ctx, log.Debug, module.Config.Dir, "bash", "-c", module.Config.Build)
command.Env = append(command.Env, "FTL_MODULE_NAME="+module.Config.Module)
err := command.RunBuffered(ctx)
if err != nil {
return fmt.Errorf("failed to build module %q: %w", module.Config.Module, err)
Expand Down
5 changes: 4 additions & 1 deletion jvm-runtime/ftl-runtime/common/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-credentials-deployment</artifactId>
</dependency>

<dependency>
<groupId>xyz.block.ftl</groupId>
<artifactId>ftl-jvm-runtime</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.tomlj</groupId>
<artifactId>tomlj</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@
import io.quarkus.deployment.builditem.ApplicationInfoBuildItem;
import io.quarkus.deployment.builditem.ApplicationStartBuildItem;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.GeneratedResourceBuildItem;
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.deployment.builditem.RunTimeConfigBuilderBuildItem;
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
import io.quarkus.deployment.builditem.SystemPropertyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
Expand Down Expand Up @@ -91,7 +89,6 @@
import xyz.block.ftl.runtime.builtin.HttpRequest;
import xyz.block.ftl.runtime.builtin.HttpResponse;
import xyz.block.ftl.runtime.config.FTLConfigSource;
import xyz.block.ftl.runtime.config.FTLConfigSourceFactoryBuilder;
import xyz.block.ftl.v1.CallRequest;
import xyz.block.ftl.v1.schema.Any;
import xyz.block.ftl.v1.schema.Array;
Expand Down Expand Up @@ -124,7 +121,6 @@ class FtlProcessor {
private static final Logger log = Logger.getLogger(FtlProcessor.class);

private static final String SCHEMA_OUT = "schema.pb";
private static final String FEATURE = "ftl-java-runtime";
public static final DotName EXPORT = DotName.createSimple(Export.class);
public static final DotName VERB = DotName.createSimple(Verb.class);
public static final DotName CRON = DotName.createSimple(Cron.class);
Expand All @@ -141,21 +137,6 @@ class FtlProcessor {
public static final DotName NOT_NULL = DotName.createSimple(NotNull.class);
public static final DotName JSON_NODE = DotName.createSimple(JsonNode.class.getName());

@BuildStep
ModuleNameBuildItem moduleName(ApplicationInfoBuildItem applicationInfoBuildItem, FTLBuildTimeConfig buildTimeConfig) {
return new ModuleNameBuildItem(buildTimeConfig.moduleName.orElse(applicationInfoBuildItem.getName()));
}

@BuildStep
RunTimeConfigBuilderBuildItem runTimeConfigBuilderBuildItem() {
return new RunTimeConfigBuilderBuildItem(FTLConfigSourceFactoryBuilder.class.getName());
}

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@BuildStep
BindableServiceBuildItem verbService() {
var ret = new BindableServiceBuildItem(DotName.createSimple(VerbHandler.class));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package xyz.block.ftl.deployment;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Objects;
import java.util.stream.Collectors;

import org.jboss.logging.Logger;
import org.tomlj.Toml;
import org.tomlj.TomlParseResult;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.ApplicationArchivesBuildItem;
import io.quarkus.deployment.builditem.ApplicationInfoBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.RunTimeConfigBuilderBuildItem;
import xyz.block.ftl.runtime.config.FTLConfigSourceFactoryBuilder;

public class ModuleProcessor {

private static final Logger log = Logger.getLogger(ModuleProcessor.class);

private static final String FEATURE = "ftl-java-runtime";

@BuildStep
ModuleNameBuildItem moduleName(ApplicationInfoBuildItem applicationInfoBuildItem,
ApplicationArchivesBuildItem archivesBuildItem) throws IOException {
for (var root : archivesBuildItem.getRootArchive().getRootDirectories()) {
Path source = root;
for (;;) {
var toml = source.resolve("ftl.toml");
if (Files.exists(toml)) {
TomlParseResult result = Toml.parse(toml);
if (result.hasErrors()) {
throw new RuntimeException("Failed to parse " + toml + " "
+ result.errors().stream().map(Objects::toString).collect(Collectors.joining(", ")));
}

String value = result.getString("module");
if (value != null) {
return new ModuleNameBuildItem(value);
} else {
log.errorf("module name not found in %s", toml);
}
}
if (source.getParent() == null) {
break;
} else {
source = source.getParent();
}
}
}

return new ModuleNameBuildItem(applicationInfoBuildItem.getName());
}

@BuildStep
RunTimeConfigBuilderBuildItem runTimeConfigBuilderBuildItem() {
return new RunTimeConfigBuilderBuildItem(FTLConfigSourceFactoryBuilder.class.getName());
}

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}
}
6 changes: 6 additions & 0 deletions jvm-runtime/ftl-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<version.formatter.plugin>2.24.1</version.formatter.plugin>
<version.impsort.plugin>1.11.0</version.impsort.plugin>
<kotlinpoet.version>1.18.1</kotlinpoet.version>
<tomlj.version>1.1.1</tomlj.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -72,6 +73,11 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.tomlj</groupId>
<artifactId>tomlj</artifactId>
<version>${tomlj.version}</version>
</dependency>

<dependency>
<groupId>com.squareup</groupId>
Expand Down
2 changes: 1 addition & 1 deletion jvm-runtime/testdata/java/verbs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<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>
<groupId>xyz.block.ftl.examples</groupId>
<artifactId>verbs</artifactId>
<artifactId>verbs-module</artifactId>
<version>1.0-SNAPSHOT</version>

<parent>
Expand Down

0 comments on commit 147a98c

Please sign in to comment.