From 7a8be3d6006bca50757f035dd45506100087ad01 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 28 May 2014 19:06:55 +0100 Subject: [PATCH] Use Spring Framework bom and fully exclude commons-logging Closes #955 Closes #978 --- ...gurationReportLoggingInitializerTests.java | 30 ++++- spring-boot-cli/pom.xml | 19 ++- spring-boot-dependencies/pom.xml | 124 +++++------------- spring-boot-parent/pom.xml | 6 + .../boot/loader/tools/LogbackInitializer.java | 3 +- spring-boot/pom.xml | 9 +- 6 files changed, 78 insertions(+), 113 deletions(-) diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/logging/AutoConfigurationReportLoggingInitializerTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/logging/AutoConfigurationReportLoggingInitializerTests.java index 26f738fbd3d..3f5e22b8f75 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/logging/AutoConfigurationReportLoggingInitializerTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/logging/AutoConfigurationReportLoggingInitializerTests.java @@ -16,14 +16,15 @@ package org.springframework.boot.autoconfigure.logging; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogConfigurationException; import org.apache.commons.logging.LogFactory; -import org.apache.commons.logging.impl.LogFactoryImpl; import org.apache.commons.logging.impl.NoOpLog; +import org.apache.commons.logging.impl.SLF4JLogFactory; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -41,6 +42,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.mock.web.MockServletContext; +import org.springframework.util.ReflectionUtils; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; import static org.hamcrest.Matchers.containsString; @@ -56,7 +58,7 @@ import static org.mockito.Mockito.mock; /** * Tests for {@link AutoConfigurationReportLoggingInitializer}. - * + * * @author Phillip Webb */ public class AutoConfigurationReportLoggingInitializerTests { @@ -71,6 +73,10 @@ public class AutoConfigurationReportLoggingInitializerTests { protected List infoLog = new ArrayList(); + private Field logFactoryField; + + private LogFactory originalLogFactory; + @Before public void setup() { setupLogging(true, true); @@ -98,15 +104,25 @@ public class AutoConfigurationReportLoggingInitializerTests { } }).given(this.log).info(anyObject()); - LogFactory.releaseAll(); - System.setProperty(LogFactory.FACTORY_PROPERTY, MockLogFactory.class.getName()); + try { + this.logFactoryField = LogFactory.class.getDeclaredField("logFactory"); + ReflectionUtils.makeAccessible(this.logFactoryField); + + this.originalLogFactory = (LogFactory) ReflectionUtils.getField( + this.logFactoryField, null); + + ReflectionUtils.setField(this.logFactoryField, null, new MockLogFactory()); + } + catch (Exception e) { + throw new IllegalStateException("Failed to set logFactory", e); + } + this.initializer = new AutoConfigurationReportLoggingInitializer(); } @After public void cleanup() { - System.clearProperty(LogFactory.FACTORY_PROPERTIES); - LogFactory.releaseAll(); + ReflectionUtils.setField(this.logFactoryField, null, this.originalLogFactory); } @Test @@ -199,7 +215,7 @@ public class AutoConfigurationReportLoggingInitializerTests { containsString("Unable to provide auto-configuration report")); } - public static class MockLogFactory extends LogFactoryImpl { + public static class MockLogFactory extends SLF4JLogFactory { @Override public Log getInstance(String name) throws LogConfigurationException { if (AutoConfigurationReportLoggingInitializer.class.getName().equals(name)) { diff --git a/spring-boot-cli/pom.xml b/spring-boot-cli/pom.xml index e9e3ddfb0c5..95bc8086129 100644 --- a/spring-boot-cli/pom.xml +++ b/spring-boot-cli/pom.xml @@ -104,17 +104,22 @@ org.eclipse.aether aether-transport-http - - - jcl-over-slf4j - org.slf4j - - org.eclipse.aether aether-util + + org.slf4j + jcl-over-slf4j + + + + org.slf4j + slf4j-nop + 1.7.7 + runtime + org.codehaus.groovy @@ -125,7 +130,7 @@ junit junit provided - + diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml index b7a4823bf24..a31d44b7423 100644 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -474,6 +474,12 @@ org.apache.velocity velocity-tools ${velocity-tools.version} + + + commons-logging + commons-logging + + org.aspectj @@ -594,6 +600,12 @@ org.crashub crash.connectors.ssh ${crashub.version} + + + commons-logging + commons-logging + + org.crashub @@ -804,111 +816,22 @@ org.springframework - spring-aop - ${spring.version} - - - org.springframework - spring-aspects - ${spring.version} - - - org.springframework - spring-beans - ${spring.version} - - - org.springframework - spring-context - ${spring.version} - - - org.springframework - spring-context-support + spring-framework-bom ${spring.version} + import + pom org.springframework spring-core ${spring.version} - - - org.springframework - spring-expression - ${spring.version} - - - org.springframework - spring-instrument - ${spring.version} - - - org.springframework - spring-jdbc - ${spring.version} - - - org.springframework - spring-jms - ${spring.version} - - - org.springframework - spring-messaging - ${spring.version} - - - org.springframework - spring-orm - ${spring.version} - - - org.springframework - spring-oxm - ${spring.version} - commons-lang - commons-lang - - - - - org.springframework - spring-test - ${spring.version} - - - org.springframework - spring-tx - ${spring.version} - - - org.springframework - spring-web - ${spring.version} - - - org.springframework - spring-webmvc - ${spring.version} - - - commons-logging commons-logging + commons-logging - - org.springframework - spring-webmvc-portlet - ${spring.version} - - - org.springframework - spring-websocket - ${spring.version} - org.springframework springloaded @@ -968,6 +891,21 @@ import pom + + org.springframework.integration + spring-integration-http + ${spring-integration.version} + + + commons-logging + commons-logging + + + commons-logging + commons-logging-api + + + org.springframework.mobile spring-mobile-device diff --git a/spring-boot-parent/pom.xml b/spring-boot-parent/pom.xml index 7a3ee85b96d..b771b93849c 100644 --- a/spring-boot-parent/pom.xml +++ b/spring-boot-parent/pom.xml @@ -369,6 +369,12 @@ 1.7 + + + commons-logging:commons-logging:*:compile + + true + diff --git a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/LogbackInitializer.java b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/LogbackInitializer.java index b8211270857..6dee1986b4e 100644 --- a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/LogbackInitializer.java +++ b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/LogbackInitializer.java @@ -29,7 +29,8 @@ import ch.qos.logback.classic.Level; public class LogbackInitializer { public static void initialize() { - if (ClassUtils.isPresent("org.slf4j.impl.StaticLoggerBinder", null)) { + if (ClassUtils.isPresent("org.slf4j.impl.StaticLoggerBinder", null) + && ClassUtils.isPresent("ch.qos.logback.classic.Logger", null)) { new Initializer().setRootLogLevel(); } } diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml index 47d1717e774..2206a2bcae3 100644 --- a/spring-boot/pom.xml +++ b/spring-boot/pom.xml @@ -20,6 +20,10 @@ + + org.slf4j + jcl-over-slf4j + org.springframework spring-core @@ -150,11 +154,6 @@ spring-webmvc test - - org.slf4j - jcl-over-slf4j - test -