Merge branch '2.0.x' into 2.1.x
Closes gh-17078
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -50,13 +50,11 @@ public class MetadataStoreTests {
|
||||
File classesLocation = new File(app, "target/classes");
|
||||
File metaInf = new File(classesLocation, "META-INF");
|
||||
metaInf.mkdirs();
|
||||
File additionalMetadata = new File(metaInf,
|
||||
"additional-spring-configuration-metadata.json");
|
||||
File additionalMetadata = new File(metaInf, "additional-spring-configuration-metadata.json");
|
||||
additionalMetadata.createNewFile();
|
||||
assertThat(
|
||||
this.metadataStore.locateAdditionalMetadataFile(new File(classesLocation,
|
||||
"META-INF/additional-spring-configuration-metadata.json")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
assertThat(this.metadataStore.locateAdditionalMetadataFile(
|
||||
new File(classesLocation, "META-INF/additional-spring-configuration-metadata.json")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -66,13 +64,11 @@ public class MetadataStoreTests {
|
||||
File resourcesLocation = new File(app, "build/resources/main");
|
||||
File metaInf = new File(resourcesLocation, "META-INF");
|
||||
metaInf.mkdirs();
|
||||
File additionalMetadata = new File(metaInf,
|
||||
"additional-spring-configuration-metadata.json");
|
||||
File additionalMetadata = new File(metaInf, "additional-spring-configuration-metadata.json");
|
||||
additionalMetadata.createNewFile();
|
||||
assertThat(
|
||||
this.metadataStore.locateAdditionalMetadataFile(new File(classesLocation,
|
||||
"META-INF/additional-spring-configuration-metadata.json")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
assertThat(this.metadataStore.locateAdditionalMetadataFile(
|
||||
new File(classesLocation, "META-INF/additional-spring-configuration-metadata.json")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,13 +78,11 @@ public class MetadataStoreTests {
|
||||
File resourcesLocation = new File(app, "build/resources/main");
|
||||
File metaInf = new File(resourcesLocation, "META-INF");
|
||||
metaInf.mkdirs();
|
||||
File additionalMetadata = new File(metaInf,
|
||||
"additional-spring-configuration-metadata.json");
|
||||
File additionalMetadata = new File(metaInf, "additional-spring-configuration-metadata.json");
|
||||
additionalMetadata.createNewFile();
|
||||
assertThat(
|
||||
this.metadataStore.locateAdditionalMetadataFile(new File(classesLocation,
|
||||
"META-INF/additional-spring-configuration-metadata.json")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
assertThat(this.metadataStore.locateAdditionalMetadataFile(
|
||||
new File(classesLocation, "META-INF/additional-spring-configuration-metadata.json")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,14 +91,12 @@ public class MetadataStoreTests {
|
||||
File location = new File(app, "src/main/resources");
|
||||
File metaInf = new File(location, "META-INF");
|
||||
metaInf.mkdirs();
|
||||
File additionalMetadata = new File(metaInf,
|
||||
"additional-spring-configuration-metadata.json");
|
||||
File additionalMetadata = new File(metaInf, "additional-spring-configuration-metadata.json");
|
||||
additionalMetadata.createNewFile();
|
||||
given(this.environment.getOptions()).willReturn(Collections.singletonMap(
|
||||
ConfigurationMetadataAnnotationProcessor.ADDITIONAL_METADATA_LOCATIONS_OPTION,
|
||||
location.getAbsolutePath()));
|
||||
assertThat(this.metadataStore.locateAdditionalMetadataFile(new File(app, "foo")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
given(this.environment.getOptions()).willReturn(
|
||||
Collections.singletonMap(ConfigurationMetadataAnnotationProcessor.ADDITIONAL_METADATA_LOCATIONS_OPTION,
|
||||
location.getAbsolutePath()));
|
||||
assertThat(this.metadataStore.locateAdditionalMetadataFile(new File(app, "foo"))).isEqualTo(additionalMetadata);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -37,8 +37,7 @@ import org.springframework.boot.configurationprocessor.metadata.JsonMarshaller;
|
||||
*/
|
||||
@SupportedAnnotationTypes({ "*" })
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_6)
|
||||
public class TestConfigurationMetadataAnnotationProcessor
|
||||
extends ConfigurationMetadataAnnotationProcessor {
|
||||
public class TestConfigurationMetadataAnnotationProcessor extends ConfigurationMetadataAnnotationProcessor {
|
||||
|
||||
static final String CONFIGURATION_PROPERTIES_ANNOTATION = "org.springframework.boot.configurationsample.ConfigurationProperties";
|
||||
|
||||
@@ -87,11 +86,9 @@ public class TestConfigurationMetadataAnnotationProcessor
|
||||
protected ConfigurationMetadata writeMetaData() throws Exception {
|
||||
super.writeMetaData();
|
||||
try {
|
||||
File metadataFile = new File(this.outputLocation,
|
||||
"META-INF/spring-configuration-metadata.json");
|
||||
File metadataFile = new File(this.outputLocation, "META-INF/spring-configuration-metadata.json");
|
||||
if (metadataFile.isFile()) {
|
||||
this.metadata = new JsonMarshaller()
|
||||
.read(new FileInputStream(metadataFile));
|
||||
this.metadata = new JsonMarshaller().read(new FileInputStream(metadataFile));
|
||||
}
|
||||
else {
|
||||
this.metadata = new ConfigurationMetadata();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -63,8 +63,7 @@ public class TestProject {
|
||||
|
||||
private Set<File> sourceFiles = new LinkedHashSet<>();
|
||||
|
||||
public TestProject(TemporaryFolder tempFolder, Class<?>... classes)
|
||||
throws IOException {
|
||||
public TestProject(TemporaryFolder tempFolder, Class<?>... classes) throws IOException {
|
||||
this.sourceFolder = tempFolder.newFolder();
|
||||
this.compiler = new TestCompiler(tempFolder) {
|
||||
@Override
|
||||
@@ -133,15 +132,12 @@ public class TestProject {
|
||||
* @param snippetStream the snippet stream
|
||||
* @throws Exception if the source cannot be added
|
||||
*/
|
||||
public void addSourceCode(Class<?> target, InputStream snippetStream)
|
||||
throws Exception {
|
||||
public void addSourceCode(Class<?> target, InputStream snippetStream) throws Exception {
|
||||
File targetFile = getSourceFile(target);
|
||||
String contents = getContents(targetFile);
|
||||
int insertAt = contents.lastIndexOf('}');
|
||||
String additionalSource = FileCopyUtils
|
||||
.copyToString(new InputStreamReader(snippetStream));
|
||||
contents = contents.substring(0, insertAt) + additionalSource
|
||||
+ contents.substring(insertAt);
|
||||
String additionalSource = FileCopyUtils.copyToString(new InputStreamReader(snippetStream));
|
||||
contents = contents.substring(0, insertAt) + additionalSource + contents.substring(insertAt);
|
||||
putContents(targetFile, contents);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,16 +56,12 @@ public class TypeUtilsTests {
|
||||
public void resolveTypeDescriptorOnConcreteClass() throws IOException {
|
||||
process(SimpleGenericProperties.class, (roundEnv, typeUtils) -> {
|
||||
for (Element rootElement : roundEnv.getRootElements()) {
|
||||
TypeDescriptor typeDescriptor = typeUtils
|
||||
.resolveTypeDescriptor((TypeElement) rootElement);
|
||||
assertThat(typeDescriptor.getGenerics().keySet().stream()
|
||||
.map(Object::toString)).containsOnly("A", "B", "C");
|
||||
assertThat(typeDescriptor.resolveGeneric("A"))
|
||||
.hasToString(String.class.getName());
|
||||
assertThat(typeDescriptor.resolveGeneric("B"))
|
||||
.hasToString(Integer.class.getName());
|
||||
assertThat(typeDescriptor.resolveGeneric("C"))
|
||||
.hasToString(Duration.class.getName());
|
||||
TypeDescriptor typeDescriptor = typeUtils.resolveTypeDescriptor((TypeElement) rootElement);
|
||||
assertThat(typeDescriptor.getGenerics().keySet().stream().map(Object::toString)).containsOnly("A", "B",
|
||||
"C");
|
||||
assertThat(typeDescriptor.resolveGeneric("A")).hasToString(String.class.getName());
|
||||
assertThat(typeDescriptor.resolveGeneric("B")).hasToString(Integer.class.getName());
|
||||
assertThat(typeDescriptor.resolveGeneric("C")).hasToString(Duration.class.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -74,14 +70,11 @@ public class TypeUtilsTests {
|
||||
public void resolveTypeDescriptorOnIntermediateClass() throws IOException {
|
||||
process(AbstractIntermediateGenericProperties.class, (roundEnv, typeUtils) -> {
|
||||
for (Element rootElement : roundEnv.getRootElements()) {
|
||||
TypeDescriptor typeDescriptor = typeUtils
|
||||
.resolveTypeDescriptor((TypeElement) rootElement);
|
||||
assertThat(typeDescriptor.getGenerics().keySet().stream()
|
||||
.map(Object::toString)).containsOnly("A", "B", "C");
|
||||
assertThat(typeDescriptor.resolveGeneric("A"))
|
||||
.hasToString(String.class.getName());
|
||||
assertThat(typeDescriptor.resolveGeneric("B"))
|
||||
.hasToString(Integer.class.getName());
|
||||
TypeDescriptor typeDescriptor = typeUtils.resolveTypeDescriptor((TypeElement) rootElement);
|
||||
assertThat(typeDescriptor.getGenerics().keySet().stream().map(Object::toString)).containsOnly("A", "B",
|
||||
"C");
|
||||
assertThat(typeDescriptor.resolveGeneric("A")).hasToString(String.class.getName());
|
||||
assertThat(typeDescriptor.resolveGeneric("B")).hasToString(Integer.class.getName());
|
||||
assertThat(typeDescriptor.resolveGeneric("C")).hasToString("C");
|
||||
}
|
||||
});
|
||||
@@ -91,17 +84,15 @@ public class TypeUtilsTests {
|
||||
public void resolveTypeDescriptorWithOnlyGenerics() throws IOException {
|
||||
process(AbstractGenericProperties.class, (roundEnv, typeUtils) -> {
|
||||
for (Element rootElement : roundEnv.getRootElements()) {
|
||||
TypeDescriptor typeDescriptor = typeUtils
|
||||
.resolveTypeDescriptor((TypeElement) rootElement);
|
||||
assertThat(typeDescriptor.getGenerics().keySet().stream()
|
||||
.map(Object::toString)).containsOnly("A", "B", "C");
|
||||
TypeDescriptor typeDescriptor = typeUtils.resolveTypeDescriptor((TypeElement) rootElement);
|
||||
assertThat(typeDescriptor.getGenerics().keySet().stream().map(Object::toString)).containsOnly("A", "B",
|
||||
"C");
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void process(Class<?> target,
|
||||
BiConsumer<RoundEnvironment, TypeUtils> consumer) throws IOException {
|
||||
private void process(Class<?> target, BiConsumer<RoundEnvironment, TypeUtils> consumer) throws IOException {
|
||||
TestProcessor processor = new TestProcessor(consumer);
|
||||
TestCompiler compiler = new TestCompiler(this.temporaryFolder);
|
||||
compiler.getTask(target).call(processor);
|
||||
@@ -125,8 +116,7 @@ public class TypeUtilsTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(Set<? extends TypeElement> annotations,
|
||||
RoundEnvironment roundEnv) {
|
||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||
this.typeUtilsConsumer.accept(roundEnv, this.typeUtils);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -84,8 +84,7 @@ public abstract class AbstractFieldValuesProcessorTests {
|
||||
assertThat(values.get("stringArrayNone")).isNull();
|
||||
assertThat(values.get("stringEmptyArray")).isEqualTo(new Object[0]);
|
||||
assertThat(values.get("stringArrayConst")).isEqualTo(new Object[] { "OK", "KO" });
|
||||
assertThat(values.get("stringArrayConstElements"))
|
||||
.isEqualTo(new Object[] { "c" });
|
||||
assertThat(values.get("stringArrayConstElements")).isEqualTo(new Object[] { "c" });
|
||||
assertThat(values.get("integerArray")).isEqualTo(new Object[] { 42, 24 });
|
||||
assertThat(values.get("unknownArray")).isNull();
|
||||
assertThat(values.get("durationNone")).isNull();
|
||||
@@ -103,8 +102,7 @@ public abstract class AbstractFieldValuesProcessorTests {
|
||||
assertThat(values.get("dataSizeTerabytes")).isEqualTo("40TB");
|
||||
}
|
||||
|
||||
@SupportedAnnotationTypes({
|
||||
"org.springframework.boot.configurationsample.ConfigurationProperties" })
|
||||
@SupportedAnnotationTypes({ "org.springframework.boot.configurationsample.ConfigurationProperties" })
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_6)
|
||||
private class TestProcessor extends AbstractProcessor {
|
||||
|
||||
@@ -118,14 +116,12 @@ public abstract class AbstractFieldValuesProcessorTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(Set<? extends TypeElement> annotations,
|
||||
RoundEnvironment roundEnv) {
|
||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||
for (TypeElement annotation : annotations) {
|
||||
for (Element element : roundEnv.getElementsAnnotatedWith(annotation)) {
|
||||
if (element instanceof TypeElement) {
|
||||
try {
|
||||
this.values.putAll(
|
||||
this.processor.getFieldValues((TypeElement) element));
|
||||
this.values.putAll(this.processor.getFieldValues((TypeElement) element));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -28,8 +28,7 @@ import static org.junit.Assume.assumeNoException;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class JavaCompilerFieldValuesProcessorTests
|
||||
extends AbstractFieldValuesProcessorTests {
|
||||
public class JavaCompilerFieldValuesProcessorTests extends AbstractFieldValuesProcessorTests {
|
||||
|
||||
@Override
|
||||
protected FieldValuesParser createProcessor(ProcessingEnvironment env) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -44,14 +44,12 @@ public class ConfigurationMetadataTests {
|
||||
|
||||
@Test
|
||||
public void toDashedCaseWordsUnderscore() {
|
||||
assertThat(toDashedCase("Word_With_underscore"))
|
||||
.isEqualTo("word-with-underscore");
|
||||
assertThat(toDashedCase("Word_With_underscore")).isEqualTo("word-with-underscore");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toDashedCaseWordsSeveralUnderscores() {
|
||||
assertThat(toDashedCase("Word___With__underscore"))
|
||||
.isEqualTo("word---with--underscore");
|
||||
assertThat(toDashedCase("Word___With__underscore")).isEqualTo("word---with--underscore");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -34,14 +34,12 @@ public class ItemMetadataTests {
|
||||
|
||||
@Test
|
||||
public void newItemMetadataPrefixWithCamelCaseSuffix() {
|
||||
assertThat(newItemMetadataPrefix("prefix.", "myValue"))
|
||||
.isEqualTo("prefix.my-value");
|
||||
assertThat(newItemMetadataPrefix("prefix.", "myValue")).isEqualTo("prefix.my-value");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newItemMetadataPrefixWithUpperCamelCaseSuffix() {
|
||||
assertThat(newItemMetadataPrefix("prefix.", "MyValue"))
|
||||
.isEqualTo("prefix.my-value");
|
||||
assertThat(newItemMetadataPrefix("prefix.", "MyValue")).isEqualTo("prefix.my-value");
|
||||
}
|
||||
|
||||
private String newItemMetadataPrefix(String prefix, String suffix) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -38,49 +38,34 @@ public class JsonMarshallerTests {
|
||||
@Test
|
||||
public void marshallAndUnmarshal() throws Exception {
|
||||
ConfigurationMetadata metadata = new ConfigurationMetadata();
|
||||
metadata.add(ItemMetadata.newProperty("a", "b", StringBuffer.class.getName(),
|
||||
InputStream.class.getName(), "sourceMethod", "desc", "x",
|
||||
new ItemDeprecation("Deprecation comment", "b.c.d")));
|
||||
metadata.add(ItemMetadata.newProperty("b.c.d", null, null, null, null, null, null,
|
||||
null));
|
||||
metadata.add(
|
||||
ItemMetadata.newProperty("c", null, null, null, null, null, 123, null));
|
||||
metadata.add(
|
||||
ItemMetadata.newProperty("d", null, null, null, null, null, true, null));
|
||||
metadata.add(ItemMetadata.newProperty("e", null, null, null, null, null,
|
||||
new String[] { "y", "n" }, null));
|
||||
metadata.add(ItemMetadata.newProperty("f", null, null, null, null, null,
|
||||
new Boolean[] { true, false }, null));
|
||||
metadata.add(ItemMetadata.newProperty("a", "b", StringBuffer.class.getName(), InputStream.class.getName(),
|
||||
"sourceMethod", "desc", "x", new ItemDeprecation("Deprecation comment", "b.c.d")));
|
||||
metadata.add(ItemMetadata.newProperty("b.c.d", null, null, null, null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("c", null, null, null, null, null, 123, null));
|
||||
metadata.add(ItemMetadata.newProperty("d", null, null, null, null, null, true, null));
|
||||
metadata.add(ItemMetadata.newProperty("e", null, null, null, null, null, new String[] { "y", "n" }, null));
|
||||
metadata.add(ItemMetadata.newProperty("f", null, null, null, null, null, new Boolean[] { true, false }, null));
|
||||
metadata.add(ItemMetadata.newGroup("d", null, null, null));
|
||||
metadata.add(ItemHint.newHint("a.b"));
|
||||
metadata.add(ItemHint.newHint("c", new ItemHint.ValueHint(123, "hey"),
|
||||
new ItemHint.ValueHint(456, null)));
|
||||
metadata.add(ItemHint.newHint("c", new ItemHint.ValueHint(123, "hey"), new ItemHint.ValueHint(456, null)));
|
||||
metadata.add(new ItemHint("d", null,
|
||||
Arrays.asList(
|
||||
new ItemHint.ValueProvider("first",
|
||||
Collections.singletonMap("target", "foo")),
|
||||
Arrays.asList(new ItemHint.ValueProvider("first", Collections.singletonMap("target", "foo")),
|
||||
new ItemHint.ValueProvider("second", null))));
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
JsonMarshaller marshaller = new JsonMarshaller();
|
||||
marshaller.write(metadata, outputStream);
|
||||
ConfigurationMetadata read = marshaller
|
||||
.read(new ByteArrayInputStream(outputStream.toByteArray()));
|
||||
assertThat(read).has(Metadata.withProperty("a.b", StringBuffer.class)
|
||||
.fromSource(InputStream.class).withDescription("desc")
|
||||
.withDefaultValue("x").withDeprecation("Deprecation comment", "b.c.d"));
|
||||
ConfigurationMetadata read = marshaller.read(new ByteArrayInputStream(outputStream.toByteArray()));
|
||||
assertThat(read).has(Metadata.withProperty("a.b", StringBuffer.class).fromSource(InputStream.class)
|
||||
.withDescription("desc").withDefaultValue("x").withDeprecation("Deprecation comment", "b.c.d"));
|
||||
assertThat(read).has(Metadata.withProperty("b.c.d"));
|
||||
assertThat(read).has(Metadata.withProperty("c").withDefaultValue(123));
|
||||
assertThat(read).has(Metadata.withProperty("d").withDefaultValue(true));
|
||||
assertThat(read).has(
|
||||
Metadata.withProperty("e").withDefaultValue(new String[] { "y", "n" }));
|
||||
assertThat(read).has(Metadata.withProperty("f")
|
||||
.withDefaultValue(new Object[] { true, false }));
|
||||
assertThat(read).has(Metadata.withProperty("e").withDefaultValue(new String[] { "y", "n" }));
|
||||
assertThat(read).has(Metadata.withProperty("f").withDefaultValue(new Object[] { true, false }));
|
||||
assertThat(read).has(Metadata.withGroup("d"));
|
||||
assertThat(read).has(Metadata.withHint("a.b"));
|
||||
assertThat(read).has(
|
||||
Metadata.withHint("c").withValue(0, 123, "hey").withValue(1, 456, null));
|
||||
assertThat(read).has(Metadata.withHint("d").withProvider("first", "target", "foo")
|
||||
.withProvider("second"));
|
||||
assertThat(read).has(Metadata.withHint("c").withValue(0, 123, "hey").withValue(1, 456, null));
|
||||
assertThat(read).has(Metadata.withHint("d").withProvider("first", "target", "foo").withProvider("second"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,45 +73,35 @@ public class JsonMarshallerTests {
|
||||
ConfigurationMetadata metadata = new ConfigurationMetadata();
|
||||
metadata.add(ItemHint.newHint("fff"));
|
||||
metadata.add(ItemHint.newHint("eee"));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.bravo", "bbb", null, null,
|
||||
null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.bravo", "aaa", null, null,
|
||||
null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.alpha", "ddd", null, null,
|
||||
null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.alpha", "ccc", null, null,
|
||||
null, null, null, null));
|
||||
metadata.add(ItemMetadata.newGroup("com.acme.bravo",
|
||||
"com.example.AnotherTestProperties", null, null));
|
||||
metadata.add(ItemMetadata.newGroup("com.acme.alpha", "com.example.TestProperties",
|
||||
null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.bravo", "bbb", null, null, null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.bravo", "aaa", null, null, null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.alpha", "ddd", null, null, null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.alpha", "ccc", null, null, null, null, null, null));
|
||||
metadata.add(ItemMetadata.newGroup("com.acme.bravo", "com.example.AnotherTestProperties", null, null));
|
||||
metadata.add(ItemMetadata.newGroup("com.acme.alpha", "com.example.TestProperties", null, null));
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
JsonMarshaller marshaller = new JsonMarshaller();
|
||||
marshaller.write(metadata, outputStream);
|
||||
String json = new String(outputStream.toByteArray());
|
||||
assertThat(json).containsSubsequence("\"groups\"", "\"com.acme.alpha\"",
|
||||
"\"com.acme.bravo\"", "\"properties\"", "\"com.example.alpha.ccc\"",
|
||||
"\"com.example.alpha.ddd\"", "\"com.example.bravo.aaa\"",
|
||||
assertThat(json).containsSubsequence("\"groups\"", "\"com.acme.alpha\"", "\"com.acme.bravo\"", "\"properties\"",
|
||||
"\"com.example.alpha.ccc\"", "\"com.example.alpha.ddd\"", "\"com.example.bravo.aaa\"",
|
||||
"\"com.example.bravo.bbb\"", "\"hints\"", "\"eee\"", "\"fff\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void marshallPutDeprecatedItemsAtTheEnd() throws IOException {
|
||||
ConfigurationMetadata metadata = new ConfigurationMetadata();
|
||||
metadata.add(ItemMetadata.newProperty("com.example.bravo", "bbb", null, null,
|
||||
null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.bravo", "aaa", null, null,
|
||||
null, null, null, new ItemDeprecation(null, null, "warning")));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.alpha", "ddd", null, null,
|
||||
null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.alpha", "ccc", null, null,
|
||||
null, null, null, new ItemDeprecation(null, null, "warning")));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.bravo", "bbb", null, null, null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.bravo", "aaa", null, null, null, null, null,
|
||||
new ItemDeprecation(null, null, "warning")));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.alpha", "ddd", null, null, null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.alpha", "ccc", null, null, null, null, null,
|
||||
new ItemDeprecation(null, null, "warning")));
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
JsonMarshaller marshaller = new JsonMarshaller();
|
||||
marshaller.write(metadata, outputStream);
|
||||
String json = new String(outputStream.toByteArray());
|
||||
assertThat(json).containsSubsequence("\"properties\"",
|
||||
"\"com.example.alpha.ddd\"", "\"com.example.bravo.bbb\"",
|
||||
assertThat(json).containsSubsequence("\"properties\"", "\"com.example.alpha.ddd\"", "\"com.example.bravo.bbb\"",
|
||||
"\"com.example.alpha.ccc\"", "\"com.example.bravo.aaa\"");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -92,9 +92,8 @@ public final class Metadata {
|
||||
this(itemType, name, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
public MetadataItemCondition(ItemType itemType, String name, String type,
|
||||
Class<?> sourceType, String sourceMethod, String description,
|
||||
Object defaultValue, ItemDeprecation deprecation) {
|
||||
public MetadataItemCondition(ItemType itemType, String name, String type, Class<?> sourceType,
|
||||
String sourceMethod, String description, Object defaultValue, ItemDeprecation deprecation) {
|
||||
this.itemType = itemType;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
@@ -139,90 +138,76 @@ public final class Metadata {
|
||||
if (this.type != null && !this.type.equals(itemMetadata.getType())) {
|
||||
return false;
|
||||
}
|
||||
if (this.sourceType != null
|
||||
&& !this.sourceType.getName().equals(itemMetadata.getSourceType())) {
|
||||
if (this.sourceType != null && !this.sourceType.getName().equals(itemMetadata.getSourceType())) {
|
||||
return false;
|
||||
}
|
||||
if (this.sourceMethod != null
|
||||
&& !this.sourceMethod.equals(itemMetadata.getSourceMethod())) {
|
||||
if (this.sourceMethod != null && !this.sourceMethod.equals(itemMetadata.getSourceMethod())) {
|
||||
return false;
|
||||
}
|
||||
if (this.defaultValue != null && !ObjectUtils
|
||||
.nullSafeEquals(this.defaultValue, itemMetadata.getDefaultValue())) {
|
||||
if (this.defaultValue != null
|
||||
&& !ObjectUtils.nullSafeEquals(this.defaultValue, itemMetadata.getDefaultValue())) {
|
||||
return false;
|
||||
}
|
||||
if (this.defaultValue == null && itemMetadata.getDefaultValue() != null) {
|
||||
return false;
|
||||
}
|
||||
if (this.description != null
|
||||
&& !this.description.equals(itemMetadata.getDescription())) {
|
||||
if (this.description != null && !this.description.equals(itemMetadata.getDescription())) {
|
||||
return false;
|
||||
}
|
||||
if (this.deprecation == null && itemMetadata.getDeprecation() != null) {
|
||||
return false;
|
||||
}
|
||||
if (this.deprecation != null
|
||||
&& !this.deprecation.equals(itemMetadata.getDeprecation())) {
|
||||
if (this.deprecation != null && !this.deprecation.equals(itemMetadata.getDeprecation())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public MetadataItemCondition ofType(Class<?> dataType) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, dataType.getName(),
|
||||
this.sourceType, this.sourceMethod, this.description,
|
||||
this.defaultValue, this.deprecation);
|
||||
return new MetadataItemCondition(this.itemType, this.name, dataType.getName(), this.sourceType,
|
||||
this.sourceMethod, this.description, this.defaultValue, this.deprecation);
|
||||
}
|
||||
|
||||
public MetadataItemCondition ofType(String dataType) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, dataType,
|
||||
this.sourceType, this.sourceMethod, this.description,
|
||||
this.defaultValue, this.deprecation);
|
||||
return new MetadataItemCondition(this.itemType, this.name, dataType, this.sourceType, this.sourceMethod,
|
||||
this.description, this.defaultValue, this.deprecation);
|
||||
}
|
||||
|
||||
public MetadataItemCondition fromSource(Class<?> sourceType) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type,
|
||||
sourceType, this.sourceMethod, this.description, this.defaultValue,
|
||||
this.deprecation);
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type, sourceType, this.sourceMethod,
|
||||
this.description, this.defaultValue, this.deprecation);
|
||||
}
|
||||
|
||||
public MetadataItemCondition fromSourceMethod(String sourceMethod) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type,
|
||||
this.sourceType, sourceMethod, this.description, this.defaultValue,
|
||||
this.deprecation);
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type, this.sourceType, sourceMethod,
|
||||
this.description, this.defaultValue, this.deprecation);
|
||||
}
|
||||
|
||||
public MetadataItemCondition withDescription(String description) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type,
|
||||
this.sourceType, this.sourceMethod, description, this.defaultValue,
|
||||
this.deprecation);
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type, this.sourceType, this.sourceMethod,
|
||||
description, this.defaultValue, this.deprecation);
|
||||
}
|
||||
|
||||
public MetadataItemCondition withDefaultValue(Object defaultValue) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type,
|
||||
this.sourceType, this.sourceMethod, this.description, defaultValue,
|
||||
this.deprecation);
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type, this.sourceType, this.sourceMethod,
|
||||
this.description, defaultValue, this.deprecation);
|
||||
}
|
||||
|
||||
public MetadataItemCondition withDeprecation(String reason, String replacement) {
|
||||
return withDeprecation(reason, replacement, null);
|
||||
}
|
||||
|
||||
public MetadataItemCondition withDeprecation(String reason, String replacement,
|
||||
String level) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type,
|
||||
this.sourceType, this.sourceMethod, this.description,
|
||||
this.defaultValue, new ItemDeprecation(reason, replacement, level));
|
||||
public MetadataItemCondition withDeprecation(String reason, String replacement, String level) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type, this.sourceType, this.sourceMethod,
|
||||
this.description, this.defaultValue, new ItemDeprecation(reason, replacement, level));
|
||||
}
|
||||
|
||||
public MetadataItemCondition withNoDeprecation() {
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type,
|
||||
this.sourceType, this.sourceMethod, this.description,
|
||||
this.defaultValue, null);
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type, this.sourceType, this.sourceMethod,
|
||||
this.description, this.defaultValue, null);
|
||||
}
|
||||
|
||||
private ItemMetadata getFirstItemWithName(ConfigurationMetadata metadata,
|
||||
String name) {
|
||||
private ItemMetadata getFirstItemWithName(ConfigurationMetadata metadata, String name) {
|
||||
for (ItemMetadata item : metadata.getItems()) {
|
||||
if (item.isOfItemType(this.itemType) && name.equals(item.getName())) {
|
||||
return item;
|
||||
@@ -247,8 +232,7 @@ public final class Metadata {
|
||||
this.providerConditions = Collections.emptyList();
|
||||
}
|
||||
|
||||
public MetadataHintCondition(String name,
|
||||
List<ItemHintValueCondition> valueConditions,
|
||||
public MetadataHintCondition(String name, List<ItemHintValueCondition> valueConditions,
|
||||
List<ItemHintProviderCondition> providerConditions) {
|
||||
this.name = name;
|
||||
this.valueConditions = valueConditions;
|
||||
@@ -274,12 +258,10 @@ public final class Metadata {
|
||||
if (itemHint == null) {
|
||||
return false;
|
||||
}
|
||||
return matches(itemHint, this.valueConditions)
|
||||
&& matches(itemHint, this.providerConditions);
|
||||
return matches(itemHint, this.valueConditions) && matches(itemHint, this.providerConditions);
|
||||
}
|
||||
|
||||
private boolean matches(ItemHint itemHint,
|
||||
List<? extends Condition<ItemHint>> conditions) {
|
||||
private boolean matches(ItemHint itemHint, List<? extends Condition<ItemHint>> conditions) {
|
||||
for (Condition<ItemHint> condition : conditions) {
|
||||
if (!condition.matches(itemHint)) {
|
||||
return false;
|
||||
@@ -288,8 +270,7 @@ public final class Metadata {
|
||||
return true;
|
||||
}
|
||||
|
||||
private ItemHint getFirstHintWithName(ConfigurationMetadata metadata,
|
||||
String name) {
|
||||
private ItemHint getFirstHintWithName(ConfigurationMetadata metadata, String name) {
|
||||
for (ItemHint hint : metadata.getHints()) {
|
||||
if (name.equals(hint.getName())) {
|
||||
return hint;
|
||||
@@ -298,11 +279,9 @@ public final class Metadata {
|
||||
return null;
|
||||
}
|
||||
|
||||
public MetadataHintCondition withValue(int index, Object value,
|
||||
String description) {
|
||||
public MetadataHintCondition withValue(int index, Object value, String description) {
|
||||
return new MetadataHintCondition(this.name,
|
||||
add(this.valueConditions,
|
||||
new ItemHintValueCondition(index, value, description)),
|
||||
add(this.valueConditions, new ItemHintValueCondition(index, value, description)),
|
||||
this.providerConditions);
|
||||
}
|
||||
|
||||
@@ -310,17 +289,13 @@ public final class Metadata {
|
||||
return withProvider(this.providerConditions.size(), provider, null);
|
||||
}
|
||||
|
||||
public MetadataHintCondition withProvider(String provider, String key,
|
||||
Object value) {
|
||||
return withProvider(this.providerConditions.size(), provider,
|
||||
Collections.singletonMap(key, value));
|
||||
public MetadataHintCondition withProvider(String provider, String key, Object value) {
|
||||
return withProvider(this.providerConditions.size(), provider, Collections.singletonMap(key, value));
|
||||
}
|
||||
|
||||
public MetadataHintCondition withProvider(int index, String provider,
|
||||
Map<String, Object> parameters) {
|
||||
public MetadataHintCondition withProvider(int index, String provider, Map<String, Object> parameters) {
|
||||
return new MetadataHintCondition(this.name, this.valueConditions,
|
||||
add(this.providerConditions,
|
||||
new ItemHintProviderCondition(index, provider, parameters)));
|
||||
add(this.providerConditions, new ItemHintProviderCondition(index, provider, parameters)));
|
||||
}
|
||||
|
||||
private <T> List<T> add(List<T> items, T item) {
|
||||
@@ -367,8 +342,7 @@ public final class Metadata {
|
||||
if (this.value != null && !this.value.equals(valueHint.getValue())) {
|
||||
return false;
|
||||
}
|
||||
if (this.description != null
|
||||
&& !this.description.equals(valueHint.getDescription())) {
|
||||
if (this.description != null && !this.description.equals(valueHint.getDescription())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -384,8 +358,7 @@ public final class Metadata {
|
||||
|
||||
private final Map<String, Object> parameters;
|
||||
|
||||
ItemHintProviderCondition(int index, String name,
|
||||
Map<String, Object> parameters) {
|
||||
ItemHintProviderCondition(int index, String name, Map<String, Object> parameters) {
|
||||
this.index = index;
|
||||
this.name = name;
|
||||
this.parameters = parameters;
|
||||
|
||||
@@ -22,7 +22,6 @@ package org.springframework.boot.configurationsample.generic;
|
||||
* @param <C> mapping value type
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public abstract class AbstractIntermediateGenericProperties<C>
|
||||
extends AbstractGenericProperties<String, Integer, C> {
|
||||
public abstract class AbstractIntermediateGenericProperties<C> extends AbstractGenericProperties<String, Integer, C> {
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.springframework.boot.configurationsample.ConfigurationProperties;
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ConfigurationProperties("generic")
|
||||
public class SimpleGenericProperties
|
||||
extends AbstractIntermediateGenericProperties<Duration> {
|
||||
public class SimpleGenericProperties extends AbstractIntermediateGenericProperties<Duration> {
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.springframework.boot.configurationsample.ConfigurationProperties;
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ConfigurationProperties("generic")
|
||||
public class UnresolvedGenericProperties<B extends Number, C>
|
||||
extends AbstractGenericProperties<String, B, C> {
|
||||
public class UnresolvedGenericProperties<B extends Number, C> extends AbstractGenericProperties<String, B, C> {
|
||||
|
||||
}
|
||||
|
||||
@@ -30,8 +30,7 @@ public class DeprecatedSingleProperty {
|
||||
private String newName;
|
||||
|
||||
@Deprecated
|
||||
@DeprecatedConfigurationProperty(reason = "renamed",
|
||||
replacement = "singledeprecated.new-name")
|
||||
@DeprecatedConfigurationProperty(reason = "renamed", replacement = "singledeprecated.new-name")
|
||||
public String getName() {
|
||||
return getNewName();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -21,8 +21,7 @@ package org.springframework.boot.configurationsample.simple;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public abstract class HierarchicalPropertiesParent
|
||||
extends HierarchicalPropertiesGrandparent {
|
||||
public abstract class HierarchicalPropertiesParent extends HierarchicalPropertiesGrandparent {
|
||||
|
||||
private String second;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user