Skip to content

Commit 14898ba

Browse files
authored
Merge pull request #184 from zonkyio/liquibase-4
#179 Fix support for Liquibase 4 and above
2 parents 01fa392 + 7f94a6f commit 14898ba

File tree

3 files changed

+101
-42
lines changed

3 files changed

+101
-42
lines changed

build.gradle

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ ext {
1919
[name: '4.3.29', spring: '4.3.29.RELEASE', 'zonky-postgres': 'default', opentable: 'default', yandex: 'default', 'mssql-driver': 'default', 'mysql-driver': 'default', 'mariadb-driver': 'default', 'h2': 'default'],
2020
[name: '5.0.19', spring: '5.0.19.RELEASE', 'zonky-postgres': 'default', opentable: 'default', yandex: 'default', 'mssql-driver': 'default', 'mysql-driver': 'default', 'mariadb-driver': 'default', 'h2': 'default'],
2121
[name: '5.1.19', spring: '5.1.19.RELEASE', 'zonky-postgres': 'default', opentable: 'default', yandex: 'default', 'mssql-driver': 'default', 'mysql-driver': 'default', 'mariadb-driver': 'default', 'h2': 'default'],
22-
[name: '5.2.11', spring: '5.2.11.RELEASE', 'zonky-postgres': 'default', opentable: 'default', yandex: 'default', 'mssql-driver': 'default', 'mysql-driver': 'default', 'mariadb-driver': 'default', 'h2': 'default'],
23-
[name: '5.3.1', spring: '5.3.1', 'zonky-postgres': 'default', opentable: 'default', yandex: 'default', 'mssql-driver': 'default', 'mysql-driver': 'default', 'mariadb-driver': 'default', 'h2': 'default']
22+
[name: '5.2.12', spring: '5.2.12.RELEASE', 'zonky-postgres': 'default', opentable: 'default', yandex: 'default', 'mssql-driver': 'default', 'mysql-driver': 'default', 'mariadb-driver': 'default', 'h2': 'default'],
23+
[name: '5.3.10', spring: '5.3.10', 'zonky-postgres': 'default', opentable: 'default', yandex: 'default', 'mssql-driver': 'default', 'mysql-driver': 'default', 'mariadb-driver': 'default', 'h2': 'default']
2424
]],
2525
[name: 'flyway', versions: [
2626
[name: '4.0.3', flyway: '4.0.3', 'flyway-test': '4.0.1', spring: '4.3.25.RELEASE', 'spring-boot': '1.5.22.RELEASE', 'zonky-postgres': 'default'],
@@ -29,42 +29,43 @@ ext {
2929
[name: '5.0.7', flyway: '5.0.7', 'flyway-test': '5.0.0', spring: '5.0.13.RELEASE', 'spring-boot': '2.0.9.RELEASE', 'zonky-postgres': 'default'],
3030
[name: '5.1.4', flyway: '5.1.4', 'flyway-test': '5.1.0', spring: '5.0.13.RELEASE', 'spring-boot': '2.0.9.RELEASE', 'zonky-postgres': 'default'],
3131
[name: '5.2.4', flyway: '5.2.4', 'flyway-test': '5.2.4', spring: '5.1.19.RELEASE', 'spring-boot': '2.1.18.RELEASE', 'zonky-postgres': 'default'],
32-
[name: '6.0.6', flyway: '6.0.6', 'flyway-test': '6.0.0', spring: '5.2.10.RELEASE', 'spring-boot': '2.2.11.RELEASE', 'zonky-postgres': 'default'],
33-
[name: '6.0.8', flyway: '6.0.8', 'flyway-test': '6.0.0', spring: '5.2.10.RELEASE', 'spring-boot': '2.2.11.RELEASE', 'zonky-postgres': 'default'],
34-
[name: '6.1.4', flyway: '6.1.4', 'flyway-test': '6.1.0', spring: '5.2.10.RELEASE', 'spring-boot': '2.2.11.RELEASE', 'zonky-postgres': 'default'],
35-
[name: '6.2.4', flyway: '6.2.4', 'flyway-test': '6.1.0', spring: '5.2.10.RELEASE', 'spring-boot': '2.2.11.RELEASE', 'zonky-postgres': 'default'],
36-
[name: '6.3.2', flyway: '6.3.2', 'flyway-test': '6.1.0', spring: '5.2.10.RELEASE', 'spring-boot': '2.2.11.RELEASE', 'zonky-postgres': 'default'],
37-
[name: '6.3.3', flyway: '6.3.3', 'flyway-test': '6.3.3', spring: '5.2.10.RELEASE', 'spring-boot': '2.2.11.RELEASE', 'zonky-postgres': 'default'],
38-
[name: '6.4.4', flyway: '6.4.4', 'flyway-test': '6.4.0', spring: '5.2.10.RELEASE', 'spring-boot': '2.2.11.RELEASE', 'zonky-postgres': 'default'],
39-
[name: '6.5.7', flyway: '6.5.7', 'flyway-test': '6.4.0', spring: '5.2.10.RELEASE', 'spring-boot': '2.2.11.RELEASE', 'zonky-postgres': 'default'],
40-
[name: '7.0.4', flyway: '7.0.4', 'flyway-test': '7.0.0', spring: '5.3.9', 'spring-boot': '2.4.9', 'zonky-postgres': 'default'],
41-
[name: '7.1.1', flyway: '7.1.1', 'flyway-test': '7.0.0', spring: '5.3.9', 'spring-boot': '2.4.9', 'zonky-postgres': 'default'],
42-
[name: '7.2.1', flyway: '7.2.1', 'flyway-test': '7.0.0', spring: '5.3.9', 'spring-boot': '2.4.9', 'zonky-postgres': 'default'],
43-
[name: '7.3.2', flyway: '7.3.2', 'flyway-test': '7.0.0', spring: '5.3.9', 'spring-boot': '2.4.9', 'zonky-postgres': 'default'],
44-
[name: '7.4.0', flyway: '7.4.0', 'flyway-test': '7.0.0', spring: '5.3.9', 'spring-boot': '2.4.9', 'zonky-postgres': 'default'],
45-
[name: '7.5.4', flyway: '7.5.4', 'flyway-test': '7.0.0', spring: '5.3.9', 'spring-boot': '2.4.9', 'zonky-postgres': 'default'],
46-
[name: '7.6.0', flyway: '7.6.0', 'flyway-test': '7.0.0', spring: '5.3.9', 'spring-boot': '2.4.9', 'zonky-postgres': 'default'],
47-
[name: '7.7.3', flyway: '7.7.3', 'flyway-test': '7.0.0', spring: '5.3.9', 'spring-boot': '2.5.3', 'zonky-postgres': 'default'],
48-
[name: '7.8.2', flyway: '7.8.2', 'flyway-test': '7.0.0', spring: '5.3.9', 'spring-boot': '2.5.3', 'zonky-postgres': 'default'],
49-
[name: '7.9.2', flyway: '7.9.2', 'flyway-test': '7.0.0', spring: '5.3.9', 'spring-boot': '2.5.3', 'zonky-postgres': 'default'],
50-
[name: '7.10.0', flyway: '7.10.0', 'flyway-test': '7.0.0', spring: '5.3.9', 'spring-boot': '2.5.3', 'zonky-postgres': 'default'],
51-
[name: '7.11.4', flyway: '7.11.4', 'flyway-test': '7.0.0', spring: '5.3.9', 'spring-boot': '2.5.3', 'zonky-postgres': 'default'],
52-
[name: '7.12.1', flyway: '7.12.1', 'flyway-test': '7.0.0', spring: '5.3.9', 'spring-boot': '2.5.3', 'zonky-postgres': 'default'],
53-
[name: '7.13.0', flyway: '7.13.0', 'flyway-test': '7.0.0', spring: '5.3.9', 'spring-boot': '2.5.3', 'zonky-postgres': 'default'],
32+
[name: '6.0.6', flyway: '6.0.6', 'flyway-test': '6.0.0', spring: '5.2.12.RELEASE', 'spring-boot': '2.2.13.RELEASE', 'zonky-postgres': 'default'],
33+
[name: '6.0.8', flyway: '6.0.8', 'flyway-test': '6.0.0', spring: '5.2.12.RELEASE', 'spring-boot': '2.2.13.RELEASE', 'zonky-postgres': 'default'],
34+
[name: '6.1.4', flyway: '6.1.4', 'flyway-test': '6.1.0', spring: '5.2.12.RELEASE', 'spring-boot': '2.2.13.RELEASE', 'zonky-postgres': 'default'],
35+
[name: '6.2.4', flyway: '6.2.4', 'flyway-test': '6.1.0', spring: '5.2.12.RELEASE', 'spring-boot': '2.2.13.RELEASE', 'zonky-postgres': 'default'],
36+
[name: '6.3.2', flyway: '6.3.2', 'flyway-test': '6.1.0', spring: '5.2.12.RELEASE', 'spring-boot': '2.2.13.RELEASE', 'zonky-postgres': 'default'],
37+
[name: '6.3.3', flyway: '6.3.3', 'flyway-test': '6.3.3', spring: '5.2.12.RELEASE', 'spring-boot': '2.2.13.RELEASE', 'zonky-postgres': 'default'],
38+
[name: '6.4.4', flyway: '6.4.4', 'flyway-test': '6.4.0', spring: '5.2.12.RELEASE', 'spring-boot': '2.2.13.RELEASE', 'zonky-postgres': 'default'],
39+
[name: '6.5.7', flyway: '6.5.7', 'flyway-test': '6.4.0', spring: '5.2.12.RELEASE', 'spring-boot': '2.2.13.RELEASE', 'zonky-postgres': 'default'],
40+
[name: '7.0.4', flyway: '7.0.4', 'flyway-test': '7.0.0', spring: '5.3.10', 'spring-boot': '2.4.11', 'zonky-postgres': 'default'],
41+
[name: '7.1.1', flyway: '7.1.1', 'flyway-test': '7.0.0', spring: '5.3.10', 'spring-boot': '2.4.11', 'zonky-postgres': 'default'],
42+
[name: '7.2.1', flyway: '7.2.1', 'flyway-test': '7.0.0', spring: '5.3.10', 'spring-boot': '2.4.11', 'zonky-postgres': 'default'],
43+
[name: '7.3.2', flyway: '7.3.2', 'flyway-test': '7.0.0', spring: '5.3.10', 'spring-boot': '2.4.11', 'zonky-postgres': 'default'],
44+
[name: '7.4.0', flyway: '7.4.0', 'flyway-test': '7.0.0', spring: '5.3.10', 'spring-boot': '2.4.11', 'zonky-postgres': 'default'],
45+
[name: '7.5.4', flyway: '7.5.4', 'flyway-test': '7.0.0', spring: '5.3.10', 'spring-boot': '2.4.11', 'zonky-postgres': 'default'],
46+
[name: '7.6.0', flyway: '7.6.0', 'flyway-test': '7.0.0', spring: '5.3.10', 'spring-boot': '2.4.11', 'zonky-postgres': 'default'],
47+
[name: '7.7.3', flyway: '7.7.3', 'flyway-test': '7.0.0', spring: '5.3.10', 'spring-boot': '2.5.5', 'zonky-postgres': 'default'],
48+
[name: '7.8.2', flyway: '7.8.2', 'flyway-test': '7.0.0', spring: '5.3.10', 'spring-boot': '2.5.5', 'zonky-postgres': 'default'],
49+
[name: '7.9.2', flyway: '7.9.2', 'flyway-test': '7.0.0', spring: '5.3.10', 'spring-boot': '2.5.5', 'zonky-postgres': 'default'],
50+
[name: '7.10.0', flyway: '7.10.0', 'flyway-test': '7.0.0', spring: '5.3.10', 'spring-boot': '2.5.5', 'zonky-postgres': 'default'],
51+
[name: '7.11.4', flyway: '7.11.4', 'flyway-test': '7.0.0', spring: '5.3.10', 'spring-boot': '2.5.5', 'zonky-postgres': 'default'],
52+
[name: '7.12.1', flyway: '7.12.1', 'flyway-test': '7.0.0', spring: '5.3.10', 'spring-boot': '2.5.5', 'zonky-postgres': 'default'],
53+
[name: '7.13.0', flyway: '7.13.0', 'flyway-test': '7.0.0', spring: '5.3.10', 'spring-boot': '2.5.5', 'zonky-postgres': 'default'],
5454
[name: 'no_sb', flyway: 'default', 'flyway-test': 'default', 'zonky-postgres': 'default']
5555
]],
5656
[name: 'liquibase', versions: [
5757
[name: '3.5.5', liquibase: '3.5.5', spring: '4.3.25.RELEASE', 'spring-boot': '1.5.22.RELEASE'],
5858
[name: '3.6.3', liquibase: '3.6.3', spring: '5.1.19.RELEASE', 'spring-boot': '2.1.18.RELEASE'],
5959
[name: '3.7.0', liquibase: '3.7.0', spring: '5.1.19.RELEASE', 'spring-boot': '2.1.18.RELEASE'],
60-
[name: '3.8.9', liquibase: '3.8.9', spring: '5.2.10.RELEASE', 'spring-boot': '2.2.11.RELEASE'],
61-
[name: '3.9.0', liquibase: '3.9.0', spring: '5.2.10.RELEASE', 'spring-boot': '2.2.11.RELEASE'],
62-
[name: '3.10.3', liquibase: '3.10.3', spring: '5.3.9', 'spring-boot': '2.4.9'],
63-
[name: '4.0.0', liquibase: '4.0.0', spring: '5.3.9', 'spring-boot': '2.4.9'],
64-
[name: '4.1.1', liquibase: '4.1.1', spring: '5.3.9', 'spring-boot': '2.4.9'],
65-
[name: '4.2.2', liquibase: '4.2.2', spring: '5.3.9', 'spring-boot': '2.4.9'],
66-
[name: '4.3.5', liquibase: '4.3.5', spring: '5.3.9', 'spring-boot': '2.5.3'],
67-
[name: '4.4.3', liquibase: '4.4.3', spring: '5.3.9', 'spring-boot': '2.5.3'],
60+
[name: '3.8.9', liquibase: '3.8.9', spring: '5.2.12.RELEASE', 'spring-boot': '2.2.13.RELEASE'],
61+
[name: '3.9.0', liquibase: '3.9.0', spring: '5.2.12.RELEASE', 'spring-boot': '2.2.13.RELEASE'],
62+
[name: '3.10.3', liquibase: '3.10.3', spring: '5.3.10', 'spring-boot': '2.4.11'],
63+
[name: '4.0.0', liquibase: '4.0.0', spring: '5.3.10', 'spring-boot': '2.4.11'],
64+
[name: '4.1.1', liquibase: '4.1.1', spring: '5.3.10', 'spring-boot': '2.4.11'],
65+
[name: '4.2.2', liquibase: '4.2.2', spring: '5.3.10', 'spring-boot': '2.4.11'],
66+
[name: '4.3.5', liquibase: '4.3.5', spring: '5.3.10', 'spring-boot': '2.5.5'],
67+
[name: '4.4.3', liquibase: '4.4.3', spring: '5.3.10', 'spring-boot': '2.5.5'],
68+
[name: '4.5.0', liquibase: '4.5.0', spring: '5.3.10', 'spring-boot': '2.5.5'],
6869
[name: 'no_sb', liquibase: 'default']
6970
]],
7071
[name: 'postgres', versions: [

embedded-database-spring-test/src/main/java/io/zonky/test/db/liquibase/LiquibaseDatabasePreparer.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@
1919
import com.google.common.base.MoreObjects;
2020
import com.google.common.base.Stopwatch;
2121
import io.zonky.test.db.preparer.DatabasePreparer;
22+
import io.zonky.test.db.util.ReflectionUtils;
2223
import liquibase.exception.ChangeLogParseException;
2324
import liquibase.exception.LiquibaseException;
2425
import liquibase.integration.spring.SpringLiquibase;
25-
import liquibase.integration.spring.SpringLiquibase.SpringResourceOpener;
26-
import liquibase.resource.ResourceAccessor;
2726
import liquibase.util.StreamUtil;
2827
import org.slf4j.Logger;
2928
import org.slf4j.LoggerFactory;
29+
import org.springframework.util.ClassUtils;
3030

3131
import javax.sql.DataSource;
3232
import java.io.BufferedReader;
33+
import java.io.IOException;
3334
import java.io.InputStream;
3435
import java.io.InputStreamReader;
3536
import java.util.Objects;
@@ -50,12 +51,7 @@ public LiquibaseDatabasePreparer(LiquibaseDescriptor descriptor) {
5051
public long estimatedDuration() {
5152
if (estimatedDuration == null) {
5253
Stopwatch stopwatch = Stopwatch.createStarted();
53-
54-
SpringLiquibase springLiquibase = new SpringLiquibase();
55-
springLiquibase.setResourceLoader(descriptor.getResourceLoader());
56-
SpringResourceOpener resourceAccessor = springLiquibase.new SpringResourceOpener(descriptor.getChangeLog());
57-
long linesCount = resolveChangeLogLines(descriptor.getChangeLog(), resourceAccessor);
58-
54+
long linesCount = resolveChangeLogLines(descriptor.getChangeLog());
5955
estimatedDuration = 100 + (linesCount * 2);
6056
logger.trace("Resolved {} changelog lines in {}", linesCount, stopwatch);
6157
}
@@ -100,10 +96,10 @@ public String toString() {
10096
.toString();
10197
}
10298

103-
protected long resolveChangeLogLines(String path, ResourceAccessor resourceAccessor) {
99+
protected long resolveChangeLogLines(String path) {
104100
try {
105101
String changeLogPath = path.replace('\\', '/');
106-
InputStream changeLogStream = StreamUtil.singleInputStream(changeLogPath, resourceAccessor);
102+
InputStream changeLogStream = openChangeLogStream(changeLogPath);
107103
if (changeLogStream == null) {
108104
throw new ChangeLogParseException(changeLogPath + " does not exist");
109105
}
@@ -115,4 +111,19 @@ protected long resolveChangeLogLines(String path, ResourceAccessor resourceAcces
115111
return 10000; // fallback value
116112
}
117113
}
114+
115+
protected InputStream openChangeLogStream(String changeLogPath) throws IOException, ClassNotFoundException {
116+
SpringLiquibase springLiquibase = new SpringLiquibase();
117+
springLiquibase.setResourceLoader(descriptor.getResourceLoader());
118+
if (ClassUtils.isPresent("liquibase.integration.spring.SpringLiquibase$SpringResourceOpener", null)) {
119+
SpringLiquibase.SpringResourceOpener resourceAccessor = springLiquibase.new SpringResourceOpener(descriptor.getChangeLog());
120+
return StreamUtil.singleInputStream(changeLogPath, resourceAccessor);
121+
} else if (ClassUtils.isPresent("liquibase.integration.spring.SpringLiquibase$SpringResourceAccessor", null)) {
122+
Object resourceAccessor = ReflectionUtils.invokeConstructor("liquibase.integration.spring.SpringLiquibase$SpringResourceAccessor", springLiquibase);
123+
return ReflectionUtils.invokeMethod(resourceAccessor, "openStream", null, changeLogPath);
124+
} else {
125+
Object resourceAccessor = ReflectionUtils.invokeConstructor("liquibase.integration.spring.SpringResourceAccessor", descriptor.getResourceLoader());
126+
return ReflectionUtils.invokeMethod(resourceAccessor, "openStream", null, changeLogPath);
127+
}
128+
}
118129
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.zonky.test.db.liquibase;
18+
19+
import io.zonky.test.category.LiquibaseTestSuite;
20+
import liquibase.integration.spring.SpringLiquibase;
21+
import org.junit.Before;
22+
import org.junit.Test;
23+
import org.junit.experimental.categories.Category;
24+
import org.springframework.core.io.DefaultResourceLoader;
25+
26+
import static org.assertj.core.api.Assertions.assertThat;
27+
28+
@Category(LiquibaseTestSuite.class)
29+
public class LiquibaseDatabasePreparerTest {
30+
31+
private LiquibaseDatabasePreparer preparer;
32+
33+
@Before
34+
public void setUp() throws Exception {
35+
SpringLiquibase liquibase = new SpringLiquibase();
36+
liquibase.setChangeLog("classpath:/db/changelog/db.changelog-master.yaml");
37+
liquibase.setResourceLoader(new DefaultResourceLoader());
38+
LiquibaseDescriptor descriptor = LiquibaseDescriptor.from(liquibase);
39+
40+
preparer = new LiquibaseDatabasePreparer(descriptor);
41+
}
42+
43+
@Test
44+
public void estimatedDuration() {
45+
assertThat(preparer.estimatedDuration()).isEqualTo(214);
46+
}
47+
}

0 commit comments

Comments
 (0)