Skip to content

Commit

Permalink
Add jOOQ record auto reflection registration
Browse files Browse the repository at this point in the history
  • Loading branch information
luneo7 committed Jun 22, 2022
1 parent 8494774 commit 79cfa80
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-narayana-jta-deployment</artifactId>
</dependency>

<dependency>
<groupId>io.quarkiverse.jooq</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javax.inject.Inject;
import javax.inject.Singleton;

import io.quarkus.deployment.pkg.steps.NativeBuild;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.DotName;
Expand All @@ -31,13 +32,18 @@
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.IndexDependencyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.recording.RecorderContext;
import io.quarkus.gizmo.*;
import io.quarkus.runtime.util.HashUtil;

public class JooqProcessor {
private static final DotName JOOQ_RECORD_DOT_NAME = DotName.createSimple(org.jooq.Record.class.getName());

private static final String JOOQ_PACKAGE_PREFIX = "org.jooq";

private static final String FEATURE = "jooq";

Expand All @@ -59,6 +65,21 @@ FeatureBuildItem featureBuildItem() {
return new FeatureBuildItem(FEATURE);
}

@BuildStep(onlyIf = NativeBuild.class)
void addDependencies(BuildProducer<IndexDependencyBuildItem> indexDependency) {
indexDependency.produce(new IndexDependencyBuildItem("org.jooq", "jooq"));
}

@BuildStep(onlyIf = NativeBuild.class)
public void registerReflections(CombinedIndexBuildItem indexBuildItem,
BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
indexBuildItem.getIndex()
.getAllKnownImplementors(JOOQ_RECORD_DOT_NAME)
.stream()
.filter(o -> !o.name().packagePrefix().startsWith(JOOQ_PACKAGE_PREFIX))
.forEach(clazz -> reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, clazz.name().toString())));
}

@SuppressWarnings("unchecked")
@Record(ExecutionTime.STATIC_INIT)
@BuildStep
Expand Down

0 comments on commit 79cfa80

Please sign in to comment.