From d5e4a194461375b7bcd7432c29bdfea527a9d6a9 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 11 May 2018 12:37:54 +0100 Subject: [PATCH] Upgrade to Liquibase 3.6.1 and adapt to logging changes Closes gh-13145 --- .../spring-boot-dependencies/pom.xml | 2 +- .../CommonsLoggingLiquibaseLogger.java | 138 ---------------- ...baseServiceLocatorApplicationListener.java | 3 - .../CommonsLoggingLiquibaseLoggerTests.java | 155 ------------------ 4 files changed, 1 insertion(+), 297 deletions(-) delete mode 100644 spring-boot-project/spring-boot/src/main/java/org/springframework/boot/liquibase/CommonsLoggingLiquibaseLogger.java delete mode 100644 spring-boot-project/spring-boot/src/test/java/org/springframework/boot/liquibase/CommonsLoggingLiquibaseLoggerTests.java diff --git a/spring-boot-project/spring-boot-dependencies/pom.xml b/spring-boot-project/spring-boot-dependencies/pom.xml index ee80b3d2d8..4c82871193 100644 --- a/spring-boot-project/spring-boot-dependencies/pom.xml +++ b/spring-boot-project/spring-boot-dependencies/pom.xml @@ -116,7 +116,7 @@ 1.1.0 1.2.41 5.0.4.RELEASE - 3.5.5 + 3.6.1 2.10.0 1.2.3 1.16.20 diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/liquibase/CommonsLoggingLiquibaseLogger.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/liquibase/CommonsLoggingLiquibaseLogger.java deleted file mode 100644 index 105c250173..0000000000 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/liquibase/CommonsLoggingLiquibaseLogger.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright 2012-2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.liquibase; - -import liquibase.logging.LogLevel; -import liquibase.logging.Logger; -import liquibase.logging.core.AbstractLogger; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Liquibase {@link Logger} that delegates to an Apache Commons {@link Log}. - * - * @author Michael Cramer - * @author Phillip Webb - * @author Andy Wilkinson - * @since 1.2.0 - */ -public class CommonsLoggingLiquibaseLogger extends AbstractLogger { - - /** - * The priority for the {@link CommonsLoggingLiquibaseLogger}. - */ - public static final int PRIORITY = 10; - - private Log logger; - - @Override - public void setName(String name) { - this.logger = createLogger(name); - } - - /** - * Factory method used to create the logger. - * @param name the name of the logger - * @return a {@link Log} instance - */ - protected Log createLogger(String name) { - return LogFactory.getLog(name); - } - - @Override - public void setLogLevel(String logLevel, String logFile) { - super.setLogLevel(logLevel); - } - - @Override - public void severe(String message) { - if (isEnabled(LogLevel.SEVERE)) { - this.logger.error(buildMessage(message)); - } - } - - @Override - public void severe(String message, Throwable e) { - if (isEnabled(LogLevel.SEVERE)) { - this.logger.error(buildMessage(message), e); - } - } - - @Override - public void warning(String message) { - if (isEnabled(LogLevel.WARNING)) { - this.logger.warn(buildMessage(message)); - } - } - - @Override - public void warning(String message, Throwable e) { - if (isEnabled(LogLevel.WARNING)) { - this.logger.warn(buildMessage(message), e); - } - } - - @Override - public void info(String message) { - if (isEnabled(LogLevel.INFO)) { - this.logger.info(buildMessage(message)); - } - } - - @Override - public void info(String message, Throwable e) { - if (isEnabled(LogLevel.INFO)) { - this.logger.info(buildMessage(message), e); - } - } - - @Override - public void debug(String message) { - if (isEnabled(LogLevel.DEBUG)) { - this.logger.debug(buildMessage(message)); - } - } - - @Override - public void debug(String message, Throwable e) { - if (isEnabled(LogLevel.DEBUG)) { - this.logger.debug(buildMessage(message), e); - } - } - - @Override - public int getPriority() { - return PRIORITY; - } - - private boolean isEnabled(LogLevel level) { - if (this.logger != null) { - switch (level) { - case DEBUG: - return this.logger.isDebugEnabled(); - case INFO: - return this.logger.isInfoEnabled(); - case WARNING: - return this.logger.isWarnEnabled(); - case SEVERE: - return this.logger.isErrorEnabled(); - } - } - return false; - } - -} diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/liquibase/LiquibaseServiceLocatorApplicationListener.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/liquibase/LiquibaseServiceLocatorApplicationListener.java index c0cd49d08d..ce479336a9 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/liquibase/LiquibaseServiceLocatorApplicationListener.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/liquibase/LiquibaseServiceLocatorApplicationListener.java @@ -54,10 +54,7 @@ public class LiquibaseServiceLocatorApplicationListener public void replaceServiceLocator() { CustomResolverServiceLocator customResolverServiceLocator = new CustomResolverServiceLocator( new SpringPackageScanClassResolver(logger)); - customResolverServiceLocator.addPackageToScan( - CommonsLoggingLiquibaseLogger.class.getPackage().getName()); ServiceLocator.setInstance(customResolverServiceLocator); - liquibase.logging.LogFactory.reset(); } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/liquibase/CommonsLoggingLiquibaseLoggerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/liquibase/CommonsLoggingLiquibaseLoggerTests.java deleted file mode 100644 index a52b173b08..0000000000 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/liquibase/CommonsLoggingLiquibaseLoggerTests.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright 2012-2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.liquibase; - -import liquibase.logging.LogLevel; -import org.apache.commons.logging.Log; -import org.junit.Before; -import org.junit.Test; - -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; - -/** - * Tests for {@link CommonsLoggingLiquibaseLogger}. - * - * @author Phillip Webb - * @author Andy Wilkinson - */ -public class CommonsLoggingLiquibaseLoggerTests { - - private Log delegate = mock(Log.class); - - private CommonsLoggingLiquibaseLogger logger; - - private Throwable ex = new Exception(); - - @Before - public void setup() { - this.logger = new MockCommonsLoggingLiquibaseLogger(); - this.logger.setName("mylog"); - } - - @Test - public void debug() { - this.logger.setLogLevel(LogLevel.DEBUG); - given(this.delegate.isDebugEnabled()).willReturn(true); - this.logger.debug("debug"); - verify(this.delegate).debug("debug"); - } - - @Test - public void debugWithException() { - this.logger.setLogLevel(LogLevel.DEBUG); - given(this.delegate.isDebugEnabled()).willReturn(true); - this.logger.debug("debug", this.ex); - verify(this.delegate).debug("debug", this.ex); - } - - @Test - public void debugWithLoggerOff() { - this.logger.setLogLevel(LogLevel.DEBUG); - given(this.delegate.isDebugEnabled()).willReturn(false); - this.logger.debug("debug"); - verify(this.delegate, never()).debug("debug"); - } - - @Test - public void info() { - this.logger.setLogLevel(LogLevel.INFO); - given(this.delegate.isInfoEnabled()).willReturn(true); - this.logger.info("info"); - verify(this.delegate).info("info"); - } - - @Test - public void infoWithException() { - this.logger.setLogLevel(LogLevel.INFO); - given(this.delegate.isInfoEnabled()).willReturn(true); - this.logger.info("info", this.ex); - verify(this.delegate).info("info", this.ex); - } - - @Test - public void infoWithLoggerOff() { - this.logger.setLogLevel(LogLevel.INFO); - given(this.delegate.isInfoEnabled()).willReturn(false); - this.logger.info("info"); - verify(this.delegate, never()).info("info"); - } - - @Test - public void warning() { - this.logger.setLogLevel(LogLevel.WARNING); - given(this.delegate.isWarnEnabled()).willReturn(true); - this.logger.warning("warning"); - verify(this.delegate).warn("warning"); - } - - @Test - public void warningWithException() { - this.logger.setLogLevel(LogLevel.WARNING); - given(this.delegate.isWarnEnabled()).willReturn(true); - this.logger.warning("warning", this.ex); - verify(this.delegate).warn("warning", this.ex); - } - - @Test - public void warningWithLoggerOff() { - this.logger.setLogLevel(LogLevel.WARNING); - given(this.delegate.isWarnEnabled()).willReturn(false); - this.logger.warning("warning"); - verify(this.delegate, never()).warn("warning"); - } - - @Test - public void severe() { - this.logger.setLogLevel(LogLevel.SEVERE); - given(this.delegate.isErrorEnabled()).willReturn(true); - this.logger.severe("severe"); - verify(this.delegate).error("severe"); - } - - @Test - public void severeWithException() { - this.logger.setLogLevel(LogLevel.SEVERE); - given(this.delegate.isErrorEnabled()).willReturn(true); - this.logger.severe("severe", this.ex); - verify(this.delegate).error("severe", this.ex); - } - - @Test - public void severeWithLoggerOff() { - this.logger.setLogLevel(LogLevel.SEVERE); - given(this.delegate.isErrorEnabled()).willReturn(false); - this.logger.severe("severe"); - verify(this.delegate, never()).error("severe"); - } - - private class MockCommonsLoggingLiquibaseLogger - extends CommonsLoggingLiquibaseLogger { - - @Override - protected Log createLogger(String name) { - return CommonsLoggingLiquibaseLoggerTests.this.delegate; - } - - } - -}