Skip to content

Commit 3e4e59a

Browse files
committed
Restore compatibility with Liquibase 4.23
Closes spring-projectsgh-38522
1 parent 903f85c commit 3e4e59a

File tree

6 files changed

+198
-15
lines changed

6 files changed

+198
-15
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import javax.sql.DataSource;
2020

21+
import liquibase.UpdateSummaryEnum;
22+
import liquibase.UpdateSummaryOutputEnum;
2123
import liquibase.change.DatabaseChange;
2224
import liquibase.integration.spring.SpringLiquibase;
2325

@@ -113,8 +115,13 @@ public SpringLiquibase liquibase(ObjectProvider<DataSource> dataSource,
113115
liquibase.setRollbackFile(properties.getRollbackFile());
114116
liquibase.setTestRollbackOnUpdate(properties.isTestRollbackOnUpdate());
115117
liquibase.setTag(properties.getTag());
116-
liquibase.setShowSummary(properties.getShowSummary());
117-
liquibase.setShowSummaryOutput(properties.getShowSummaryOutput());
118+
if (properties.getShowSummary() != null) {
119+
liquibase.setShowSummary(UpdateSummaryEnum.valueOf(properties.getShowSummary().name()));
120+
}
121+
if (properties.getShowSummaryOutput() != null) {
122+
liquibase
123+
.setShowSummaryOutput(UpdateSummaryOutputEnum.valueOf(properties.getShowSummaryOutput().name()));
124+
}
118125
return liquibase;
119126
}
120127

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseProperties.java

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,14 @@ public class LiquibaseProperties {
138138
private String tag;
139139

140140
/**
141-
* Whether to print a summary of the update operation. Values can be 'off', 'summary'
142-
* (default), 'verbose'
141+
* Whether to print a summary of the update operation.
143142
*/
144-
private UpdateSummaryEnum showSummary;
143+
private ShowSummary showSummary;
145144

146145
/**
147-
* Where to print a summary of the update operation. Values can be 'log' (default),
148-
* 'console', or 'all'.
146+
* Where to print a summary of the update operation.
149147
*/
150-
private UpdateSummaryOutputEnum showSummaryOutput;
148+
private ShowSummaryOutput showSummaryOutput;
151149

152150
public String getChangeLog() {
153151
return this.changeLog;
@@ -302,20 +300,72 @@ public void setTag(String tag) {
302300
this.tag = tag;
303301
}
304302

305-
public UpdateSummaryEnum getShowSummary() {
303+
public ShowSummary getShowSummary() {
306304
return this.showSummary;
307305
}
308306

309-
public void setShowSummary(UpdateSummaryEnum showSummary) {
307+
public void setShowSummary(ShowSummary showSummary) {
310308
this.showSummary = showSummary;
311309
}
312310

313-
public UpdateSummaryOutputEnum getShowSummaryOutput() {
311+
public ShowSummaryOutput getShowSummaryOutput() {
314312
return this.showSummaryOutput;
315313
}
316314

317-
public void setShowSummaryOutput(UpdateSummaryOutputEnum showSummaryOutput) {
315+
public void setShowSummaryOutput(ShowSummaryOutput showSummaryOutput) {
318316
this.showSummaryOutput = showSummaryOutput;
319317
}
320318

319+
/**
320+
* Enumeration of types of summary to show. Values are the same as those on
321+
* {@link UpdateSummaryEnum}. To maximize backwards compatibility, the Liquibase enum
322+
* is not used directly.
323+
*
324+
* @since 3.2.1
325+
*/
326+
public enum ShowSummary {
327+
328+
/**
329+
* Do not show a summary.
330+
*/
331+
OFF,
332+
333+
/**
334+
* Show a summary.
335+
*/
336+
SUMMARY,
337+
338+
/**
339+
* Show a verbose summary.
340+
*/
341+
VERBOSE
342+
343+
}
344+
345+
/**
346+
* Enumeration of destinations to which the summary should be output. Values are the
347+
* same as those on {@link UpdateSummaryOutputEnum}. To maximize backwards
348+
* compatibility, the Liquibase enum is not used directly.
349+
*
350+
* @since 3.2.1
351+
*/
352+
public enum ShowSummaryOutput {
353+
354+
/**
355+
* Log the summary.
356+
*/
357+
LOG,
358+
359+
/**
360+
* Output the summary to the console.
361+
*/
362+
CONSOLE,
363+
364+
/**
365+
* Log the summary and output it to the console.
366+
*/
367+
ALL
368+
369+
}
370+
321371
}

spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,14 @@
19221922
"level": "error"
19231923
}
19241924
},
1925+
{
1926+
"name": "spring.liquibase.show-summary",
1927+
"defaultValue": "summary"
1928+
},
1929+
{
1930+
"name": "spring.liquibase.show-summary-output",
1931+
"defaultValue": "log"
1932+
},
19251933
{
19261934
"name": "spring.mail.test-connection",
19271935
"description": "Whether to test that the mail server is available on startup.",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2012-2023 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+
* https://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 org.springframework.boot.autoconfigure.liquibase;
18+
19+
import java.util.function.Consumer;
20+
21+
import liquibase.integration.spring.SpringLiquibase;
22+
import org.junit.jupiter.api.Test;
23+
24+
import org.springframework.boot.autoconfigure.AutoConfigurations;
25+
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
26+
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
27+
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
28+
import org.springframework.boot.test.context.runner.ContextConsumer;
29+
import org.springframework.boot.testsupport.classpath.ClassPathOverrides;
30+
31+
import static org.assertj.core.api.Assertions.assertThat;
32+
33+
/**
34+
* Tests for {@link LiquibaseAutoConfiguration} with Liquibase 4.23.
35+
*
36+
* @author Andy Wilkinson
37+
*/
38+
@ClassPathOverrides("org.liquibase:liquibase-core:4.23.1")
39+
class Liquibase423AutoConfigurationTests {
40+
41+
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
42+
.withConfiguration(AutoConfigurations.of(LiquibaseAutoConfiguration.class))
43+
.withPropertyValues("spring.datasource.generate-unique-name=true");
44+
45+
@Test
46+
void defaultSpringLiquibase() {
47+
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
48+
.run(assertLiquibase((liquibase) -> {
49+
assertThat(liquibase.getChangeLog()).isEqualTo("classpath:/db/changelog/db.changelog-master.yaml");
50+
assertThat(liquibase.getContexts()).isNull();
51+
assertThat(liquibase.getDefaultSchema()).isNull();
52+
assertThat(liquibase.isDropFirst()).isFalse();
53+
assertThat(liquibase.isClearCheckSums()).isFalse();
54+
}));
55+
}
56+
57+
private ContextConsumer<AssertableApplicationContext> assertLiquibase(Consumer<SpringLiquibase> consumer) {
58+
return (context) -> {
59+
assertThat(context).hasSingleBean(SpringLiquibase.class);
60+
SpringLiquibase liquibase = context.getBean(SpringLiquibase.class);
61+
consumer.accept(liquibase);
62+
};
63+
}
64+
65+
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.zaxxer.hikari.HikariDataSource;
3232
import liquibase.UpdateSummaryEnum;
3333
import liquibase.UpdateSummaryOutputEnum;
34+
import liquibase.command.core.helpers.ShowSummaryArgument;
3435
import liquibase.integration.spring.SpringLiquibase;
3536
import org.junit.jupiter.api.Test;
3637
import org.junit.jupiter.api.extension.ExtendWith;
@@ -119,9 +120,6 @@ void defaultSpringLiquibase() {
119120
assertThat(liquibase.getDefaultSchema()).isNull();
120121
assertThat(liquibase.isDropFirst()).isFalse();
121122
assertThat(liquibase.isClearCheckSums()).isFalse();
122-
UpdateSummaryOutputEnum showSummaryOutput = (UpdateSummaryOutputEnum) ReflectionTestUtils
123-
.getField(liquibase, "showSummaryOutput");
124-
assertThat(showSummaryOutput).isEqualTo(UpdateSummaryOutputEnum.LOG);
125123
}));
126124
}
127125

@@ -225,6 +223,9 @@ void defaultValues() {
225223
assertThat(liquibase.isDropFirst()).isEqualTo(properties.isDropFirst());
226224
assertThat(liquibase.isClearCheckSums()).isEqualTo(properties.isClearChecksums());
227225
assertThat(liquibase.isTestRollbackOnUpdate()).isEqualTo(properties.isTestRollbackOnUpdate());
226+
assertThat(liquibase).extracting("showSummary").isNull();
227+
assertThat(ShowSummaryArgument.SHOW_SUMMARY.getDefaultValue()).isEqualTo(UpdateSummaryEnum.SUMMARY);
228+
assertThat(liquibase).extracting("showSummaryOutput").isEqualTo(UpdateSummaryOutputEnum.LOG);
228229
}));
229230
}
230231

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2012-2023 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+
* https://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 org.springframework.boot.autoconfigure.liquibase;
18+
19+
import java.util.List;
20+
import java.util.stream.Stream;
21+
22+
import liquibase.UpdateSummaryEnum;
23+
import liquibase.UpdateSummaryOutputEnum;
24+
import org.junit.jupiter.api.Test;
25+
26+
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties.ShowSummary;
27+
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties.ShowSummaryOutput;
28+
29+
import static org.assertj.core.api.Assertions.assertThat;
30+
31+
/**
32+
* Tests for {@link LiquibaseProperties}.
33+
*
34+
* @author Andy Wilkinson
35+
*/
36+
public class LiquibasePropertiesTests {
37+
38+
@Test
39+
void valuesOfShowSummaryMatchValuesOfUpdateSummaryEnum() {
40+
assertThat(namesOf(ShowSummary.values())).isEqualTo(namesOf(UpdateSummaryEnum.values()));
41+
}
42+
43+
@Test
44+
void valuesOfShowSummaryOutputMatchValuesOfUpdateSummaryOutputEnum() {
45+
assertThat(namesOf(ShowSummaryOutput.values())).isEqualTo(namesOf(UpdateSummaryOutputEnum.values()));
46+
}
47+
48+
private List<String> namesOf(Enum<?>[] input) {
49+
return Stream.of(input).map(Enum::name).toList();
50+
}
51+
52+
}

0 commit comments

Comments
 (0)