Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with Liquibase and H2 database #40720

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading