Skip to content

Commit

Permalink
fix(liquibase): register Precondition services
Browse files Browse the repository at this point in the history
  • Loading branch information
machi1990 committed Dec 11, 2020
1 parent b5919d7 commit 25c925b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ void nativeImageConfiguration(
liquibase.sqlgenerator.SqlGenerator.class,
liquibase.structure.DatabaseObject.class,
liquibase.hub.HubService.class)
.forEach(t -> addService(services, reflective, t));
.forEach(t -> addService(services, reflective, t, false));

// Register Precondition services, and the implementation class for reflection while also registering fields for reflection
addService(services, reflective, liquibase.precondition.Precondition.class, true);

// liquibase XSD
resource.produce(new NativeImageResourceBuildItem(
Expand All @@ -161,14 +164,16 @@ void nativeImageConfiguration(
}

private void addService(BuildProducer<ServiceProviderBuildItem> services,
BuildProducer<ReflectiveClassBuildItem> reflective, Class<?> serviceClass) {
BuildProducer<ReflectiveClassBuildItem> reflective, Class<?> serviceClass,
boolean shouldRegisterFieldForReflection) {
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, false, implementations.toArray(new String[0])));
reflective.produce(new ReflectiveClassBuildItem(true, true, shouldRegisterFieldForReflection,
implementations.toArray(new String[0])));
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
Expand All @@ -182,10 +187,10 @@ FeatureBuildItem feature() {
@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
ServiceStartBuildItem createBeansAndStartActions(LiquibaseRecorder recorder,
List<JdbcDataSourceBuildItem> jdbcDataSourceBuildItems,
BuildProducer<AdditionalBeanBuildItem> additionalBeans,
BuildProducer<SyntheticBeanBuildItem> syntheticBeanBuildItemBuildProducer,
BuildProducer<JdbcDataSourceSchemaReadyBuildItem> schemaReadyBuildItem) {
List<JdbcDataSourceBuildItem> jdbcDataSourceBuildItems,
BuildProducer<AdditionalBeanBuildItem> additionalBeans,
BuildProducer<SyntheticBeanBuildItem> syntheticBeanBuildItemBuildProducer,
BuildProducer<JdbcDataSourceSchemaReadyBuildItem> schemaReadyBuildItem) {

// make a LiquibaseContainerProducer bean
additionalBeans
Expand Down Expand Up @@ -281,8 +286,8 @@ private List<String> getChangeLogs(Collection<String> dataSourceNames, Liquibase
* Finds all resource files for the given change log file
*/
private Set<String> findAllChangeLogFiles(String file, ChangeLogParserFactory changeLogParserFactory,
ClassLoaderResourceAccessor classLoaderResourceAccessor,
ChangeLogParameters changeLogParameters) {
ClassLoaderResourceAccessor classLoaderResourceAccessor,
ChangeLogParameters changeLogParameters) {
try {
ChangeLogParser parser = changeLogParserFactory.getParser(file, classLoaderResourceAccessor);
DatabaseChangeLog changelog = parser.parse(file, changeLogParameters, classLoaderResourceAccessor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">

<preConditions>
<dbms type="h2"/>
</preConditions>

<changeSet author="dev (generated)" id="create-tables-1">
<createTable tableName="LIQUIBASE">
<column name="ID" type="VARCHAR(255)">
Expand Down

0 comments on commit 25c925b

Please sign in to comment.