Skip to content

Commit

Permalink
Fix issue with Liquibase and H2 database
Browse files Browse the repository at this point in the history
Fixes: #40575
  • Loading branch information
geoand committed May 20, 2024
1 parent f020580 commit 509ec82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions extensions/jdbc/jdbc-h2/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<parentFirstArtifacts>
<parentFirstArtifact>com.h2database:h2</parentFirstArtifact>
</parentFirstArtifacts>
<capabilities>
<provides>io.quarkus.jdbc.h2</provides>
</capabilities>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiConsumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -36,6 +37,7 @@
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.arc.processor.DotNames;
import io.quarkus.datasource.common.runtime.DataSourceUtil;
import io.quarkus.deployment.Capabilities;
import io.quarkus.deployment.Feature;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
Expand Down Expand Up @@ -101,6 +103,7 @@ void nativeImageConfiguration(
LiquibaseBuildTimeConfig liquibaseBuildConfig,
List<JdbcDataSourceBuildItem> jdbcDataSourceBuildItems,
CombinedIndexBuildItem combinedIndex,
Capabilities capabilities,
BuildProducer<ReflectiveClassBuildItem> reflective,
BuildProducer<NativeImageResourceBuildItem> resource,
BuildProducer<ServiceProviderBuildItem> services,
Expand Down Expand Up @@ -212,7 +215,7 @@ void nativeImageConfiguration(
// CommandStep implementations are needed
consumeService(liquibase.command.CommandStep.class, (serviceClass, implementations) -> {
var filteredImpls = implementations.stream()
.filter(not("liquibase.command.core.StartH2CommandStep"::equals))
.filter(commandStepPredicate(capabilities))
.toArray(String[]::new);
services.produce(new ServiceProviderBuildItem(serviceClass.getName(), filteredImpls));
reflective.produce(ReflectiveClassBuildItem.builder(filteredImpls).constructors().build());
Expand Down Expand Up @@ -250,6 +253,14 @@ void nativeImageConfiguration(
resourceBundle.produce(new NativeImageResourceBundleBuildItem("liquibase/i18n/liquibase-core"));
}

private static Predicate<String> commandStepPredicate(Capabilities capabilities) {
if (capabilities.isPresent("io.quarkus.jdbc.h2")) {
return (s) -> true;
} else {
return not("liquibase.command.core.StartH2CommandStep"::equals);
}
}

private void consumeService(Class<?> serviceClass, BiConsumer<Class<?>, Collection<String>> consumer) {
try {
String service = "META-INF/services/" + serviceClass.getName();
Expand Down

0 comments on commit 509ec82

Please sign in to comment.