mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Polish
This commit is contained in:
parent
acfae2ebff
commit
cf93f84e87
@ -100,4 +100,5 @@ public class AuthenticationAuditListenerTests {
|
||||
assertThat(auditApplicationEvent.getValue().getAuditEvent().getData(),
|
||||
hasEntry("details", details));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -183,26 +183,27 @@ public class FlywayAutoConfiguration {
|
||||
private static class StringOrNumberToMigrationVersionConverter
|
||||
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
|
||||
public Set<ConvertiblePair> getConvertibleTypes() {
|
||||
return CONVERTIBLE_PAIRS;
|
||||
return CONVERTIBLE_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
public Object convert(Object source, TypeDescriptor sourceType,
|
||||
TypeDescriptor targetType) {
|
||||
String value = ObjectUtils.nullSafeToString(source);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,8 +26,8 @@ import org.springframework.context.annotation.Conditional;
|
||||
|
||||
/**
|
||||
* {@link Conditional} that checks whether or not the Spring resource handling chain is
|
||||
* enabled. Matches if {@link ResourceProperties.Chain#getEnabled()} is {@code true} or
|
||||
* if {@code webjars-locator} is on the classpath.
|
||||
* enabled. Matches if {@link ResourceProperties.Chain#getEnabled()} is {@code true} or if
|
||||
* {@code webjars-locator} is on the classpath.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.3.0
|
||||
|
@ -34,7 +34,7 @@ import org.springframework.util.ClassUtils;
|
||||
*/
|
||||
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
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context,
|
||||
@ -46,8 +46,8 @@ class OnEnabledResourceChainCondition extends SpringBootCondition {
|
||||
binder.bind(new PropertySourcesPropertyValues(environment.getPropertySources()));
|
||||
Boolean match = properties.getChain().getEnabled();
|
||||
if (match == null) {
|
||||
boolean webJarsLocatorPresent = ClassUtils.isPresent(
|
||||
WEBJAR_ASSERT_LOCATOR, getClass().getClassLoader());
|
||||
boolean webJarsLocatorPresent = ClassUtils.isPresent(WEBJAR_ASSERT_LOCATOR,
|
||||
getClass().getClassLoader());
|
||||
return new ConditionOutcome(webJarsLocatorPresent,
|
||||
"Webjars locator (" + WEBJAR_ASSERT_LOCATOR + ") is "
|
||||
+ (webJarsLocatorPresent ? "present" : "absent"));
|
||||
|
@ -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");
|
||||
* 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
|
||||
* specific settings are present.
|
||||
* @return whether the resource chain is enabled or {@code null} if no
|
||||
* specified settings are present.
|
||||
* @return whether the resource chain is enabled or {@code null} if no specified
|
||||
* settings are present.
|
||||
*/
|
||||
public Boolean getEnabled() {
|
||||
// Check if at least one of the available strategy has been enabled
|
||||
Boolean strategyEnabled = getStrategy().getFixed().isEnabled()
|
||||
|| getStrategy().getContent().isEnabled();
|
||||
return (strategyEnabled ? Boolean.TRUE : this.enabled);
|
||||
|
@ -258,20 +258,24 @@ public class WebMvcAutoConfiguration {
|
||||
}
|
||||
Integer cachePeriod = this.resourceProperties.getCachePeriod();
|
||||
if (!registry.hasMappingForPattern("/webjars/**")) {
|
||||
customizeResourceHandlerRegistration(registry.addResourceHandler("/webjars/**")
|
||||
.addResourceLocations("classpath:/META-INF/resources/webjars/")
|
||||
customizeResourceHandlerRegistration(
|
||||
registry.addResourceHandler("/webjars/**")
|
||||
.addResourceLocations(
|
||||
"classpath:/META-INF/resources/webjars/")
|
||||
.setCachePeriod(cachePeriod));
|
||||
}
|
||||
String staticPathPattern = this.mvcProperties.getStaticPathPattern();
|
||||
if (!registry.hasMappingForPattern(staticPathPattern)) {
|
||||
customizeResourceHandlerRegistration(registry.addResourceHandler(staticPathPattern)
|
||||
.addResourceLocations(
|
||||
this.resourceProperties.getStaticLocations())
|
||||
customizeResourceHandlerRegistration(
|
||||
registry.addResourceHandler(staticPathPattern)
|
||||
.addResourceLocations(
|
||||
this.resourceProperties.getStaticLocations())
|
||||
.setCachePeriod(cachePeriod));
|
||||
}
|
||||
}
|
||||
|
||||
private void customizeResourceHandlerRegistration(ResourceHandlerRegistration registration) {
|
||||
private void customizeResourceHandlerRegistration(
|
||||
ResourceHandlerRegistration registration) {
|
||||
if (this.resourceHandlerRegistrationCustomizer != null) {
|
||||
this.resourceHandlerRegistrationCustomizer.customize(registration);
|
||||
}
|
||||
@ -411,6 +415,7 @@ public class WebMvcAutoConfiguration {
|
||||
}
|
||||
return resolver;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -225,8 +225,10 @@ public class FlywayAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void overrideBaselineVersionNumber() throws Exception {
|
||||
Map<String, Object> source = Collections.<String, Object>singletonMap("flyway.baseline-version", 1);
|
||||
this.context.getEnvironment().getPropertySources().addLast(new MapPropertySource("flyway", source));
|
||||
Map<String, Object> source = Collections
|
||||
.<String, Object>singletonMap("flyway.baseline-version", 1);
|
||||
this.context.getEnvironment().getPropertySources()
|
||||
.addLast(new MapPropertySource("flyway", source));
|
||||
registerAndRefresh(EmbeddedDataSourceConfiguration.class,
|
||||
FlywayAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
|
@ -18,8 +18,8 @@ package org.springframework.boot.autoconfigure.web;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
@ -34,25 +34,25 @@ public class ResourcePropertiesTest {
|
||||
@Test
|
||||
public void resourceChainNoCustomization() {
|
||||
System.out.println(this.properties.getChain().getEnabled());
|
||||
assertThat(this.properties.getChain().getEnabled(), is(nullValue()));
|
||||
assertThat(this.properties.getChain().getEnabled(), nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resourceChainStrategyEnabled() {
|
||||
this.properties.getChain().getStrategy().getFixed().setEnabled(true);
|
||||
assertThat(this.properties.getChain().getEnabled(), is(true));
|
||||
assertThat(this.properties.getChain().getEnabled(), equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resourceChainEnabled() {
|
||||
this.properties.getChain().setEnabled(true);
|
||||
assertThat(this.properties.getChain().getEnabled(), is(true));
|
||||
assertThat(this.properties.getChain().getEnabled(), equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resourceChainDisabled() {
|
||||
this.properties.getChain().setEnabled(false);
|
||||
assertThat(this.properties.getChain().getEnabled(), is(false));
|
||||
assertThat(this.properties.getChain().getEnabled(), equalTo(false));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -111,8 +111,8 @@ public class JavaLoggingSystem extends AbstractLoggingSystem {
|
||||
@Override
|
||||
public void setLogLevel(String loggerName, LogLevel level) {
|
||||
Assert.notNull(level, "Level must not be null");
|
||||
Logger logger = Logger
|
||||
.getLogger(StringUtils.hasText(loggerName) ? loggerName : "");
|
||||
String name = (StringUtils.hasText(loggerName) ? loggerName : "");
|
||||
Logger logger = Logger.getLogger(name);
|
||||
logger.setLevel(LEVELS.get(level));
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
* 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("");
|
||||
}
|
||||
|
||||
private LoggerConfig getLoggerConfig(String loggerName) {
|
||||
loggerName = StringUtils.hasText(loggerName) ? loggerName
|
||||
: LogManager.ROOT_LOGGER_NAME;
|
||||
return getLoggerContext().getConfiguration().getLoggers().get(loggerName);
|
||||
private LoggerConfig getLoggerConfig(String name) {
|
||||
name = (StringUtils.hasText(name) ? name : LogManager.ROOT_LOGGER_NAME);
|
||||
return getLoggerContext().getConfiguration().getLoggers().get(name);
|
||||
}
|
||||
|
||||
private LoggerContext getLoggerContext() {
|
||||
|
@ -49,7 +49,7 @@ import static org.junit.Assert.assertThat;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(TestConfig.class)
|
||||
@IntegrationTest({"foo=one", "bar=two"})
|
||||
@IntegrationTest({ "foo=one", "bar=two" })
|
||||
public class ConverterBindingTests {
|
||||
|
||||
@Value("${foo:}")
|
||||
@ -88,11 +88,13 @@ public class ConverterBindingTests {
|
||||
return new GenericConverter() {
|
||||
@Override
|
||||
public Set<ConvertiblePair> getConvertibleTypes() {
|
||||
return Collections.singleton(new ConvertiblePair(String.class, Bar.class));
|
||||
return Collections
|
||||
.singleton(new ConvertiblePair(String.class, Bar.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
public Object convert(Object source, TypeDescriptor sourceType,
|
||||
TypeDescriptor targetType) {
|
||||
return new Bar((String) source);
|
||||
}
|
||||
};
|
||||
@ -112,6 +114,7 @@ public class ConverterBindingTests {
|
||||
public Foo(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Bar {
|
||||
@ -121,6 +124,7 @@ public class ConverterBindingTests {
|
||||
public Bar(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ConfigurationProperties
|
||||
@ -145,6 +149,7 @@ public class ConverterBindingTests {
|
||||
public void setBar(Bar bar) {
|
||||
this.bar = bar;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user