Polish
This commit is contained in:
parent
71ab5dd748
commit
8e783cdae9
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.web;
|
package org.springframework.boot.autoconfigure.web;
|
||||||
|
|
||||||
|
import reactor.core.support.Assert;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
@ -80,14 +82,11 @@ public class ServerPropertiesAutoConfiguration {
|
||||||
// a single bean
|
// a single bean
|
||||||
String[] serverPropertiesBeans = this.applicationContext
|
String[] serverPropertiesBeans = this.applicationContext
|
||||||
.getBeanNamesForType(ServerProperties.class);
|
.getBeanNamesForType(ServerProperties.class);
|
||||||
if (serverPropertiesBeans.length == 0) {
|
Assert.state(serverPropertiesBeans.length != 0,
|
||||||
throw new IllegalStateException("No ServerProperties bean registered");
|
"No ServerProperties registered");
|
||||||
}
|
Assert.state(serverPropertiesBeans.length == 1,
|
||||||
if (serverPropertiesBeans.length > 1) {
|
"Multiple ServerProperties registered " + StringUtils
|
||||||
throw new IllegalStateException(
|
.arrayToCommaDelimitedString(serverPropertiesBeans));
|
||||||
"Multiple ServerProperties beans registered " + StringUtils
|
|
||||||
.arrayToCommaDelimitedString(serverPropertiesBeans));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
@ -34,7 +33,6 @@
|
||||||
<!-- this override is required to reproduce an issue -->
|
<!-- this override is required to reproduce an issue -->
|
||||||
<version>2.0.1.Final</version>
|
<version>2.0.1.Final</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
|
|
|
@ -44,8 +44,8 @@ public class ConfigurationProcessorIntegrationTests {
|
||||||
"META-INF/spring-configuration-metadata.json");
|
"META-INF/spring-configuration-metadata.json");
|
||||||
assertThat(resource.exists()).isTrue();
|
assertThat(resource.exists()).isTrue();
|
||||||
// Make sure the right file is detected
|
// Make sure the right file is detected
|
||||||
assertThat(resource.getURL().toString()).contains(
|
assertThat(resource.getURL().toString())
|
||||||
"spring-boot-configuration-processor-tests");
|
.contains("spring-boot-configuration-processor-tests");
|
||||||
repository = ConfigurationMetadataRepositoryJsonBuilder
|
repository = ConfigurationMetadataRepositoryJsonBuilder
|
||||||
.create(resource.getInputStream()).build();
|
.create(resource.getInputStream()).build();
|
||||||
|
|
||||||
|
@ -53,8 +53,8 @@ public class ConfigurationProcessorIntegrationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void extractTypeFromAnnotatedGetter() {
|
public void extractTypeFromAnnotatedGetter() {
|
||||||
ConfigurationMetadataProperty property = repository.getAllProperties().get(
|
ConfigurationMetadataProperty property = repository.getAllProperties()
|
||||||
"annotated.name");
|
.get("annotated.name");
|
||||||
assertThat(property).isNotNull();
|
assertThat(property).isNotNull();
|
||||||
assertThat(property.getType()).isEqualTo("java.lang.String");
|
assertThat(property.getType()).isEqualTo("java.lang.String");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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.
|
||||||
|
@ -75,8 +75,9 @@ class DuplicateJsonObjectContextCustomizerFactory implements ContextCustomizerFa
|
||||||
}
|
}
|
||||||
|
|
||||||
private void logDuplicateJsonObjectsWarning(List<URL> jsonObjects) {
|
private void logDuplicateJsonObjectsWarning(List<URL> jsonObjects) {
|
||||||
StringBuilder message = new StringBuilder(String.format("%n%nFound multiple occurrences of"
|
StringBuilder message = new StringBuilder(
|
||||||
+ " org.json.JSONObject on the class path:%n%n"));
|
String.format("%n%nFound multiple occurrences of"
|
||||||
|
+ " org.json.JSONObject on the class path:%n%n"));
|
||||||
for (URL jsonObject : jsonObjects) {
|
for (URL jsonObject : jsonObjects) {
|
||||||
message.append(String.format("\t%s%n", jsonObject));
|
message.append(String.format("\t%s%n", jsonObject));
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,7 +168,6 @@ class TypeUtils {
|
||||||
return WRAPPER_TO_PRIMITIVE.get(type.toString());
|
return WRAPPER_TO_PRIMITIVE.get(type.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A visitor that extracts the full qualified name of a type, including generic
|
* A visitor that extracts the full qualified name of a type, including generic
|
||||||
* information.
|
* information.
|
||||||
|
@ -188,21 +187,24 @@ class TypeUtils {
|
||||||
return getQualifiedName(enclosingElement) + "$"
|
return getQualifiedName(enclosingElement) + "$"
|
||||||
+ type.asElement().getSimpleName().toString();
|
+ type.asElement().getSimpleName().toString();
|
||||||
}
|
}
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder name = new StringBuilder();
|
||||||
sb.append(getQualifiedName(type.asElement()));
|
name.append(getQualifiedName(type.asElement()));
|
||||||
if (!type.getTypeArguments().isEmpty()) {
|
if (!type.getTypeArguments().isEmpty()) {
|
||||||
sb.append("<");
|
appendTypeArguments(type, name);
|
||||||
Iterator<?> it = type.getTypeArguments().iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
sb.append(it.next());
|
|
||||||
if (it.hasNext()) {
|
|
||||||
sb.append(",");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sb.append(">");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return name.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendTypeArguments(DeclaredType type, StringBuilder name) {
|
||||||
|
name.append("<");
|
||||||
|
Iterator<?> iterator = type.getTypeArguments().iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
name.append(iterator.next());
|
||||||
|
if (iterator.hasNext()) {
|
||||||
|
name.append(",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
name.append(">");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -223,7 +225,7 @@ class TypeUtils {
|
||||||
if (enclosingElement != null) {
|
if (enclosingElement != null) {
|
||||||
return getQualifiedName(enclosingElement) + "$"
|
return getQualifiedName(enclosingElement) + "$"
|
||||||
+ ((DeclaredType) element.asType()).asElement().getSimpleName()
|
+ ((DeclaredType) element.asType()).asElement().getSimpleName()
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
if (element instanceof TypeElement) {
|
if (element instanceof TypeElement) {
|
||||||
return ((TypeElement) element).getQualifiedName().toString();
|
return ((TypeElement) element).getQualifiedName().toString();
|
||||||
|
|
|
@ -261,12 +261,12 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||||
@Test
|
@Test
|
||||||
public void parseArrayConfig() throws Exception {
|
public void parseArrayConfig() throws Exception {
|
||||||
ConfigurationMetadata metadata = compile(SimpleArrayProperties.class);
|
ConfigurationMetadata metadata = compile(SimpleArrayProperties.class);
|
||||||
assertThat(metadata).has(Metadata.withGroup("array")
|
assertThat(metadata)
|
||||||
.ofType(SimpleArrayProperties.class));
|
.has(Metadata.withGroup("array").ofType(SimpleArrayProperties.class));
|
||||||
assertThat(metadata).has(Metadata.withProperty("array.primitive",
|
assertThat(metadata)
|
||||||
"java.lang.Integer[]"));
|
.has(Metadata.withProperty("array.primitive", "java.lang.Integer[]"));
|
||||||
assertThat(metadata).has(Metadata.withProperty("array.simple",
|
assertThat(metadata)
|
||||||
"java.lang.String[]"));
|
.has(Metadata.withProperty("array.simple", "java.lang.String[]"));
|
||||||
assertThat(metadata).has(Metadata.withProperty("array.inner",
|
assertThat(metadata).has(Metadata.withProperty("array.inner",
|
||||||
"org.springframework.boot.configurationsample.simple.SimpleArrayProperties$Holder[]"));
|
"org.springframework.boot.configurationsample.simple.SimpleArrayProperties$Holder[]"));
|
||||||
assertThat(metadata).has(Metadata.withProperty("array.name-to-integer",
|
assertThat(metadata).has(Metadata.withProperty("array.name-to-integer",
|
||||||
|
@ -464,8 +464,8 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||||
@Test
|
@Test
|
||||||
public void wildcardTypes() throws IOException {
|
public void wildcardTypes() throws IOException {
|
||||||
ConfigurationMetadata metadata = compile(WildcardConfig.class);
|
ConfigurationMetadata metadata = compile(WildcardConfig.class);
|
||||||
assertThat(metadata).has(Metadata.withGroup("wildcard")
|
assertThat(metadata)
|
||||||
.ofType(WildcardConfig.class));
|
.has(Metadata.withGroup("wildcard").ofType(WildcardConfig.class));
|
||||||
assertThat(metadata).has(Metadata.withProperty("wildcard.string-to-number")
|
assertThat(metadata).has(Metadata.withProperty("wildcard.string-to-number")
|
||||||
.ofType("java.util.Map<java.lang.String,? extends java.lang.Number>")
|
.ofType("java.util.Map<java.lang.String,? extends java.lang.Number>")
|
||||||
.fromSource(WildcardConfig.class));
|
.fromSource(WildcardConfig.class));
|
||||||
|
|
|
@ -89,6 +89,7 @@ public class SimpleCollectionProperties {
|
||||||
|
|
||||||
public static class Holder<T> {
|
public static class Holder<T> {
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
private T target;
|
private T target;
|
||||||
|
|
||||||
public void setTarget(T target) {
|
public void setTarget(T target) {
|
||||||
|
|
|
@ -68,8 +68,8 @@ public class LiquibaseServiceLocatorApplicationListenerTests {
|
||||||
SpringApplication application = new SpringApplication(Conf.class);
|
SpringApplication application = new SpringApplication(Conf.class);
|
||||||
application.setWebEnvironment(false);
|
application.setWebEnvironment(false);
|
||||||
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
|
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
|
||||||
resourceLoader.setClassLoader(new ClassHidingClassLoader(
|
resourceLoader.setClassLoader(
|
||||||
CustomResolverServiceLocator.class));
|
new ClassHidingClassLoader(CustomResolverServiceLocator.class));
|
||||||
application.setResourceLoader(resourceLoader);
|
application.setResourceLoader(resourceLoader);
|
||||||
this.context = application.run();
|
this.context = application.run();
|
||||||
Object resolver = getServiceLocator();
|
Object resolver = getServiceLocator();
|
||||||
|
@ -93,7 +93,8 @@ public class LiquibaseServiceLocatorApplicationListenerTests {
|
||||||
private final List<Class<?>> hiddenClasses;
|
private final List<Class<?>> hiddenClasses;
|
||||||
|
|
||||||
private ClassHidingClassLoader(Class<?>... hiddenClasses) {
|
private ClassHidingClassLoader(Class<?>... hiddenClasses) {
|
||||||
super(new URL[0], LiquibaseServiceLocatorApplicationListenerTests.class.getClassLoader());
|
super(new URL[0], LiquibaseServiceLocatorApplicationListenerTests.class
|
||||||
|
.getClassLoader());
|
||||||
this.hiddenClasses = Arrays.asList(hiddenClasses);
|
this.hiddenClasses = Arrays.asList(hiddenClasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue