Merge branch '1.5.x'

This commit is contained in:
Phillip Webb 2017-12-13 13:07:18 -08:00
commit 5ca608330c
14 changed files with 124 additions and 44 deletions

View File

@ -87,7 +87,7 @@ public class AuditEvent implements Serializable {
Assert.notNull(timestamp, "Timestamp must not be null");
Assert.notNull(type, "Type must not be null");
this.timestamp = timestamp;
this.principal = principal != null ? principal : "";
this.principal = (principal != null ? principal : "");
this.type = type;
this.data = Collections.unmodifiableMap(data);
}

View File

@ -16,8 +16,9 @@
package org.springframework.boot.cli;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.springframework.boot.cli.command.Command;
@ -38,14 +39,24 @@ import org.springframework.boot.cli.command.run.RunCommand;
*/
public class DefaultCommandFactory implements CommandFactory {
private static final List<Command> defaultCommands = Arrays.asList(
new VersionCommand(), new RunCommand(), new GrabCommand(), new JarCommand(),
new WarCommand(), new InstallCommand(), new UninstallCommand(),
new InitCommand());
private static final List<Command> DEFAULT_COMMANDS;
static {
ArrayList<Command> defaultCommands = new ArrayList<>();
defaultCommands.add(new VersionCommand());
defaultCommands.add(new RunCommand());
defaultCommands.add(new GrabCommand());
defaultCommands.add(new JarCommand());
defaultCommands.add(new WarCommand());
defaultCommands.add(new InstallCommand());
defaultCommands.add(new UninstallCommand());
defaultCommands.add(new InitCommand());
DEFAULT_COMMANDS = Collections.unmodifiableList(defaultCommands);
}
@Override
public Collection<Command> getCommands() {
return defaultCommands;
return DEFAULT_COMMANDS;
}
}

View File

@ -42,7 +42,7 @@ import org.springframework.core.env.PropertySource;
@Order(Ordered.LOWEST_PRECEDENCE)
public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostProcessor {
private static final Map<String, Object> properties;
private static final Map<String, Object> PROPERTIES;
static {
Map<String, Object> devToolsProperties = new HashMap<>();
@ -58,7 +58,7 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro
devToolsProperties.put("spring.mvc.log-resolved-exception", "true");
devToolsProperties.put("server.servlet.jsp.init-parameters.development", "true");
devToolsProperties.put("spring.reactor.stacktrace-mode.enabled", "true");
properties = Collections.unmodifiableMap(devToolsProperties);
PROPERTIES = Collections.unmodifiableMap(devToolsProperties);
}
@Override
@ -66,7 +66,7 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro
SpringApplication application) {
if (isLocalApplication(environment) && canAddProperties(environment)) {
PropertySource<?> propertySource = new MapPropertySource("refresh",
properties);
PROPERTIES);
environment.getPropertySources().addLast(propertySource);
}
}

View File

@ -228,14 +228,14 @@ class ImportsContextCustomizer implements ContextCustomizer {
private static final Class<?>[] NO_IMPORTS = {};
private static final Set<AnnotationFilter> annotationFilters;
private static final Set<AnnotationFilter> ANNOTATION_FILTERS;
static {
Set<AnnotationFilter> filters = new HashSet<>();
filters.add(new JavaLangAnnotationFilter());
filters.add(new KotlinAnnotationFilter());
filters.add(new SpockAnnotationFilter());
annotationFilters = Collections.unmodifiableSet(filters);
ANNOTATION_FILTERS = Collections.unmodifiableSet(filters);
}
private final Set<Object> key;
@ -274,7 +274,7 @@ class ImportsContextCustomizer implements ContextCustomizer {
}
private boolean isIgnoredAnnotation(Annotation annotation) {
for (AnnotationFilter annotationFilter : annotationFilters) {
for (AnnotationFilter annotationFilter : ANNOTATION_FILTERS) {
if (annotationFilter.isIgnored(annotation)) {
return true;
}

View File

@ -55,7 +55,6 @@ public final class JsonContent<T> implements AssertProvider<JsonContentAssert> {
/**
* Use AssertJ's {@link org.assertj.core.api.Assertions#assertThat assertThat}
* instead.
*
* @deprecated in favor of AssertJ's {@link org.assertj.core.api.Assertions#assertThat
* assertThat}
*/

View File

@ -177,7 +177,7 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor {
return result;
}
private Object processValue(Object value) {
private Object processValue(Object value) {
if (value instanceof DeclaredType) {
return getQualifiedName(((DeclaredType) value).asElement());
}

View File

@ -121,7 +121,7 @@ public final class Layouts {
*/
public static class War implements Layout {
private static final Map<LibraryScope, String> scopeDestinations;
private static final Map<LibraryScope, String> SCOPE_DESTINATIONS;
static {
Map<LibraryScope, String> map = new HashMap<>();
@ -129,7 +129,7 @@ public final class Layouts {
map.put(LibraryScope.CUSTOM, "WEB-INF/lib/");
map.put(LibraryScope.RUNTIME, "WEB-INF/lib/");
map.put(LibraryScope.PROVIDED, "WEB-INF/lib-provided/");
scopeDestinations = Collections.unmodifiableMap(map);
SCOPE_DESTINATIONS = Collections.unmodifiableMap(map);
}
@Override
@ -139,7 +139,7 @@ public final class Layouts {
@Override
public String getLibraryDestination(String libraryName, LibraryScope scope) {
return scopeDestinations.get(scope);
return SCOPE_DESTINATIONS.get(scope);
}
@Override

View File

@ -42,7 +42,7 @@ import org.springframework.boot.loader.tools.LibraryScope;
*/
public class ArtifactsLibraries implements Libraries {
private static final Map<String, LibraryScope> scopes;
private static final Map<String, LibraryScope> SCOPES;
static {
Map<String, LibraryScope> libraryScopes = new HashMap<>();
@ -50,7 +50,7 @@ public class ArtifactsLibraries implements Libraries {
libraryScopes.put(Artifact.SCOPE_RUNTIME, LibraryScope.RUNTIME);
libraryScopes.put(Artifact.SCOPE_PROVIDED, LibraryScope.PROVIDED);
libraryScopes.put(Artifact.SCOPE_SYSTEM, LibraryScope.PROVIDED);
scopes = Collections.unmodifiableMap(libraryScopes);
SCOPES = Collections.unmodifiableMap(libraryScopes);
}
private final Set<Artifact> artifacts;
@ -70,7 +70,7 @@ public class ArtifactsLibraries implements Libraries {
public void doWithLibraries(LibraryCallback callback) throws IOException {
Set<String> duplicates = getDuplicates(this.artifacts);
for (Artifact artifact : this.artifacts) {
LibraryScope scope = scopes.get(artifact.getScope());
LibraryScope scope = SCOPES.get(artifact.getScope());
if (scope != null && artifact.getFile() != null) {
String name = getFileName(artifact);
if (duplicates.contains(name)) {

View File

@ -106,7 +106,7 @@ public enum EmbeddedDatabaseConnection {
*/
public String getUrl(String databaseName) {
Assert.hasText(databaseName, "DatabaseName must not be null.");
return this.url != null ? String.format(this.url, databaseName) : null;
return (this.url != null ? String.format(this.url, databaseName) : null);
}
/**

View File

@ -49,7 +49,7 @@ import org.springframework.boot.ansi.AnsiStyle;
@ConverterKeys({ "clr", "color" })
public final class ColorConverter extends LogEventPatternConverter {
private static final Map<String, AnsiElement> elements;
private static final Map<String, AnsiElement> ELEMENTS;
static {
Map<String, AnsiElement> ansiElements = new HashMap<>();
@ -60,17 +60,17 @@ public final class ColorConverter extends LogEventPatternConverter {
ansiElements.put("blue", AnsiColor.BLUE);
ansiElements.put("magenta", AnsiColor.MAGENTA);
ansiElements.put("cyan", AnsiColor.CYAN);
elements = Collections.unmodifiableMap(ansiElements);
ELEMENTS = Collections.unmodifiableMap(ansiElements);
}
private static final Map<Integer, AnsiElement> levels;
private static final Map<Integer, AnsiElement> LEVELS;
static {
Map<Integer, AnsiElement> ansiLevels = new HashMap<>();
ansiLevels.put(Level.FATAL.intLevel(), AnsiColor.RED);
ansiLevels.put(Level.ERROR.intLevel(), AnsiColor.RED);
ansiLevels.put(Level.WARN.intLevel(), AnsiColor.YELLOW);
levels = Collections.unmodifiableMap(ansiLevels);
LEVELS = Collections.unmodifiableMap(ansiLevels);
}
private final List<PatternFormatter> formatters;
@ -101,7 +101,7 @@ public final class ColorConverter extends LogEventPatternConverter {
}
PatternParser parser = PatternLayout.createPatternParser(config);
List<PatternFormatter> formatters = parser.parse(options[0]);
AnsiElement element = (options.length == 1 ? null : elements.get(options[1]));
AnsiElement element = (options.length == 1 ? null : ELEMENTS.get(options[1]));
return new ColorConverter(formatters, element);
}
@ -125,7 +125,7 @@ public final class ColorConverter extends LogEventPatternConverter {
AnsiElement element = this.styling;
if (element == null) {
// Assume highlighting
element = levels.get(event.getLevel().intLevel());
element = LEVELS.get(event.getLevel().intLevel());
element = (element == null ? AnsiColor.GREEN : element);
}
appendAnsiString(toAppendTo, buf.toString(), element);

View File

@ -38,7 +38,7 @@ import org.springframework.boot.ansi.AnsiStyle;
*/
public class ColorConverter extends CompositeConverter<ILoggingEvent> {
private static final Map<String, AnsiElement> elements;
private static final Map<String, AnsiElement> ELEMENTS;
static {
Map<String, AnsiElement> ansiElements = new HashMap<>();
@ -49,24 +49,24 @@ public class ColorConverter extends CompositeConverter<ILoggingEvent> {
ansiElements.put("blue", AnsiColor.BLUE);
ansiElements.put("magenta", AnsiColor.MAGENTA);
ansiElements.put("cyan", AnsiColor.CYAN);
elements = Collections.unmodifiableMap(ansiElements);
ELEMENTS = Collections.unmodifiableMap(ansiElements);
}
private static final Map<Integer, AnsiElement> levels;
private static final Map<Integer, AnsiElement> LEVELS;
static {
Map<Integer, AnsiElement> ansiLevels = new HashMap<>();
ansiLevels.put(Level.ERROR_INTEGER, AnsiColor.RED);
ansiLevels.put(Level.WARN_INTEGER, AnsiColor.YELLOW);
levels = Collections.unmodifiableMap(ansiLevels);
LEVELS = Collections.unmodifiableMap(ansiLevels);
}
@Override
protected String transform(ILoggingEvent event, String in) {
AnsiElement element = elements.get(getFirstOption());
AnsiElement element = ELEMENTS.get(getFirstOption());
if (element == null) {
// Assume highlighting
element = levels.get(event.getLevel().toInteger());
element = LEVELS.get(event.getLevel().toInteger());
element = (element == null ? AnsiColor.GREEN : element);
}
return toAnsiString(in, element);

View File

@ -66,23 +66,23 @@ public class ApplicationPidFileWriter
private static final String DEFAULT_FILE_NAME = "application.pid";
private static final List<Property> fileProperties;
private static final List<Property> FILE_PROPERTIES;
static {
List<Property> properties = new ArrayList<>();
properties.add(new SpringProperty("spring.pid.", "file"));
properties.add(new SpringProperty("spring.", "pidfile"));
properties.add(new SystemProperty("PIDFILE"));
fileProperties = Collections.unmodifiableList(properties);
FILE_PROPERTIES = Collections.unmodifiableList(properties);
}
private static final List<Property> failOnWriteErrorProperties;
private static final List<Property> FAIL_ON_WRITE_ERROR_PROPERTIES;
static {
List<Property> properties = new ArrayList<>();
properties.add(new SpringProperty("spring.pid.", "fail-on-write-error"));
properties.add(new SystemProperty("PID_FAIL_ON_WRITE_ERROR"));
failOnWriteErrorProperties = Collections.unmodifiableList(properties);
FAIL_ON_WRITE_ERROR_PROPERTIES = Collections.unmodifiableList(properties);
}
private static final AtomicBoolean created = new AtomicBoolean(false);
@ -153,7 +153,7 @@ public class ApplicationPidFileWriter
private void writePidFile(SpringApplicationEvent event) throws IOException {
File pidFile = this.file;
String override = getProperty(event, fileProperties);
String override = getProperty(event, FILE_PROPERTIES);
if (override != null) {
pidFile = new File(override);
}
@ -162,7 +162,7 @@ public class ApplicationPidFileWriter
}
private boolean failOnWriteError(SpringApplicationEvent event) {
String value = getProperty(event, failOnWriteErrorProperties);
String value = getProperty(event, FAIL_ON_WRITE_ERROR_PROPERTIES);
return (value == null ? false : Boolean.parseBoolean(value));
}

View File

@ -43,14 +43,14 @@ import org.springframework.web.context.WebApplicationContext;
class ServletComponentRegisteringPostProcessor
implements BeanFactoryPostProcessor, ApplicationContextAware {
private static final List<ServletComponentHandler> handlers;
private static final List<ServletComponentHandler> HANDLERS;
static {
List<ServletComponentHandler> servletComponentHandlers = new ArrayList<>();
servletComponentHandlers.add(new WebServletHandler());
servletComponentHandlers.add(new WebFilterHandler());
servletComponentHandlers.add(new WebListenerHandler());
handlers = Collections.unmodifiableList(servletComponentHandlers);
HANDLERS = Collections.unmodifiableList(servletComponentHandlers);
}
private final Set<String> packagesToScan;
@ -78,7 +78,7 @@ class ServletComponentRegisteringPostProcessor
for (BeanDefinition candidate : componentProvider
.findCandidateComponents(packageToScan)) {
if (candidate instanceof ScannedGenericBeanDefinition) {
for (ServletComponentHandler handler : handlers) {
for (ServletComponentHandler handler : HANDLERS) {
handler.handle(((ScannedGenericBeanDefinition) candidate),
(BeanDefinitionRegistry) this.applicationContext);
}
@ -97,7 +97,7 @@ class ServletComponentRegisteringPostProcessor
false);
componentProvider.setEnvironment(this.applicationContext.getEnvironment());
componentProvider.setResourceLoader(this.applicationContext);
for (ServletComponentHandler handler : handlers) {
for (ServletComponentHandler handler : HANDLERS) {
componentProvider.addIncludeFilter(handler.getTypeFilter());
}
return componentProvider;

View File

@ -19,6 +19,7 @@ package org.springframework.boot.web.servlet;
import java.util.Collections;
import java.util.EventListener;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.servlet.ServletContext;
@ -104,6 +105,75 @@ public class ServletListenerRegistrationBean<T extends EventListener>
this.listener = listener;
}
/**
* Set the name of this registration. If not specified the bean name will be used.
* @param name the name of the registration
* @deprecated as of 1.5 since not applicable to listeners
*/
@Override
@Deprecated
public void setName(String name) {
super.setName(name);
}
/**
* Sets if asynchronous operations are support for this registration. If not specified
* defaults to {@code true}.
* @param asyncSupported if async is supported
* @deprecated as of 1.5 since not applicable to listeners
*/
@Override
@Deprecated
public void setAsyncSupported(boolean asyncSupported) {
super.setAsyncSupported(asyncSupported);
}
/**
* Returns if asynchronous operations are support for this registration.
* @return if async is supported
* @deprecated as of 1.5 since not applicable to listeners
*/
@Override
@Deprecated
public boolean isAsyncSupported() {
return super.isAsyncSupported();
}
/**
* Set init-parameters for this registration. Calling this method will replace any
* existing init-parameters.
* @param initParameters the init parameters
* @deprecated as of 1.5 since not applicable to listeners
*/
@Override
@Deprecated
public void setInitParameters(Map<String, String> initParameters) {
super.setInitParameters(initParameters);
}
/**
* Returns a mutable Map of the registration init-parameters.
* @return the init parameters
* @deprecated as of 1.5 since not applicable to listeners
*/
@Override
@Deprecated
public Map<String, String> getInitParameters() {
return super.getInitParameters();
}
/**
* Add a single init-parameter, replacing any existing parameter with the same name.
* @param name the init-parameter name
* @param value the init-parameter value
* @deprecated as of 1.5 since not applicable to listeners
*/
@Override
@Deprecated
public void addInitParameter(String name, String value) {
super.addInitParameter(name, value);
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
if (!isEnabled()) {