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 broken Liquibase 4.4 in native mode #18059

Merged
merged 1 commit into from
Jun 22, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -45,6 +46,7 @@
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBundleBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild;
import io.quarkus.deployment.util.ServiceUtil;
Expand Down Expand Up @@ -104,6 +106,7 @@ void nativeImageConfiguration(
BuildProducer<NativeImageResourceBuildItem> resource,
BuildProducer<ServiceProviderBuildItem> services,
BuildProducer<RuntimeInitializedClassBuildItem> runtimeInitialized,
BuildProducer<RuntimeReinitializedClassBuildItem> runtimeReInitialized,
BuildProducer<NativeImageResourceBundleBuildItem> resourceBundle) {

runtimeInitialized.produce(new RuntimeInitializedClassBuildItem(liquibase.diff.compare.CompareControl.class.getName()));
Expand All @@ -112,7 +115,8 @@ void nativeImageConfiguration(
liquibase.change.AbstractSQLChange.class.getName(),
liquibase.database.jvm.JdbcConnection.class.getName()));

reflective.produce(new ReflectiveClassBuildItem(true, false, false, "liquibase.command.LiquibaseCommandFactory"));
reflective.produce(new ReflectiveClassBuildItem(true, false, false, "liquibase.command.LiquibaseCommandFactory",
liquibase.command.CommandFactory.class.getName()));

reflective.produce(new ReflectiveClassBuildItem(true, true, true,
liquibase.parser.ChangeLogParserCofiguration.class.getName(),
Expand Down Expand Up @@ -180,10 +184,26 @@ void nativeImageConfiguration(
liquibase.sqlgenerator.SqlGenerator.class,
liquibase.structure.DatabaseObject.class,
liquibase.hub.HubService.class)
.forEach(t -> addService(services, reflective, t, false));
.forEach(t -> consumeService(t, (serviceClass, implementations) -> {
services.produce(
new ServiceProviderBuildItem(serviceClass.getName(), implementations.toArray(new String[0])));
reflective.produce(new ReflectiveClassBuildItem(true, true, false, implementations.toArray(new String[0])));
}));

// Register Precondition services, and the implementation class for reflection while also registering fields for reflection
addService(services, reflective, liquibase.precondition.Precondition.class, true);
consumeService(liquibase.precondition.Precondition.class, (serviceClass, implementations) -> {
services.produce(new ServiceProviderBuildItem(serviceClass.getName(), implementations.toArray(new String[0])));
reflective.produce(new ReflectiveClassBuildItem(true, true, true, implementations.toArray(new String[0])));
});

// CommandStep implementations are needed
consumeService(liquibase.command.CommandStep.class, (serviceClass, implementations) -> {
services.produce(new ServiceProviderBuildItem(serviceClass.getName(), implementations.toArray(new String[0])));
reflective.produce(new ReflectiveClassBuildItem(true, false, false, implementations.toArray(new String[0])));
for (String implementation : implementations) {
runtimeInitialized.produce(new RuntimeInitializedClassBuildItem(implementation));
}
});

// liquibase XSD
resource.produce(new NativeImageResourceBuildItem(
Expand All @@ -207,17 +227,12 @@ void nativeImageConfiguration(
resourceBundle.produce(new NativeImageResourceBundleBuildItem("liquibase/i18n/liquibase-core"));
}

private void addService(BuildProducer<ServiceProviderBuildItem> services,
BuildProducer<ReflectiveClassBuildItem> reflective, Class<?> serviceClass,
boolean shouldRegisterFieldForReflection) {
private void consumeService(Class<?> serviceClass, BiConsumer<Class<?>, Collection<String>> consumer) {
try {
String service = "META-INF/services/" + serviceClass.getName();
Set<String> implementations = ServiceUtil.classNamesNamedIn(Thread.currentThread().getContextClassLoader(),
service);
services.produce(new ServiceProviderBuildItem(serviceClass.getName(), implementations.toArray(new String[0])));

reflective.produce(new ReflectiveClassBuildItem(true, true, shouldRegisterFieldForReflection,
implementations.toArray(new String[0])));
consumer.accept(serviceClass, implementations);
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
Expand Down