This commit is contained in:
Phillip Webb 2016-01-21 11:46:46 -08:00
parent acfae2ebff
commit cf93f84e87
12 changed files with 56 additions and 44 deletions

View File

@ -100,4 +100,5 @@ public class AuthenticationAuditListenerTests {
assertThat(auditApplicationEvent.getValue().getAuditEvent().getData(), assertThat(auditApplicationEvent.getValue().getAuditEvent().getData(),
hasEntry("details", details)); hasEntry("details", details));
} }
} }

View File

@ -183,26 +183,27 @@ public class FlywayAutoConfiguration {
private static class StringOrNumberToMigrationVersionConverter private static class StringOrNumberToMigrationVersionConverter
implements GenericConverter { implements GenericConverter {
private static final Set<ConvertiblePair> CONVERTIBLE_PAIRS = createConvertiblePairs(); private static final Set<ConvertiblePair> CONVERTIBLE_TYPES;
static {
Set<ConvertiblePair> types = new HashSet<ConvertiblePair>(2);
types.add(new ConvertiblePair(String.class, MigrationVersion.class));
types.add(new ConvertiblePair(Number.class, MigrationVersion.class));
CONVERTIBLE_TYPES = Collections.unmodifiableSet(types);
}
@Override @Override
public Set<ConvertiblePair> getConvertibleTypes() { public Set<ConvertiblePair> getConvertibleTypes() {
return CONVERTIBLE_PAIRS; return CONVERTIBLE_TYPES;
} }
@Override @Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { public Object convert(Object source, TypeDescriptor sourceType,
TypeDescriptor targetType) {
String value = ObjectUtils.nullSafeToString(source); String value = ObjectUtils.nullSafeToString(source);
return MigrationVersion.fromVersion(value); return MigrationVersion.fromVersion(value);
} }
private static Set<ConvertiblePair> createConvertiblePairs() {
Set<ConvertiblePair> convertiblePairs = new HashSet<ConvertiblePair>(2);
convertiblePairs.add(new ConvertiblePair(String.class, MigrationVersion.class));
convertiblePairs.add(new ConvertiblePair(Number.class, MigrationVersion.class));
return Collections.unmodifiableSet(convertiblePairs);
}
} }
} }

View File

@ -26,8 +26,8 @@ import org.springframework.context.annotation.Conditional;
/** /**
* {@link Conditional} that checks whether or not the Spring resource handling chain is * {@link Conditional} that checks whether or not the Spring resource handling chain is
* enabled. Matches if {@link ResourceProperties.Chain#getEnabled()} is {@code true} or * enabled. Matches if {@link ResourceProperties.Chain#getEnabled()} is {@code true} or if
* if {@code webjars-locator} is on the classpath. * {@code webjars-locator} is on the classpath.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @since 1.3.0 * @since 1.3.0

View File

@ -34,7 +34,7 @@ import org.springframework.util.ClassUtils;
*/ */
class OnEnabledResourceChainCondition extends SpringBootCondition { class OnEnabledResourceChainCondition extends SpringBootCondition {
public static final String WEBJAR_ASSERT_LOCATOR = "org.webjars.WebJarAssetLocator"; private static final String WEBJAR_ASSERT_LOCATOR = "org.webjars.WebJarAssetLocator";
@Override @Override
public ConditionOutcome getMatchOutcome(ConditionContext context, public ConditionOutcome getMatchOutcome(ConditionContext context,
@ -46,8 +46,8 @@ class OnEnabledResourceChainCondition extends SpringBootCondition {
binder.bind(new PropertySourcesPropertyValues(environment.getPropertySources())); binder.bind(new PropertySourcesPropertyValues(environment.getPropertySources()));
Boolean match = properties.getChain().getEnabled(); Boolean match = properties.getChain().getEnabled();
if (match == null) { if (match == null) {
boolean webJarsLocatorPresent = ClassUtils.isPresent( boolean webJarsLocatorPresent = ClassUtils.isPresent(WEBJAR_ASSERT_LOCATOR,
WEBJAR_ASSERT_LOCATOR, getClass().getClassLoader()); getClass().getClassLoader());
return new ConditionOutcome(webJarsLocatorPresent, return new ConditionOutcome(webJarsLocatorPresent,
"Webjars locator (" + WEBJAR_ASSERT_LOCATOR + ") is " "Webjars locator (" + WEBJAR_ASSERT_LOCATOR + ") is "
+ (webJarsLocatorPresent ? "present" : "absent")); + (webJarsLocatorPresent ? "present" : "absent"));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2015 the original author or authors. * Copyright 2012-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -175,11 +175,10 @@ public class ResourceProperties implements ResourceLoaderAware {
/** /**
* Return whether the resource chain is enabled. Return {@code null} if no * Return whether the resource chain is enabled. Return {@code null} if no
* specific settings are present. * specific settings are present.
* @return whether the resource chain is enabled or {@code null} if no * @return whether the resource chain is enabled or {@code null} if no specified
* specified settings are present. * settings are present.
*/ */
public Boolean getEnabled() { public Boolean getEnabled() {
// Check if at least one of the available strategy has been enabled
Boolean strategyEnabled = getStrategy().getFixed().isEnabled() Boolean strategyEnabled = getStrategy().getFixed().isEnabled()
|| getStrategy().getContent().isEnabled(); || getStrategy().getContent().isEnabled();
return (strategyEnabled ? Boolean.TRUE : this.enabled); return (strategyEnabled ? Boolean.TRUE : this.enabled);

View File

@ -258,20 +258,24 @@ public class WebMvcAutoConfiguration {
} }
Integer cachePeriod = this.resourceProperties.getCachePeriod(); Integer cachePeriod = this.resourceProperties.getCachePeriod();
if (!registry.hasMappingForPattern("/webjars/**")) { if (!registry.hasMappingForPattern("/webjars/**")) {
customizeResourceHandlerRegistration(registry.addResourceHandler("/webjars/**") customizeResourceHandlerRegistration(
.addResourceLocations("classpath:/META-INF/resources/webjars/") registry.addResourceHandler("/webjars/**")
.addResourceLocations(
"classpath:/META-INF/resources/webjars/")
.setCachePeriod(cachePeriod)); .setCachePeriod(cachePeriod));
} }
String staticPathPattern = this.mvcProperties.getStaticPathPattern(); String staticPathPattern = this.mvcProperties.getStaticPathPattern();
if (!registry.hasMappingForPattern(staticPathPattern)) { if (!registry.hasMappingForPattern(staticPathPattern)) {
customizeResourceHandlerRegistration(registry.addResourceHandler(staticPathPattern) customizeResourceHandlerRegistration(
.addResourceLocations( registry.addResourceHandler(staticPathPattern)
this.resourceProperties.getStaticLocations()) .addResourceLocations(
this.resourceProperties.getStaticLocations())
.setCachePeriod(cachePeriod)); .setCachePeriod(cachePeriod));
} }
} }
private void customizeResourceHandlerRegistration(ResourceHandlerRegistration registration) { private void customizeResourceHandlerRegistration(
ResourceHandlerRegistration registration) {
if (this.resourceHandlerRegistrationCustomizer != null) { if (this.resourceHandlerRegistrationCustomizer != null) {
this.resourceHandlerRegistrationCustomizer.customize(registration); this.resourceHandlerRegistrationCustomizer.customize(registration);
} }
@ -411,6 +415,7 @@ public class WebMvcAutoConfiguration {
} }
return resolver; return resolver;
} }
} }
} }

View File

@ -225,8 +225,10 @@ public class FlywayAutoConfigurationTests {
@Test @Test
public void overrideBaselineVersionNumber() throws Exception { public void overrideBaselineVersionNumber() throws Exception {
Map<String, Object> source = Collections.<String, Object>singletonMap("flyway.baseline-version", 1); Map<String, Object> source = Collections
this.context.getEnvironment().getPropertySources().addLast(new MapPropertySource("flyway", source)); .<String, Object>singletonMap("flyway.baseline-version", 1);
this.context.getEnvironment().getPropertySources()
.addLast(new MapPropertySource("flyway", source));
registerAndRefresh(EmbeddedDataSourceConfiguration.class, registerAndRefresh(EmbeddedDataSourceConfiguration.class,
FlywayAutoConfiguration.class, FlywayAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);

View File

@ -18,8 +18,8 @@ package org.springframework.boot.autoconfigure.web;
import org.junit.Test; import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
/** /**
@ -34,25 +34,25 @@ public class ResourcePropertiesTest {
@Test @Test
public void resourceChainNoCustomization() { public void resourceChainNoCustomization() {
System.out.println(this.properties.getChain().getEnabled()); System.out.println(this.properties.getChain().getEnabled());
assertThat(this.properties.getChain().getEnabled(), is(nullValue())); assertThat(this.properties.getChain().getEnabled(), nullValue());
} }
@Test @Test
public void resourceChainStrategyEnabled() { public void resourceChainStrategyEnabled() {
this.properties.getChain().getStrategy().getFixed().setEnabled(true); this.properties.getChain().getStrategy().getFixed().setEnabled(true);
assertThat(this.properties.getChain().getEnabled(), is(true)); assertThat(this.properties.getChain().getEnabled(), equalTo(true));
} }
@Test @Test
public void resourceChainEnabled() { public void resourceChainEnabled() {
this.properties.getChain().setEnabled(true); this.properties.getChain().setEnabled(true);
assertThat(this.properties.getChain().getEnabled(), is(true)); assertThat(this.properties.getChain().getEnabled(), equalTo(true));
} }
@Test @Test
public void resourceChainDisabled() { public void resourceChainDisabled() {
this.properties.getChain().setEnabled(false); this.properties.getChain().setEnabled(false);
assertThat(this.properties.getChain().getEnabled(), is(false)); assertThat(this.properties.getChain().getEnabled(), equalTo(false));
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2015 the original author or authors. * Copyright 2012-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2015 the original author or authors. * Copyright 2012-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -111,8 +111,8 @@ public class JavaLoggingSystem extends AbstractLoggingSystem {
@Override @Override
public void setLogLevel(String loggerName, LogLevel level) { public void setLogLevel(String loggerName, LogLevel level) {
Assert.notNull(level, "Level must not be null"); Assert.notNull(level, "Level must not be null");
Logger logger = Logger String name = (StringUtils.hasText(loggerName) ? loggerName : "");
.getLogger(StringUtils.hasText(loggerName) ? loggerName : ""); Logger logger = Logger.getLogger(name);
logger.setLevel(LEVELS.get(level)); logger.setLevel(LEVELS.get(level));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2015 the original author or authors. * Copyright 2012-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -208,10 +208,9 @@ public class Log4J2LoggingSystem extends Slf4JLoggingSystem {
return getLoggerContext().getConfiguration().getLoggerConfig(""); return getLoggerContext().getConfiguration().getLoggerConfig("");
} }
private LoggerConfig getLoggerConfig(String loggerName) { private LoggerConfig getLoggerConfig(String name) {
loggerName = StringUtils.hasText(loggerName) ? loggerName name = (StringUtils.hasText(name) ? name : LogManager.ROOT_LOGGER_NAME);
: LogManager.ROOT_LOGGER_NAME; return getLoggerContext().getConfiguration().getLoggers().get(name);
return getLoggerContext().getConfiguration().getLoggers().get(loggerName);
} }
private LoggerContext getLoggerContext() { private LoggerContext getLoggerContext() {

View File

@ -49,7 +49,7 @@ import static org.junit.Assert.assertThat;
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(TestConfig.class) @SpringApplicationConfiguration(TestConfig.class)
@IntegrationTest({"foo=one", "bar=two"}) @IntegrationTest({ "foo=one", "bar=two" })
public class ConverterBindingTests { public class ConverterBindingTests {
@Value("${foo:}") @Value("${foo:}")
@ -88,11 +88,13 @@ public class ConverterBindingTests {
return new GenericConverter() { return new GenericConverter() {
@Override @Override
public Set<ConvertiblePair> getConvertibleTypes() { public Set<ConvertiblePair> getConvertibleTypes() {
return Collections.singleton(new ConvertiblePair(String.class, Bar.class)); return Collections
.singleton(new ConvertiblePair(String.class, Bar.class));
} }
@Override @Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { public Object convert(Object source, TypeDescriptor sourceType,
TypeDescriptor targetType) {
return new Bar((String) source); return new Bar((String) source);
} }
}; };
@ -112,6 +114,7 @@ public class ConverterBindingTests {
public Foo(String name) { public Foo(String name) {
this.name = name; this.name = name;
} }
} }
public static class Bar { public static class Bar {
@ -121,6 +124,7 @@ public class ConverterBindingTests {
public Bar(String name) { public Bar(String name) {
this.name = name; this.name = name;
} }
} }
@ConfigurationProperties @ConfigurationProperties
@ -145,6 +149,7 @@ public class ConverterBindingTests {
public void setBar(Bar bar) { public void setBar(Bar bar) {
this.bar = bar; this.bar = bar;
} }
} }
} }