Skip to content

Commit be3c9b1

Browse files
bug: fix #9 - Add quarkus-jackson-jq as ExpressionFactory; Add ServiceProviderBuildItem (#11)
Signed-off-by: Ricardo Zanini <[email protected]>
1 parent 6d5706a commit be3c9b1

File tree

14 files changed

+138
-152
lines changed

14 files changed

+138
-152
lines changed

core/deployment/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
2020
<artifactId>quarkus-flow</artifactId>
2121
<version>${project.version}</version>
2222
</dependency>
23+
<!-- Required by Native compilation for serverlessworkflow-core-http module -->
24+
<dependency>
25+
<groupId>io.quarkus</groupId>
26+
<artifactId>quarkus-rest-client-jackson-deployment</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>io.quarkiverse.jackson-jq</groupId>
30+
<artifactId>quarkus-jackson-jq-deployment</artifactId>
31+
</dependency>
2332
<dependency>
2433
<groupId>io.serverlessworkflow</groupId>
2534
<artifactId>serverlessworkflow-fluent-spec</artifactId>

core/deployment/src/main/java/io/quarkiverse/flow/deployment/DiscoveredFlowBuildItem.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public DiscoveredFlowBuildItem(MethodInfo method, String workflowName) {
1313
method.declaringClass().name().toString(),
1414
method.name(),
1515
workflowName,
16+
method.parameterTypes().stream().map(t -> t.name().toString()).toArray(String[]::new),
1617
method.isStaticInitializer());
1718
}
1819

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,58 @@
11
package io.quarkiverse.flow.deployment;
22

3+
import com.github.f4b6a3.ulid.UlidCreator;
4+
import com.github.f4b6a3.ulid.UlidFactory;
5+
6+
import io.quarkus.deployment.annotations.BuildProducer;
37
import io.quarkus.deployment.annotations.BuildStep;
48
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
9+
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
10+
import io.serverlessworkflow.impl.events.EventConsumer;
11+
import io.serverlessworkflow.impl.events.EventPublisher;
12+
import io.serverlessworkflow.impl.events.InMemoryEvents;
13+
import io.serverlessworkflow.impl.executors.DefaultTaskExecutorFactory;
14+
import io.serverlessworkflow.impl.executors.TaskExecutorFactory;
15+
import io.serverlessworkflow.impl.expressions.ExpressionFactory;
16+
import io.serverlessworkflow.impl.expressions.jq.JQExpressionFactory;
17+
import io.serverlessworkflow.impl.jackson.schema.JsonSchemaValidatorFactory;
18+
import io.serverlessworkflow.impl.schema.SchemaValidatorFactory;
519

6-
/**
7-
* see <a href="https://github.com/serverlessworkflow/sdk-java/issues/812">Native-image build fails due to UlidCreator static
8-
* initialization (Random in image heap)</a>
9-
*/
1020
final class FlowNativeProcessor {
11-
@BuildStep
12-
RuntimeInitializedClassBuildItem ulidCreatorHolder() {
13-
return new RuntimeInitializedClassBuildItem("com.github.f4b6a3.ulid.UlidCreator$MonotonicFactoryHolder");
14-
}
1521

22+
/**
23+
* see <a href="https://github.com/serverlessworkflow/sdk-java/issues/812">Native-image build fails due to UlidCreator
24+
* static
25+
* initialization (Random in image heap)</a>
26+
*/
1627
@BuildStep
17-
RuntimeInitializedClassBuildItem ulidCreator() {
18-
return new RuntimeInitializedClassBuildItem("com.github.f4b6a3.ulid.UlidCreator");
28+
void runtimeInitUlid(BuildProducer<RuntimeInitializedClassBuildItem> producer) {
29+
producer.produce(new RuntimeInitializedClassBuildItem(
30+
"com.github.f4b6a3.ulid.UlidCreator$MonotonicFactoryHolder"));
31+
producer.produce(new RuntimeInitializedClassBuildItem(
32+
com.github.f4b6a3.ulid.UlidCreator.class.getName()));
33+
producer.produce(new RuntimeInitializedClassBuildItem(
34+
com.github.f4b6a3.ulid.UlidFactory.class.getName()));
1935
}
2036

37+
/**
38+
* Registers the CNCF Java SDK default providers for native compilation.
39+
*/
2140
@BuildStep
22-
RuntimeInitializedClassBuildItem ulidFactory() {
23-
return new RuntimeInitializedClassBuildItem("com.github.f4b6a3.ulid.UlidFactory");
41+
void registerSDKServiceProviders(BuildProducer<ServiceProviderBuildItem> sp) {
42+
43+
// TODO: make all of them @DefaultBeans so users can easily replace
44+
// TODO: these providers must be compatible with Quarkus Ecosystem
45+
46+
sp.produce(new ServiceProviderBuildItem(ExpressionFactory.class.getName(),
47+
JQExpressionFactory.class.getName()));
48+
sp.produce(new ServiceProviderBuildItem(TaskExecutorFactory.class.getName(),
49+
DefaultTaskExecutorFactory.class.getName()));
50+
sp.produce(new ServiceProviderBuildItem(SchemaValidatorFactory.class.getName(),
51+
JsonSchemaValidatorFactory.class.getName()));
52+
sp.produce(new ServiceProviderBuildItem(EventConsumer.class.getName(),
53+
InMemoryEvents.class.getName()));
54+
sp.produce(new ServiceProviderBuildItem(EventPublisher.class.getName(),
55+
InMemoryEvents.class.getName()));
2456
}
2557

2658
}

core/deployment/src/main/java/io/quarkiverse/flow/deployment/FlowProcessor.java

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111

1212
import io.quarkiverse.flow.FlowDefinition;
1313
import io.quarkiverse.flow.FlowDescriptor;
14-
import io.quarkiverse.flow.producers.DefaultExpressionFactoryProducer;
15-
import io.quarkiverse.flow.producers.DefaultSchemaValidatorFactoryProducer;
16-
import io.quarkiverse.flow.producers.DefaultTaskExecutorFactoryProducer;
17-
import io.quarkiverse.flow.producers.InMemoryEventsBean;
14+
import io.quarkiverse.flow.providers.QuarkusJQExpressionFactory;
1815
import io.quarkiverse.flow.recorders.FlowRecorder;
1916
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
2017
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
@@ -26,7 +23,7 @@
2623
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
2724
import io.quarkus.deployment.builditem.FeatureBuildItem;
2825
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
29-
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
26+
import io.quarkus.deployment.builditem.nativeimage.ReflectiveMethodBuildItem;
3027
import io.serverlessworkflow.impl.WorkflowApplication;
3128
import io.serverlessworkflow.impl.WorkflowDefinition;
3229

@@ -69,24 +66,18 @@ void collectFlowDescriptors(CombinedIndexBuildItem index, BuildProducer<Discover
6966
void keepAndReflectFlowDescriptors(
7067
List<DiscoveredFlowBuildItem> discovered,
7168
BuildProducer<UnremovableBeanBuildItem> keep,
72-
BuildProducer<ReflectiveClassBuildItem> reflective) {
69+
BuildProducer<ReflectiveMethodBuildItem> reflective) {
7370

74-
var owners = discovered.stream()
71+
List<String> owners = discovered.stream()
7572
.map(d -> d.workflow.className)
7673
.distinct()
7774
.toList();
7875

7976
// Keep producers from being removed
8077
keep.produce(UnremovableBeanBuildItem.beanClassNames(owners.toArray(String[]::new)));
8178

82-
// Make all declared methods on the owner classes available at runtime
83-
for (String cn : owners) {
84-
reflective.produce(
85-
ReflectiveClassBuildItem.builder(cn)
86-
.methods(true) // keep methods (needed for MethodHandles / reflection)
87-
.fields(false) // not needed here
88-
.constructors(false)
89-
.build());
79+
for (DiscoveredFlowBuildItem d : discovered) {
80+
reflective.produce(new ReflectiveMethodBuildItem(d.workflow.className, d.workflow.methodName, d.workflow.params));
9081
}
9182
}
9283

@@ -104,10 +95,7 @@ AdditionalBeanBuildItem coreBeans() {
10495
@BuildStep
10596
AdditionalBeanBuildItem registerRuntimeDefaults() {
10697
return AdditionalBeanBuildItem.builder()
107-
.addBeanClass(InMemoryEventsBean.class)
108-
.addBeanClass(DefaultExpressionFactoryProducer.class)
109-
.addBeanClass(DefaultSchemaValidatorFactoryProducer.class)
110-
.addBeanClass(DefaultTaskExecutorFactoryProducer.class)
98+
.addBeanClass(QuarkusJQExpressionFactory.class)
11199
.setUnremovable()
112100
.build();
113101
}

core/pom.xml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,4 @@
1616
<module>runtime</module>
1717
<module>deployment</module>
1818
</modules>
19-
20-
<dependencies>
21-
<dependency>
22-
<groupId>io.serverlessworkflow</groupId>
23-
<artifactId>serverlessworkflow-impl-core</artifactId>
24-
</dependency>
25-
<dependency>
26-
<groupId>io.serverlessworkflow</groupId>
27-
<artifactId>serverlessworkflow-impl-http</artifactId>
28-
</dependency>
29-
<dependency>
30-
<groupId>io.serverlessworkflow</groupId>
31-
<artifactId>serverlessworkflow-impl-jackson</artifactId>
32-
</dependency>
33-
</dependencies>
34-
3519
</project>

core/runtime/pom.xml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,40 @@
1111
<name>Quarkus Flow :: Core :: Runtime</name>
1212

1313
<dependencies>
14+
<!-- CNCF Java SDK -->
1415
<dependency>
15-
<groupId>io.quarkus</groupId>
16-
<artifactId>quarkus-arc</artifactId>
16+
<groupId>io.serverlessworkflow</groupId>
17+
<artifactId>serverlessworkflow-impl-core</artifactId>
18+
</dependency>
19+
<dependency>
20+
<groupId>io.serverlessworkflow</groupId>
21+
<artifactId>serverlessworkflow-impl-http</artifactId>
22+
</dependency>
23+
<dependency>
24+
<groupId>io.serverlessworkflow</groupId>
25+
<artifactId>serverlessworkflow-impl-jackson</artifactId>
1726
</dependency>
1827
<dependency>
1928
<groupId>io.serverlessworkflow</groupId>
2029
<artifactId>serverlessworkflow-fluent-spec</artifactId>
2130
<version>${io.serverlessworkflow.version}</version>
2231
</dependency>
32+
33+
<!-- Quarkus -->
34+
<dependency>
35+
<groupId>io.quarkus</groupId>
36+
<artifactId>quarkus-arc</artifactId>
37+
</dependency>
38+
<dependency>
39+
<groupId>io.quarkiverse.jackson-jq</groupId>
40+
<artifactId>quarkus-jackson-jq</artifactId>
41+
</dependency>
42+
<!-- Required by serverlessworkflow-core-http HttpExecutor service module -->
43+
<dependency>
44+
<groupId>io.quarkus</groupId>
45+
<artifactId>quarkus-rest-client-jackson</artifactId>
46+
</dependency>
47+
2348
</dependencies>
2449

2550
<build>

core/runtime/src/main/java/io/quarkiverse/flow/producers/DefaultExpressionFactoryProducer.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

core/runtime/src/main/java/io/quarkiverse/flow/producers/DefaultSchemaValidatorFactoryProducer.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

core/runtime/src/main/java/io/quarkiverse/flow/producers/DefaultTaskExecutorFactoryProducer.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

core/runtime/src/main/java/io/quarkiverse/flow/producers/InMemoryEventsBean.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)