From 605eb8a14d8b3189708a7ba47a3e88d84a6b7bfc Mon Sep 17 00:00:00 2001 From: Fabricio Colombo Date: Mon, 7 Sep 2015 10:53:20 -0300 Subject: [PATCH] Add Liquibase labels and parameters properties Update `LiquibaseAutoConfiguration` and `LiquibaseProperties` to add support for labels and parameters. Closes gh-3915 --- .../liquibase/LiquibaseAutoConfiguration.java | 4 ++- .../liquibase/LiquibaseProperties.java | 30 +++++++++++++++++- .../LiquibaseAutoConfigurationTests.java | 31 ++++++++++++++++++- .../appendix-application-properties.adoc | 2 ++ 4 files changed, 64 insertions(+), 3 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java index e25fd0ff49..6457e7f1c6 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -100,6 +100,8 @@ public class LiquibaseAutoConfiguration { liquibase.setDefaultSchema(this.properties.getDefaultSchema()); liquibase.setDropFirst(this.properties.isDropFirst()); liquibase.setShouldRun(this.properties.isEnabled()); + liquibase.setLabels(this.properties.getLabels()); + liquibase.setChangeLogParameters(this.properties.getParameters()); return liquibase; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseProperties.java index 67c089da96..faf4acc56b 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,8 @@ package org.springframework.boot.autoconfigure.liquibase; +import java.util.Map; + import javax.validation.constraints.NotNull; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -78,6 +80,16 @@ public class LiquibaseProperties { */ private String url; + /** + * Comma-separated list of runtime labels to use. + */ + private String labels; + + /** + * Change log parameters. + */ + private Map parameters; + public String getChangeLog() { return this.changeLog; } @@ -150,4 +162,20 @@ public class LiquibaseProperties { this.url = url; } + public String getLabels() { + return this.labels; + } + + public void setLabels(String labels) { + this.labels = labels; + } + + public Map getParameters() { + return this.parameters; + } + + public void setParameters(Map parameters) { + this.parameters = parameters; + } + } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java index 638f1e4553..f5e387fd39 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,8 @@ package org.springframework.boot.autoconfigure.liquibase; +import java.util.Map; + import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -167,4 +169,31 @@ public class LiquibaseAutoConfigurationTests { assertThat(log, instanceOf(CommonsLoggingLiquibaseLogger.class)); } + @Test + public void testOverrideLabels() throws Exception { + EnvironmentTestUtils.addEnvironment(this.context, + "liquibase.labels:test, production"); + this.context.register(EmbeddedDataSourceConfiguration.class, + LiquibaseAutoConfiguration.class, + PropertyPlaceholderAutoConfiguration.class); + this.context.refresh(); + SpringLiquibase liquibase = this.context.getBean(SpringLiquibase.class); + assertEquals("test, production", liquibase.getLabels()); + } + + @Test + @SuppressWarnings("unchecked") + public void testOverrideParameters() throws Exception { + EnvironmentTestUtils.addEnvironment(this.context, "liquibase.parameters.foo:bar"); + this.context.register(EmbeddedDataSourceConfiguration.class, + LiquibaseAutoConfiguration.class, + PropertyPlaceholderAutoConfiguration.class); + this.context.refresh(); + SpringLiquibase liquibase = this.context.getBean(SpringLiquibase.class); + Map parameters = (Map) ReflectionTestUtils + .getField(liquibase, "parameters"); + assertTrue(parameters.containsKey("foo")); + assertEquals("bar", parameters.get("foo")); + } + } diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index cc64449031..94237518eb 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -472,12 +472,14 @@ content into your application; rather pick only the properties that you need. liquibase.change-log=classpath:/db/changelog/db.changelog-master.yaml liquibase.check-change-log-location=true # check the change log location exists liquibase.contexts= # runtime contexts to use + liquibase.labels= # runtime labels to use liquibase.default-schema= # default database schema to use liquibase.drop-first=false liquibase.enabled=true liquibase.url= # specific JDBC url (if not set the default datasource is used) liquibase.user= # user name for liquibase.url liquibase.password= # password for liquibase.url + liquibase.parameters= # change log parameters # JMX spring.jmx.default-domain= # JMX domain name