Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 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.
|
||||||
@@ -748,8 +748,7 @@ class ConfigurationClassParser {
|
|||||||
* @param importSelector the selector to handle
|
* @param importSelector the selector to handle
|
||||||
*/
|
*/
|
||||||
public void handle(ConfigurationClass configClass, DeferredImportSelector importSelector) {
|
public void handle(ConfigurationClass configClass, DeferredImportSelector importSelector) {
|
||||||
DeferredImportSelectorHolder holder = new DeferredImportSelectorHolder(
|
DeferredImportSelectorHolder holder = new DeferredImportSelectorHolder(configClass, importSelector);
|
||||||
configClass, importSelector);
|
|
||||||
if (this.deferredImportSelectors == null) {
|
if (this.deferredImportSelectors == null) {
|
||||||
DeferredImportSelectorGroupingHandler handler = new DeferredImportSelectorGroupingHandler();
|
DeferredImportSelectorGroupingHandler handler = new DeferredImportSelectorGroupingHandler();
|
||||||
handler.register(holder);
|
handler.register(holder);
|
||||||
@@ -775,7 +774,6 @@ class ConfigurationClassParser {
|
|||||||
this.deferredImportSelectors = new ArrayList<>();
|
this.deferredImportSelectors = new ArrayList<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -786,8 +784,7 @@ class ConfigurationClassParser {
|
|||||||
private final Map<AnnotationMetadata, ConfigurationClass> configurationClasses = new HashMap<>();
|
private final Map<AnnotationMetadata, ConfigurationClass> configurationClasses = new HashMap<>();
|
||||||
|
|
||||||
public void register(DeferredImportSelectorHolder deferredImport) {
|
public void register(DeferredImportSelectorHolder deferredImport) {
|
||||||
Class<? extends Group> group = deferredImport.getImportSelector()
|
Class<? extends Group> group = deferredImport.getImportSelector().getImportGroup();
|
||||||
.getImportGroup();
|
|
||||||
DeferredImportSelectorGrouping grouping = this.groupings.computeIfAbsent(
|
DeferredImportSelectorGrouping grouping = this.groupings.computeIfAbsent(
|
||||||
(group != null ? group : deferredImport),
|
(group != null ? group : deferredImport),
|
||||||
key -> new DeferredImportSelectorGrouping(createGroup(group)));
|
key -> new DeferredImportSelectorGrouping(createGroup(group)));
|
||||||
@@ -799,8 +796,7 @@ class ConfigurationClassParser {
|
|||||||
public void processGroupImports() {
|
public void processGroupImports() {
|
||||||
for (DeferredImportSelectorGrouping grouping : this.groupings.values()) {
|
for (DeferredImportSelectorGrouping grouping : this.groupings.values()) {
|
||||||
grouping.getImports().forEach(entry -> {
|
grouping.getImports().forEach(entry -> {
|
||||||
ConfigurationClass configurationClass = this.configurationClasses.get(
|
ConfigurationClass configurationClass = this.configurationClasses.get(entry.getMetadata());
|
||||||
entry.getMetadata());
|
|
||||||
try {
|
try {
|
||||||
processImports(configurationClass, asSourceClass(configurationClass),
|
processImports(configurationClass, asSourceClass(configurationClass),
|
||||||
asSourceClasses(entry.getImportClassName()), false);
|
asSourceClasses(entry.getImportClassName()), false);
|
||||||
@@ -818,8 +814,7 @@ class ConfigurationClassParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Group createGroup(@Nullable Class<? extends Group> type) {
|
private Group createGroup(@Nullable Class<? extends Group> type) {
|
||||||
Class<? extends Group> effectiveType = (type != null ? type
|
Class<? extends Group> effectiveType = (type != null ? type : DefaultDeferredImportSelectorGroup.class);
|
||||||
: DefaultDeferredImportSelectorGroup.class);
|
|
||||||
Group group = BeanUtils.instantiateClass(effectiveType);
|
Group group = BeanUtils.instantiateClass(effectiveType);
|
||||||
ParserStrategyUtils.invokeAwareMethods(group,
|
ParserStrategyUtils.invokeAwareMethods(group,
|
||||||
ConfigurationClassParser.this.environment,
|
ConfigurationClassParser.this.environment,
|
||||||
@@ -827,7 +822,6 @@ class ConfigurationClassParser {
|
|||||||
ConfigurationClassParser.this.registry);
|
ConfigurationClassParser.this.registry);
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 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.
|
||||||
@@ -51,6 +51,7 @@ public interface DeferredImportSelector extends ImportSelector {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface used to group results from different import selectors.
|
* Interface used to group results from different import selectors.
|
||||||
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
interface Group {
|
interface Group {
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2020 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.
|
||||||
@@ -50,6 +50,7 @@ public interface ImportSelector {
|
|||||||
/**
|
/**
|
||||||
* Select and return the names of which class(es) should be imported based on
|
* Select and return the names of which class(es) should be imported based on
|
||||||
* the {@link AnnotationMetadata} of the importing @{@link Configuration} class.
|
* the {@link AnnotationMetadata} of the importing @{@link Configuration} class.
|
||||||
|
* @return the class names, or an empty array if none
|
||||||
*/
|
*/
|
||||||
String[] selectImports(AnnotationMetadata importingClassMetadata);
|
String[] selectImports(AnnotationMetadata importingClassMetadata);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2018 the original author or authors.
|
* Copyright 2002-2020 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.
|
||||||
@@ -530,9 +530,10 @@ public class ImportSelectorTests {
|
|||||||
static Map<String, List<String>> allImports() {
|
static Map<String, List<String>> allImports() {
|
||||||
return TestImportGroup.imports.entrySet()
|
return TestImportGroup.imports.entrySet()
|
||||||
.stream()
|
.stream()
|
||||||
.collect(Collectors.toMap((entry) -> entry.getKey().getClassName(),
|
.collect(Collectors.toMap(entry -> entry.getKey().getClassName(),
|
||||||
Map.Entry::getValue));
|
Map.Entry::getValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
private final List<Entry> instanceImports = new ArrayList<>();
|
private final List<Entry> instanceImports = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2020 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.
|
||||||
@@ -52,10 +52,10 @@ public abstract class DatabasePopulatorUtils {
|
|||||||
DataSourceUtils.releaseConnection(connection, dataSource);
|
DataSourceUtils.releaseConnection(connection, dataSource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (ScriptException ex) {
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
catch (Throwable ex) {
|
catch (Throwable ex) {
|
||||||
if (ex instanceof ScriptException) {
|
|
||||||
throw (ScriptException) ex;
|
|
||||||
}
|
|
||||||
throw new UncategorizedScriptException("Failed to execute database script", ex);
|
throw new UncategorizedScriptException("Failed to execute database script", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport imple
|
|||||||
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
|
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
|
||||||
|
|
||||||
boolean forceUseOfBigDecimal = getObjectMapper().isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
|
boolean forceUseOfBigDecimal = getObjectMapper().isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
|
||||||
if (elementType != null && BigDecimal.class.equals(elementType.getType())) {
|
if (BigDecimal.class.equals(elementType.getType())) {
|
||||||
forceUseOfBigDecimal = true;
|
forceUseOfBigDecimal = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,9 +130,10 @@ public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport imple
|
|||||||
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
|
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
|
||||||
|
|
||||||
boolean forceUseOfBigDecimal = getObjectMapper().isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
|
boolean forceUseOfBigDecimal = getObjectMapper().isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
|
||||||
if (elementType != null && BigDecimal.class.equals(elementType.getType())) {
|
if (BigDecimal.class.equals(elementType.getType())) {
|
||||||
forceUseOfBigDecimal = true;
|
forceUseOfBigDecimal = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Flux<TokenBuffer> tokens = Jackson2Tokenizer.tokenize(Flux.from(input), this.jsonFactory, getObjectMapper(),
|
Flux<TokenBuffer> tokens = Jackson2Tokenizer.tokenize(Flux.from(input), this.jsonFactory, getObjectMapper(),
|
||||||
false, forceUseOfBigDecimal, getMaxInMemorySize());
|
false, forceUseOfBigDecimal, getMaxInMemorySize());
|
||||||
return decodeInternal(tokens, elementType, mimeType, hints).singleOrEmpty();
|
return decodeInternal(tokens, elementType, mimeType, hints).singleOrEmpty();
|
||||||
@@ -177,7 +178,7 @@ public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport imple
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// HttpMessageDecoder...
|
// HttpMessageDecoder
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> getDecodeHints(ResolvableType actualType, ResolvableType elementType,
|
public Map<String, Object> getDecodeHints(ResolvableType actualType, ResolvableType elementType,
|
||||||
@@ -191,7 +192,8 @@ public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport imple
|
|||||||
return getMimeTypes();
|
return getMimeTypes();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Jackson2CodecSupport ...
|
|
||||||
|
// Jackson2CodecSupport
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <A extends Annotation> A getAnnotation(MethodParameter parameter, Class<A> annotType) {
|
protected <A extends Annotation> A getAnnotation(MethodParameter parameter, Class<A> annotType) {
|
||||||
|
|||||||
@@ -170,8 +170,7 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple
|
|||||||
throw new EncodingException("JSON encoding error: " + ex.getOriginalMessage(), ex);
|
throw new EncodingException("JSON encoding error: " + ex.getOriginalMessage(), ex);
|
||||||
}
|
}
|
||||||
catch (IOException ex) {
|
catch (IOException ex) {
|
||||||
throw new IllegalStateException("Unexpected I/O error while writing to byte array builder",
|
throw new IllegalStateException("Unexpected I/O error while writing to byte array builder", ex);
|
||||||
ex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] bytes = byteBuilder.toByteArray();
|
byte[] bytes = byteBuilder.toByteArray();
|
||||||
@@ -197,8 +196,7 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple
|
|||||||
throw new EncodingException("JSON encoding error: " + ex.getOriginalMessage(), ex);
|
throw new EncodingException("JSON encoding error: " + ex.getOriginalMessage(), ex);
|
||||||
}
|
}
|
||||||
catch (IOException ex) {
|
catch (IOException ex) {
|
||||||
throw new IllegalStateException("Unexpected I/O error while writing to byte array builder",
|
throw new IllegalStateException("Unexpected I/O error while writing to byte array builder", ex);
|
||||||
ex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] bytes = byteArrayBuilder.toByteArray();
|
byte[] bytes = byteArrayBuilder.toByteArray();
|
||||||
@@ -233,6 +231,7 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple
|
|||||||
|
|
||||||
private ObjectWriter createObjectWriter(ResolvableType valueType, @Nullable MimeType mimeType,
|
private ObjectWriter createObjectWriter(ResolvableType valueType, @Nullable MimeType mimeType,
|
||||||
@Nullable Map<String, Object> hints) {
|
@Nullable Map<String, Object> hints) {
|
||||||
|
|
||||||
JavaType javaType = getJavaType(valueType.getType(), null);
|
JavaType javaType = getJavaType(valueType.getType(), null);
|
||||||
Class<?> jsonView = (hints != null ? (Class<?>) hints.get(Jackson2CodecSupport.JSON_VIEW_HINT) : null);
|
Class<?> jsonView = (hints != null ? (Class<?>) hints.get(Jackson2CodecSupport.JSON_VIEW_HINT) : null);
|
||||||
ObjectWriter writer = (jsonView != null ?
|
ObjectWriter writer = (jsonView != null ?
|
||||||
@@ -280,7 +279,7 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// HttpMessageEncoder...
|
// HttpMessageEncoder
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MimeType> getEncodableMimeTypes() {
|
public List<MimeType> getEncodableMimeTypes() {
|
||||||
@@ -299,7 +298,8 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple
|
|||||||
return (actualType != null ? getHints(actualType) : Hints.none());
|
return (actualType != null ? getHints(actualType) : Hints.none());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Jackson2CodecSupport ...
|
|
||||||
|
// Jackson2CodecSupport
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <A extends Annotation> A getAnnotation(MethodParameter parameter, Class<A> annotType) {
|
protected <A extends Annotation> A getAnnotation(MethodParameter parameter, Class<A> annotType) {
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ import org.springframework.core.codec.DecodingException;
|
|||||||
import org.springframework.core.io.buffer.DataBuffer;
|
import org.springframework.core.io.buffer.DataBuffer;
|
||||||
import org.springframework.core.io.buffer.DataBufferLimitException;
|
import org.springframework.core.io.buffer.DataBufferLimitException;
|
||||||
import org.springframework.core.io.buffer.DataBufferUtils;
|
import org.springframework.core.io.buffer.DataBufferUtils;
|
||||||
import org.springframework.lang.Nullable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link Function} to transform a JSON stream of arbitrary size, byte array
|
* {@link Function} to transform a JSON stream of arbitrary size, byte array
|
||||||
@@ -66,7 +65,6 @@ final class Jackson2Tokenizer {
|
|||||||
|
|
||||||
private int byteCount;
|
private int byteCount;
|
||||||
|
|
||||||
@Nullable // yet initialized by calling createToken() in the constructor
|
|
||||||
private TokenBuffer tokenBuffer;
|
private TokenBuffer tokenBuffer;
|
||||||
|
|
||||||
|
|
||||||
@@ -84,7 +82,7 @@ final class Jackson2Tokenizer {
|
|||||||
this.forceUseOfBigDecimal = forceUseOfBigDecimal;
|
this.forceUseOfBigDecimal = forceUseOfBigDecimal;
|
||||||
this.inputFeeder = (ByteArrayFeeder) this.parser.getNonBlockingInputFeeder();
|
this.inputFeeder = (ByteArrayFeeder) this.parser.getNonBlockingInputFeeder();
|
||||||
this.maxInMemorySize = maxInMemorySize;
|
this.maxInMemorySize = maxInMemorySize;
|
||||||
createToken();
|
this.tokenBuffer = createToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -174,9 +172,8 @@ final class Jackson2Tokenizer {
|
|||||||
|
|
||||||
if ((token.isStructEnd() || token.isScalarValue()) && this.objectDepth == 0 && this.arrayDepth == 0) {
|
if ((token.isStructEnd() || token.isScalarValue()) && this.objectDepth == 0 && this.arrayDepth == 0) {
|
||||||
result.add(this.tokenBuffer);
|
result.add(this.tokenBuffer);
|
||||||
createToken();
|
this.tokenBuffer = createToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processTokenArray(JsonToken token, List<TokenBuffer> result) throws IOException {
|
private void processTokenArray(JsonToken token, List<TokenBuffer> result) throws IOException {
|
||||||
@@ -187,13 +184,14 @@ final class Jackson2Tokenizer {
|
|||||||
if (this.objectDepth == 0 && (this.arrayDepth == 0 || this.arrayDepth == 1) &&
|
if (this.objectDepth == 0 && (this.arrayDepth == 0 || this.arrayDepth == 1) &&
|
||||||
(token == JsonToken.END_OBJECT || token.isScalarValue())) {
|
(token == JsonToken.END_OBJECT || token.isScalarValue())) {
|
||||||
result.add(this.tokenBuffer);
|
result.add(this.tokenBuffer);
|
||||||
createToken();
|
this.tokenBuffer = createToken();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createToken() {
|
private TokenBuffer createToken() {
|
||||||
this.tokenBuffer = new TokenBuffer(this.parser, this.deserializationContext);
|
TokenBuffer tokenBuffer = new TokenBuffer(this.parser, this.deserializationContext);
|
||||||
this.tokenBuffer.forceUseOfBigDecimal(this.forceUseOfBigDecimal);
|
tokenBuffer.forceUseOfBigDecimal(this.forceUseOfBigDecimal);
|
||||||
|
return tokenBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isTopLevelArrayToken(JsonToken token) {
|
private boolean isTopLevelArrayToken(JsonToken token) {
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ import org.springframework.web.util.UriTemplateHandler;
|
|||||||
*/
|
*/
|
||||||
public class RestTemplate extends InterceptingHttpAccessor implements RestOperations {
|
public class RestTemplate extends InterceptingHttpAccessor implements RestOperations {
|
||||||
|
|
||||||
private static boolean romePresent;
|
private static final boolean romePresent;
|
||||||
|
|
||||||
private static final boolean jaxb2Present;
|
private static final boolean jaxb2Present;
|
||||||
|
|
||||||
@@ -200,6 +200,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
|||||||
this.uriTemplateHandler = initUriTemplateHandler();
|
this.uriTemplateHandler = initUriTemplateHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static DefaultUriBuilderFactory initUriTemplateHandler() {
|
private static DefaultUriBuilderFactory initUriTemplateHandler() {
|
||||||
DefaultUriBuilderFactory uriFactory = new DefaultUriBuilderFactory();
|
DefaultUriBuilderFactory uriFactory = new DefaultUriBuilderFactory();
|
||||||
uriFactory.setEncodingMode(EncodingMode.URI_COMPONENT); // for backwards compatibility..
|
uriFactory.setEncodingMode(EncodingMode.URI_COMPONENT); // for backwards compatibility..
|
||||||
|
|||||||
Reference in New Issue
Block a user