Merge branch '2.7.x' into 3.0.x
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@@ -103,7 +103,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
static final String AUTO_CONFIGURATION_ANNOTATION = "org.springframework.boot.autoconfigure.AutoConfiguration";
|
||||
|
||||
private static final Set<String> SUPPORTED_OPTIONS = Collections
|
||||
.unmodifiableSet(Collections.singleton(ADDITIONAL_METADATA_LOCATIONS_OPTION));
|
||||
.unmodifiableSet(Collections.singleton(ADDITIONAL_METADATA_LOCATIONS_OPTION));
|
||||
|
||||
private MetadataStore metadataStore;
|
||||
|
||||
@@ -241,8 +241,9 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
this.metadataEnv.getTypeUtils().getQualifiedName(element.getEnclosingElement()),
|
||||
element.toString());
|
||||
if (this.metadataCollector.hasSimilarGroup(group)) {
|
||||
this.processingEnv.getMessager().printMessage(Kind.ERROR,
|
||||
"Duplicate @ConfigurationProperties definition for prefix '" + prefix + "'", element);
|
||||
this.processingEnv.getMessager()
|
||||
.printMessage(Kind.ERROR,
|
||||
"Duplicate @ConfigurationProperties definition for prefix '" + prefix + "'", element);
|
||||
}
|
||||
else {
|
||||
this.metadataCollector.add(group);
|
||||
@@ -260,7 +261,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
this.metadataCollector.add(descriptor.resolveItemMetadata(prefix, this.metadataEnv));
|
||||
if (descriptor.isNested(this.metadataEnv)) {
|
||||
TypeElement nestedTypeElement = (TypeElement) this.metadataEnv.getTypeUtils()
|
||||
.asElement(descriptor.getType());
|
||||
.asElement(descriptor.getType());
|
||||
String nestedPrefix = ConfigurationMetadata.nestedPrefix(prefix, descriptor.getName());
|
||||
processTypeElement(nestedPrefix, nestedTypeElement, source, seen);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@@ -275,7 +275,7 @@ class MetadataGenerationEnvironment {
|
||||
Map<String, Object> getAnnotationElementValues(AnnotationMirror annotation) {
|
||||
Map<String, Object> values = new LinkedHashMap<>();
|
||||
annotation.getElementValues()
|
||||
.forEach((name, value) -> values.put(name.getSimpleName().toString(), getAnnotationValue(value)));
|
||||
.forEach((name, value) -> values.put(name.getSimpleName().toString(), getAnnotationValue(value)));
|
||||
return values;
|
||||
}
|
||||
|
||||
@@ -306,8 +306,10 @@ class MetadataGenerationEnvironment {
|
||||
}
|
||||
|
||||
Set<TypeElement> getEndpointAnnotationElements() {
|
||||
return this.endpointAnnotations.stream().map(this.elements::getTypeElement).filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
return this.endpointAnnotations.stream()
|
||||
.map(this.elements::getTypeElement)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
AnnotationMirror getReadOperationAnnotation(Element element) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@@ -100,8 +100,8 @@ public class MetadataStore {
|
||||
|
||||
private InputStream getAdditionalMetadataStream() throws IOException {
|
||||
// Most build systems will have copied the file to the class output location
|
||||
FileObject fileObject = this.environment.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "",
|
||||
ADDITIONAL_METADATA_PATH);
|
||||
FileObject fileObject = this.environment.getFiler()
|
||||
.getResource(StandardLocation.CLASS_OUTPUT, "", ADDITIONAL_METADATA_PATH);
|
||||
InputStream inputStream = getMetadataStream(fileObject);
|
||||
if (inputStream != null) {
|
||||
return inputStream;
|
||||
@@ -129,7 +129,7 @@ public class MetadataStore {
|
||||
return standardLocation;
|
||||
}
|
||||
String locations = this.environment.getOptions()
|
||||
.get(ConfigurationMetadataAnnotationProcessor.ADDITIONAL_METADATA_LOCATIONS_OPTION);
|
||||
.get(ConfigurationMetadataAnnotationProcessor.ADDITIONAL_METADATA_LOCATIONS_OPTION);
|
||||
if (locations != null) {
|
||||
for (String location : locations.split(",")) {
|
||||
File candidate = new File(location, ADDITIONAL_METADATA_PATH);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@@ -234,7 +234,8 @@ class TypeUtils {
|
||||
if (type.getKind() == TypeKind.DECLARED) {
|
||||
DeclaredType declaredType = (DeclaredType) type;
|
||||
DeclaredType freshType = (DeclaredType) this.env.getElementUtils()
|
||||
.getTypeElement(this.types.asElement(type).toString()).asType();
|
||||
.getTypeElement(this.types.asElement(type).toString())
|
||||
.asType();
|
||||
List<? extends TypeMirror> arguments = declaredType.getTypeArguments();
|
||||
for (int i = 0; i < arguments.size(); i++) {
|
||||
TypeMirror specificType = arguments.get(i);
|
||||
@@ -267,9 +268,12 @@ class TypeUtils {
|
||||
}
|
||||
StringBuilder name = new StringBuilder();
|
||||
name.append(qualifiedName);
|
||||
name.append("<").append(
|
||||
type.getTypeArguments().stream().map((t) -> visit(t, descriptor)).collect(Collectors.joining(",")))
|
||||
.append(">");
|
||||
name.append("<")
|
||||
.append(type.getTypeArguments()
|
||||
.stream()
|
||||
.map((t) -> visit(t, descriptor))
|
||||
.collect(Collectors.joining(",")))
|
||||
.append(">");
|
||||
return name.toString();
|
||||
}
|
||||
|
||||
@@ -365,14 +369,19 @@ class TypeUtils {
|
||||
}
|
||||
|
||||
TypeMirror resolveGeneric(String parameterName) {
|
||||
return this.generics.entrySet().stream().filter((e) -> getParameterName(e.getKey()).equals(parameterName))
|
||||
.findFirst().map(Entry::getValue).orElse(null);
|
||||
return this.generics.entrySet()
|
||||
.stream()
|
||||
.filter((e) -> getParameterName(e.getKey()).equals(parameterName))
|
||||
.findFirst()
|
||||
.map(Entry::getValue)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private void registerIfNecessary(TypeMirror variable, TypeMirror resolution) {
|
||||
if (variable instanceof TypeVariable typeVariable) {
|
||||
if (this.generics.keySet().stream()
|
||||
.noneMatch((candidate) -> getParameterName(candidate).equals(getParameterName(typeVariable)))) {
|
||||
if (this.generics.keySet()
|
||||
.stream()
|
||||
.noneMatch((candidate) -> getParameterName(candidate).equals(getParameterName(typeVariable)))) {
|
||||
this.generics.put(typeVariable, resolution);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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,8 +38,11 @@ class JsonConverter {
|
||||
|
||||
JSONArray toJsonArray(ConfigurationMetadata metadata, ItemType itemType) throws Exception {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
List<ItemMetadata> items = metadata.getItems().stream().filter((item) -> item.isOfItemType(itemType))
|
||||
.sorted(ITEM_COMPARATOR).toList();
|
||||
List<ItemMetadata> items = metadata.getItems()
|
||||
.stream()
|
||||
.filter((item) -> item.isOfItemType(itemType))
|
||||
.sorted(ITEM_COMPARATOR)
|
||||
.toList();
|
||||
for (ItemMetadata item : items) {
|
||||
if (item.isOfItemType(itemType)) {
|
||||
jsonArray.put(toJsonObject(item));
|
||||
@@ -160,11 +163,11 @@ class JsonConverter {
|
||||
private static class ItemMetadataComparator implements Comparator<ItemMetadata> {
|
||||
|
||||
private static final Comparator<ItemMetadata> GROUP = Comparator.comparing(ItemMetadata::getName)
|
||||
.thenComparing(ItemMetadata::getSourceType, Comparator.nullsFirst(Comparator.naturalOrder()));
|
||||
.thenComparing(ItemMetadata::getSourceType, Comparator.nullsFirst(Comparator.naturalOrder()));
|
||||
|
||||
private static final Comparator<ItemMetadata> ITEM = Comparator.comparing(ItemMetadataComparator::isDeprecated)
|
||||
.thenComparing(ItemMetadata::getName)
|
||||
.thenComparing(ItemMetadata::getSourceType, Comparator.nullsFirst(Comparator.naturalOrder()));
|
||||
.thenComparing(ItemMetadata::getName)
|
||||
.thenComparing(ItemMetadata::getSourceType, Comparator.nullsFirst(Comparator.naturalOrder()));
|
||||
|
||||
@Override
|
||||
public int compare(ItemMetadata o1, ItemMetadata o2) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@@ -43,9 +43,10 @@ public abstract class AbstractMetadataGenerationTests {
|
||||
}
|
||||
|
||||
protected ConfigurationMetadata compile(String additionalMetadata, Class<?> type, Class<?>... types) {
|
||||
TestCompiler compiler = TestCompiler.forSystem().withSources(sourceFilesOf(type))
|
||||
.withSources(sourceFilesOf(types))
|
||||
.withResources(ResourceFile.of(ADDITIONAL_METADATA_FILE, additionalMetadata));
|
||||
TestCompiler compiler = TestCompiler.forSystem()
|
||||
.withSources(sourceFilesOf(type))
|
||||
.withSources(sourceFilesOf(types))
|
||||
.withResources(ResourceFile.of(ADDITIONAL_METADATA_FILE, additionalMetadata));
|
||||
return compile(compiler);
|
||||
}
|
||||
|
||||
|
||||
@@ -79,15 +79,15 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
||||
@Test
|
||||
void supportedAnnotations() {
|
||||
assertThat(new ConfigurationMetadataAnnotationProcessor().getSupportedAnnotationTypes())
|
||||
.containsExactlyInAnyOrder("org.springframework.boot.autoconfigure.AutoConfiguration",
|
||||
"org.springframework.boot.context.properties.ConfigurationProperties",
|
||||
"org.springframework.context.annotation.Configuration",
|
||||
"org.springframework.boot.actuate.endpoint.annotation.Endpoint",
|
||||
"org.springframework.boot.actuate.endpoint.jmx.annotation.JmxEndpoint",
|
||||
"org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpoint",
|
||||
"org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint",
|
||||
"org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpoint",
|
||||
"org.springframework.boot.actuate.endpoint.web.annotation.WebEndpoint");
|
||||
.containsExactlyInAnyOrder("org.springframework.boot.autoconfigure.AutoConfiguration",
|
||||
"org.springframework.boot.context.properties.ConfigurationProperties",
|
||||
"org.springframework.context.annotation.Configuration",
|
||||
"org.springframework.boot.actuate.endpoint.annotation.Endpoint",
|
||||
"org.springframework.boot.actuate.endpoint.jmx.annotation.JmxEndpoint",
|
||||
"org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpoint",
|
||||
"org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint",
|
||||
"org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpoint",
|
||||
"org.springframework.boot.actuate.endpoint.web.annotation.WebEndpoint");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,10 +101,15 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("simple").fromSource(SimpleProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.the-name", String.class)
|
||||
.fromSource(SimpleProperties.class).withDescription("The name of this simple properties.")
|
||||
.withDefaultValue("boot").withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.flag", Boolean.class).withDefaultValue(false)
|
||||
.fromSource(SimpleProperties.class).withDescription("A simple flag.").withDeprecation(null, null));
|
||||
.fromSource(SimpleProperties.class)
|
||||
.withDescription("The name of this simple properties.")
|
||||
.withDefaultValue("boot")
|
||||
.withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.flag", Boolean.class)
|
||||
.withDefaultValue(false)
|
||||
.fromSource(SimpleProperties.class)
|
||||
.withDescription("A simple flag.")
|
||||
.withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.comparator"));
|
||||
assertThat(metadata).doesNotHave(Metadata.withProperty("simple.counter"));
|
||||
assertThat(metadata).doesNotHave(Metadata.withProperty("simple.size"));
|
||||
@@ -115,7 +120,7 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
||||
ConfigurationMetadata metadata = compile(SimplePrefixValueProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("simple").fromSource(SimplePrefixValueProperties.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.name", String.class).fromSource(SimplePrefixValueProperties.class));
|
||||
.has(Metadata.withProperty("simple.name", String.class).fromSource(SimplePrefixValueProperties.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -125,21 +130,21 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-string", String.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-byte", Byte.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-primitive-byte", Byte.class).withDefaultValue(0));
|
||||
.has(Metadata.withProperty("simple.type.my-primitive-byte", Byte.class).withDefaultValue(0));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-char", Character.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-primitive-char", Character.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-boolean", Boolean.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-primitive-boolean", Boolean.class).withDefaultValue(false));
|
||||
.has(Metadata.withProperty("simple.type.my-primitive-boolean", Boolean.class).withDefaultValue(false));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-short", Short.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-primitive-short", Short.class).withDefaultValue(0));
|
||||
.has(Metadata.withProperty("simple.type.my-primitive-short", Short.class).withDefaultValue(0));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-integer", Integer.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-primitive-integer", Integer.class).withDefaultValue(0));
|
||||
.has(Metadata.withProperty("simple.type.my-primitive-integer", Integer.class).withDefaultValue(0));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-long", Long.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-primitive-long", Long.class).withDefaultValue(0));
|
||||
.has(Metadata.withProperty("simple.type.my-primitive-long", Long.class).withDefaultValue(0));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-double", Double.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-primitive-double", Double.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-float", Float.class));
|
||||
@@ -152,12 +157,15 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
||||
ConfigurationMetadata metadata = compile(HierarchicalProperties.class, HierarchicalPropertiesParent.class,
|
||||
HierarchicalPropertiesGrandparent.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("hierarchical").fromSource(HierarchicalProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("hierarchical.first", String.class).withDefaultValue("one")
|
||||
.fromSource(HierarchicalProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("hierarchical.second", String.class).withDefaultValue("two")
|
||||
.fromSource(HierarchicalProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("hierarchical.third", String.class).withDefaultValue("three")
|
||||
.fromSource(HierarchicalProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("hierarchical.first", String.class)
|
||||
.withDefaultValue("one")
|
||||
.fromSource(HierarchicalProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("hierarchical.second", String.class)
|
||||
.withDefaultValue("two")
|
||||
.fromSource(HierarchicalProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("hierarchical.third", String.class)
|
||||
.withDefaultValue("three")
|
||||
.fromSource(HierarchicalProperties.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -165,10 +173,12 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
||||
ConfigurationMetadata metadata = compile(DescriptionProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("description").fromSource(DescriptionProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("description.simple", String.class)
|
||||
.fromSource(DescriptionProperties.class).withDescription("A simple description."));
|
||||
.fromSource(DescriptionProperties.class)
|
||||
.withDescription("A simple description."));
|
||||
assertThat(metadata).has(Metadata.withProperty("description.multi-line", String.class)
|
||||
.fromSource(DescriptionProperties.class).withDescription(
|
||||
"This is a lengthy description that spans across multiple lines to showcase that the line separators are cleaned automatically."));
|
||||
.fromSource(DescriptionProperties.class)
|
||||
.withDescription(
|
||||
"This is a lengthy description that spans across multiple lines to showcase that the line separators are cleaned automatically."));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -177,10 +187,11 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
||||
Class<?> type = org.springframework.boot.configurationsample.simple.DeprecatedProperties.class;
|
||||
ConfigurationMetadata metadata = compile(type);
|
||||
assertThat(metadata).has(Metadata.withGroup("deprecated").fromSource(type));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("deprecated.name", String.class).fromSource(type).withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("deprecated.description", String.class).fromSource(type)
|
||||
.withDeprecation(null, null));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("deprecated.name", String.class).fromSource(type).withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("deprecated.description", String.class)
|
||||
.fromSource(type)
|
||||
.withDeprecation(null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -189,8 +200,9 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
||||
ConfigurationMetadata metadata = compile(type);
|
||||
assertThat(metadata).has(Metadata.withGroup("singledeprecated").fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("singledeprecated.new-name", String.class).fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("singledeprecated.name", String.class).fromSource(type)
|
||||
.withDeprecation("renamed", "singledeprecated.new-name"));
|
||||
assertThat(metadata).has(Metadata.withProperty("singledeprecated.name", String.class)
|
||||
.fromSource(type)
|
||||
.withDeprecation("renamed", "singledeprecated.new-name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -198,8 +210,9 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
||||
Class<?> type = DeprecatedFieldSingleProperty.class;
|
||||
ConfigurationMetadata metadata = compile(type);
|
||||
assertThat(metadata).has(Metadata.withGroup("singlefielddeprecated").fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("singlefielddeprecated.name", String.class).fromSource(type)
|
||||
.withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("singlefielddeprecated.name", String.class)
|
||||
.fromSource(type)
|
||||
.withDeprecation(null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -207,10 +220,12 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
||||
Class<?> type = DeprecatedUnrelatedMethodPojo.class;
|
||||
ConfigurationMetadata metadata = compile(type);
|
||||
assertThat(metadata).has(Metadata.withGroup("not.deprecated").fromSource(type));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("not.deprecated.counter", Integer.class).withNoDeprecation().fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("not.deprecated.flag", Boolean.class).withDefaultValue(false)
|
||||
.withNoDeprecation().fromSource(type));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("not.deprecated.counter", Integer.class).withNoDeprecation().fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("not.deprecated.flag", Boolean.class)
|
||||
.withDefaultValue(false)
|
||||
.withNoDeprecation()
|
||||
.fromSource(type));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -218,8 +233,10 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
||||
Class<?> type = DeprecatedLessPreciseTypePojo.class;
|
||||
ConfigurationMetadata metadata = compile(type);
|
||||
assertThat(metadata).has(Metadata.withGroup("not.deprecated").fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("not.deprecated.flag", Boolean.class).withDefaultValue(false)
|
||||
.withNoDeprecation().fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("not.deprecated.flag", Boolean.class)
|
||||
.withDefaultValue(false)
|
||||
.withNoDeprecation()
|
||||
.fromSource(type));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -227,8 +244,9 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
||||
Class<?> type = DeprecatedRecord.class;
|
||||
ConfigurationMetadata metadata = compile(type);
|
||||
assertThat(metadata).has(Metadata.withGroup("deprecated-record").fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("deprecated-record.alpha", String.class).fromSource(type)
|
||||
.withDeprecation("some-reason", null));
|
||||
assertThat(metadata).has(Metadata.withProperty("deprecated-record.alpha", String.class)
|
||||
.fromSource(type)
|
||||
.withDeprecation("some-reason", null));
|
||||
assertThat(metadata).has(Metadata.withProperty("deprecated-record.bravo", String.class).fromSource(type));
|
||||
}
|
||||
|
||||
@@ -238,7 +256,7 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
||||
ConfigurationMetadata metadata = compile(type);
|
||||
assertThat(metadata).has(Metadata.withGroup("boxing").fromSource(type));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("boxing.flag", Boolean.class).withDefaultValue(false).fromSource(type));
|
||||
.has(Metadata.withProperty("boxing.flag", Boolean.class).withDefaultValue(false).fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("boxing.another-flag", Boolean.class).fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("boxing.counter", Integer.class).fromSource(type));
|
||||
}
|
||||
@@ -268,8 +286,8 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
||||
assertThat(metadata).has(Metadata.withProperty("array.simple", "java.lang.String[]"));
|
||||
assertThat(metadata).has(Metadata.withProperty("array.inner",
|
||||
"org.springframework.boot.configurationsample.simple.SimpleArrayProperties$Holder[]"));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("array.name-to-integer", "java.util.Map<java.lang.String,java.lang.Integer>[]"));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("array.name-to-integer", "java.util.Map<java.lang.String,java.lang.Integer>[]"));
|
||||
assertThat(metadata.getItems()).hasSize(5);
|
||||
}
|
||||
|
||||
@@ -278,7 +296,7 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
||||
ConfigurationMetadata metadata = compile(AnnotatedGetter.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("specific").fromSource(AnnotatedGetter.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("specific.name", String.class).fromSource(AnnotatedGetter.class));
|
||||
.has(Metadata.withProperty("specific.name", String.class).fromSource(AnnotatedGetter.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -286,9 +304,10 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
||||
ConfigurationMetadata metadata = compile(StaticAccessor.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("specific").fromSource(StaticAccessor.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("specific.counter", Integer.class)
|
||||
.fromSource(StaticAccessor.class).withDefaultValue(42));
|
||||
.fromSource(StaticAccessor.class)
|
||||
.withDefaultValue(42));
|
||||
assertThat(metadata)
|
||||
.doesNotHave(Metadata.withProperty("specific.name", String.class).fromSource(StaticAccessor.class));
|
||||
.doesNotHave(Metadata.withProperty("specific.name", String.class).fromSource(StaticAccessor.class));
|
||||
assertThat(metadata.getItems()).hasSize(2);
|
||||
}
|
||||
|
||||
@@ -302,16 +321,17 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
||||
void innerClassProperties() {
|
||||
ConfigurationMetadata metadata = compile(InnerClassProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("config").fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.first").ofType(InnerClassProperties.Foo.class)
|
||||
.fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.first")
|
||||
.ofType(InnerClassProperties.Foo.class)
|
||||
.fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.first.name"));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.first.bar.name"));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.the-second", InnerClassProperties.Foo.class)
|
||||
.fromSource(InnerClassProperties.class));
|
||||
.fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.the-second.name"));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.the-second.bar.name"));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withGroup("config.third").ofType(SimplePojo.class).fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("config.third").ofType(SimplePojo.class).fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.third.value"));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.fourth"));
|
||||
assertThat(metadata).isNotEqualTo(Metadata.withGroup("config.fourth"));
|
||||
@@ -322,9 +342,9 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
||||
ConfigurationMetadata metadata = compile(InnerClassHierarchicalProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("config.foo").ofType(InnerClassHierarchicalProperties.Foo.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("config.foo.bar").ofType(InnerClassHierarchicalProperties.Bar.class));
|
||||
.has(Metadata.withGroup("config.foo.bar").ofType(InnerClassHierarchicalProperties.Bar.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("config.foo.bar.baz").ofType(InnerClassHierarchicalProperties.Foo.Baz.class));
|
||||
.has(Metadata.withGroup("config.foo.bar.baz").ofType(InnerClassHierarchicalProperties.Foo.Baz.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.foo.bar.baz.blah"));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.foo.bar.bling"));
|
||||
}
|
||||
@@ -340,12 +360,14 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
||||
@Test
|
||||
void nestedClassChildProperties() {
|
||||
ConfigurationMetadata metadata = compile(ClassWithNestedProperties.class);
|
||||
assertThat(metadata).has(
|
||||
Metadata.withGroup("nestedChildProps").fromSource(ClassWithNestedProperties.NestedChildClass.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("nestedChildProps").fromSource(ClassWithNestedProperties.NestedChildClass.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("nestedChildProps.child-class-property", Integer.class)
|
||||
.fromSource(ClassWithNestedProperties.NestedChildClass.class).withDefaultValue(20));
|
||||
.fromSource(ClassWithNestedProperties.NestedChildClass.class)
|
||||
.withDefaultValue(20));
|
||||
assertThat(metadata).has(Metadata.withProperty("nestedChildProps.parent-class-property", Integer.class)
|
||||
.fromSource(ClassWithNestedProperties.NestedChildClass.class).withDefaultValue(10));
|
||||
.fromSource(ClassWithNestedProperties.NestedChildClass.class)
|
||||
.withDefaultValue(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -385,37 +407,40 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
||||
@Test
|
||||
void invalidDoubleRegistration() {
|
||||
assertThatExceptionOfType(CompilationException.class)
|
||||
.isThrownBy(() -> compile(InvalidDoubleRegistrationProperties.class))
|
||||
.withMessageContaining("Unable to compile source");
|
||||
.isThrownBy(() -> compile(InvalidDoubleRegistrationProperties.class))
|
||||
.withMessageContaining("Unable to compile source");
|
||||
}
|
||||
|
||||
@Test
|
||||
void constructorParameterPropertyWithInvalidDefaultValueOnNumber() {
|
||||
assertThatExceptionOfType(CompilationException.class)
|
||||
.isThrownBy(() -> compile(InvalidDefaultValueNumberProperties.class))
|
||||
.withMessageContaining("Unable to compile source");
|
||||
.isThrownBy(() -> compile(InvalidDefaultValueNumberProperties.class))
|
||||
.withMessageContaining("Unable to compile source");
|
||||
}
|
||||
|
||||
@Test
|
||||
void constructorParameterPropertyWithInvalidDefaultValueOnFloatingPoint() {
|
||||
assertThatExceptionOfType(CompilationException.class)
|
||||
.isThrownBy(() -> compile(InvalidDefaultValueFloatingPointProperties.class))
|
||||
.withMessageContaining("Unable to compile source");
|
||||
.isThrownBy(() -> compile(InvalidDefaultValueFloatingPointProperties.class))
|
||||
.withMessageContaining("Unable to compile source");
|
||||
}
|
||||
|
||||
@Test
|
||||
void constructorParameterPropertyWithInvalidDefaultValueOnCharacter() {
|
||||
assertThatExceptionOfType(CompilationException.class)
|
||||
.isThrownBy(() -> compile(InvalidDefaultValueCharacterProperties.class))
|
||||
.withMessageContaining("Unable to compile source");
|
||||
.isThrownBy(() -> compile(InvalidDefaultValueCharacterProperties.class))
|
||||
.withMessageContaining("Unable to compile source");
|
||||
}
|
||||
|
||||
@Test
|
||||
void constructorParameterPropertyWithEmptyDefaultValueOnProperty() {
|
||||
ConfigurationMetadata metadata = compile(EmptyDefaultValueProperties.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("test.name"));
|
||||
ItemMetadata nameMetadata = metadata.getItems().stream().filter((item) -> item.getName().equals("test.name"))
|
||||
.findFirst().get();
|
||||
ItemMetadata nameMetadata = metadata.getItems()
|
||||
.stream()
|
||||
.filter((item) -> item.getName().equals("test.name"))
|
||||
.findFirst()
|
||||
.get();
|
||||
assertThat(nameMetadata.getDefaultValue()).isNull();
|
||||
}
|
||||
|
||||
@@ -447,9 +472,9 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
||||
""";
|
||||
ConfigurationMetadata metadata = compile(source);
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("record.defaults.some-string", String.class).withDefaultValue("An1s9n"));
|
||||
.has(Metadata.withProperty("record.defaults.some-string", String.class).withDefaultValue("An1s9n"));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("record.defaults.some-integer", Integer.class).withDefaultValue(594));
|
||||
.has(Metadata.withProperty("record.defaults.some-integer", Integer.class).withDefaultValue(594));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@@ -99,8 +99,12 @@ class ConstructorParameterPropertyDescriptorTests extends PropertyDescriptorTest
|
||||
process(ImmutableSimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(ImmutableSimpleProperties.class);
|
||||
ConstructorParameterPropertyDescriptor property = createPropertyDescriptor(ownerElement, "counter");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().hasName("test.counter").hasType(Long.class)
|
||||
.hasSourceType(ImmutableSimpleProperties.class).hasNoDescription().isNotDeprecated();
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.hasName("test.counter")
|
||||
.hasType(Long.class)
|
||||
.hasSourceType(ImmutableSimpleProperties.class)
|
||||
.hasNoDescription()
|
||||
.isNotDeprecated();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -109,10 +113,13 @@ class ConstructorParameterPropertyDescriptorTests extends PropertyDescriptorTest
|
||||
process(ImmutableInnerClassProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(ImmutableInnerClassProperties.class);
|
||||
ConstructorParameterPropertyDescriptor property = createPropertyDescriptor(ownerElement, "first");
|
||||
assertItemMetadata(metadataEnv, property).isGroup().hasName("test.first")
|
||||
.hasType("org.springframework.boot.configurationsample.immutable.ImmutableInnerClassProperties$Foo")
|
||||
.hasSourceType(ImmutableInnerClassProperties.class).hasSourceMethod("getFirst()").hasNoDescription()
|
||||
.isNotDeprecated();
|
||||
assertItemMetadata(metadataEnv, property).isGroup()
|
||||
.hasName("test.first")
|
||||
.hasType("org.springframework.boot.configurationsample.immutable.ImmutableInnerClassProperties$Foo")
|
||||
.hasSourceType(ImmutableInnerClassProperties.class)
|
||||
.hasSourceMethod("getFirst()")
|
||||
.hasNoDescription()
|
||||
.isNotDeprecated();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -135,7 +142,7 @@ class ConstructorParameterPropertyDescriptorTests extends PropertyDescriptorTest
|
||||
TypeElement ownerElement = roundEnv.getRootElement(ImmutableSimpleProperties.class);
|
||||
ConstructorParameterPropertyDescriptor property = createPropertyDescriptor(ownerElement, "theName");
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.hasDescription("The name of this simple properties.");
|
||||
.hasDescription("The name of this simple properties.");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -156,7 +163,7 @@ class ConstructorParameterPropertyDescriptorTests extends PropertyDescriptorTest
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "octet")).hasDefaultValue((byte) 0);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "letter")).hasDefaultValue(null);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "number"))
|
||||
.hasDefaultValue((short) 0);
|
||||
.hasDefaultValue((short) 0);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "counter")).hasDefaultValue(0);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "value")).hasDefaultValue(0L);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "percentage")).hasDefaultValue(0F);
|
||||
@@ -170,10 +177,10 @@ class ConstructorParameterPropertyDescriptorTests extends PropertyDescriptorTest
|
||||
TypeElement ownerElement = roundEnv.getRootElement(ImmutablePrimitiveWithDefaultsProperties.class);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "flag")).hasDefaultValue(true);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "octet"))
|
||||
.hasDefaultValue((byte) 120);
|
||||
.hasDefaultValue((byte) 120);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "letter")).hasDefaultValue("a");
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "number"))
|
||||
.hasDefaultValue((short) 1000);
|
||||
.hasDefaultValue((short) 1000);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "counter")).hasDefaultValue(42);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "value")).hasDefaultValue(2000L);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "percentage")).hasDefaultValue(0.5F);
|
||||
@@ -187,10 +194,10 @@ class ConstructorParameterPropertyDescriptorTests extends PropertyDescriptorTest
|
||||
TypeElement ownerElement = roundEnv.getRootElement(ImmutablePrimitiveWrapperWithDefaultsProperties.class);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "flag")).hasDefaultValue(true);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "octet"))
|
||||
.hasDefaultValue((byte) 120);
|
||||
.hasDefaultValue((byte) 120);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "letter")).hasDefaultValue("a");
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "number"))
|
||||
.hasDefaultValue((short) 1000);
|
||||
.hasDefaultValue((short) 1000);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "counter")).hasDefaultValue(42);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "value")).hasDefaultValue(2000L);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "percentage")).hasDefaultValue(0.5F);
|
||||
@@ -204,9 +211,9 @@ class ConstructorParameterPropertyDescriptorTests extends PropertyDescriptorTest
|
||||
TypeElement ownerElement = roundEnv.getRootElement(ImmutableCollectionProperties.class);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "names")).hasDefaultValue(null);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "flags"))
|
||||
.hasDefaultValue(Arrays.asList(true, false));
|
||||
.hasDefaultValue(Arrays.asList(true, false));
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "durations"))
|
||||
.hasDefaultValue(Arrays.asList("10s", "1m", "1h"));
|
||||
.hasDefaultValue(Arrays.asList("10s", "1m", "1h"));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -220,13 +227,19 @@ class ConstructorParameterPropertyDescriptorTests extends PropertyDescriptorTest
|
||||
}
|
||||
|
||||
private VariableElement getConstructorParameter(TypeElement ownerElement, String name) {
|
||||
List<ExecutableElement> constructors = ElementFilter.constructorsIn(ownerElement.getEnclosedElements()).stream()
|
||||
.filter((constructor) -> !constructor.getParameters().isEmpty()).toList();
|
||||
List<ExecutableElement> constructors = ElementFilter.constructorsIn(ownerElement.getEnclosedElements())
|
||||
.stream()
|
||||
.filter((constructor) -> !constructor.getParameters().isEmpty())
|
||||
.toList();
|
||||
if (constructors.size() != 1) {
|
||||
throw new IllegalStateException("No candidate constructor for " + ownerElement);
|
||||
}
|
||||
return constructors.get(0).getParameters().stream()
|
||||
.filter((parameter) -> parameter.getSimpleName().toString().equals(name)).findFirst().orElse(null);
|
||||
return constructors.get(0)
|
||||
.getParameters()
|
||||
.stream()
|
||||
.filter((parameter) -> parameter.getSimpleName().toString().equals(name))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2023 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,11 +38,14 @@ class DeducedImmutablePropertiesMetadataGenerationTests extends AbstractMetadata
|
||||
ConfigurationMetadata metadata = compile(DeducedImmutableClassProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("test").fromSource(DeducedImmutableClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("test.nested", DeducedImmutableClassProperties.Nested.class)
|
||||
.fromSource(DeducedImmutableClassProperties.class));
|
||||
.fromSource(DeducedImmutableClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("test.nested.name", String.class)
|
||||
.fromSource(DeducedImmutableClassProperties.Nested.class));
|
||||
ItemMetadata nestedMetadata = metadata.getItems().stream()
|
||||
.filter((item) -> item.getName().equals("test.nested")).findFirst().get();
|
||||
.fromSource(DeducedImmutableClassProperties.Nested.class));
|
||||
ItemMetadata nestedMetadata = metadata.getItems()
|
||||
.stream()
|
||||
.filter((item) -> item.getName().equals("test.nested"))
|
||||
.findFirst()
|
||||
.get();
|
||||
assertThat(nestedMetadata.getDefaultValue()).isNull();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@@ -69,9 +69,10 @@ class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
void customPropertiesEndpoint() {
|
||||
ConfigurationMetadata metadata = compile(CustomPropertiesEndpoint.class);
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("management.endpoint.customprops").fromSource(CustomPropertiesEndpoint.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("management.endpoint.customprops.name").ofType(String.class)
|
||||
.withDefaultValue("test"));
|
||||
.has(Metadata.withGroup("management.endpoint.customprops").fromSource(CustomPropertiesEndpoint.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("management.endpoint.customprops.name")
|
||||
.ofType(String.class)
|
||||
.withDefaultValue("test"));
|
||||
assertThat(metadata).has(enabledFlag("customprops", true));
|
||||
assertThat(metadata).has(cacheTtl("customprops"));
|
||||
assertThat(metadata.getItems()).hasSize(4);
|
||||
@@ -90,7 +91,7 @@ class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
void camelCaseEndpoint() {
|
||||
ConfigurationMetadata metadata = compile(CamelCaseEndpoint.class);
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("management.endpoint.pascal-case").fromSource(CamelCaseEndpoint.class));
|
||||
.has(Metadata.withGroup("management.endpoint.pascal-case").fromSource(CamelCaseEndpoint.class));
|
||||
assertThat(metadata).has(enabledFlag("PascalCase", "pascal-case", true));
|
||||
assertThat(metadata.getItems()).hasSize(2);
|
||||
}
|
||||
@@ -100,7 +101,7 @@ class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
TestProject project = new TestProject(IncrementalEndpoint.class);
|
||||
ConfigurationMetadata metadata = project.compile();
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("management.endpoint.incremental").fromSource(IncrementalEndpoint.class));
|
||||
.has(Metadata.withGroup("management.endpoint.incremental").fromSource(IncrementalEndpoint.class));
|
||||
assertThat(metadata).has(enabledFlag("incremental", true));
|
||||
assertThat(metadata).has(cacheTtl("incremental"));
|
||||
assertThat(metadata.getItems()).hasSize(3);
|
||||
@@ -108,7 +109,7 @@ class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
"id = \"incremental\", enableByDefault = false");
|
||||
metadata = project.compile();
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("management.endpoint.incremental").fromSource(IncrementalEndpoint.class));
|
||||
.has(Metadata.withGroup("management.endpoint.incremental").fromSource(IncrementalEndpoint.class));
|
||||
assertThat(metadata).has(enabledFlag("incremental", false));
|
||||
assertThat(metadata).has(cacheTtl("incremental"));
|
||||
assertThat(metadata.getItems()).hasSize(3);
|
||||
@@ -119,14 +120,14 @@ class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
TestProject project = new TestProject(IncrementalEndpoint.class);
|
||||
ConfigurationMetadata metadata = project.compile();
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("management.endpoint.incremental").fromSource(IncrementalEndpoint.class));
|
||||
.has(Metadata.withGroup("management.endpoint.incremental").fromSource(IncrementalEndpoint.class));
|
||||
assertThat(metadata).has(enabledFlag("incremental", true));
|
||||
assertThat(metadata).has(cacheTtl("incremental"));
|
||||
assertThat(metadata.getItems()).hasSize(3);
|
||||
project.replaceText(IncrementalEndpoint.class, "@Nullable String param", "String param");
|
||||
metadata = project.compile();
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("management.endpoint.incremental").fromSource(IncrementalEndpoint.class));
|
||||
.has(Metadata.withGroup("management.endpoint.incremental").fromSource(IncrementalEndpoint.class));
|
||||
assertThat(metadata).has(enabledFlag("incremental", true));
|
||||
assertThat(metadata.getItems()).hasSize(2);
|
||||
}
|
||||
@@ -149,8 +150,8 @@ class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
|
||||
private Metadata.MetadataItemCondition enabledFlag(String endpointId, String endpointSuffix, Boolean defaultValue) {
|
||||
return Metadata.withEnabledFlag("management.endpoint." + endpointSuffix + ".enabled")
|
||||
.withDefaultValue(defaultValue)
|
||||
.withDescription(String.format("Whether to enable the %s endpoint.", endpointId));
|
||||
.withDefaultValue(defaultValue)
|
||||
.withDescription(String.format("Whether to enable the %s endpoint.", endpointId));
|
||||
}
|
||||
|
||||
private Metadata.MetadataItemCondition enabledFlag(String endpointId, Boolean defaultValue) {
|
||||
@@ -158,8 +159,10 @@ class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
}
|
||||
|
||||
private Metadata.MetadataItemCondition cacheTtl(String endpointId) {
|
||||
return Metadata.withProperty("management.endpoint." + endpointId + ".cache.time-to-live").ofType(Duration.class)
|
||||
.withDefaultValue("0ms").withDescription("Maximum time that a response can be cached.");
|
||||
return Metadata.withProperty("management.endpoint." + endpointId + ".cache.time-to-live")
|
||||
.ofType(Duration.class)
|
||||
.withDefaultValue("0ms")
|
||||
.withDescription("Maximum time that a response can be cached.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@@ -43,10 +43,14 @@ class GenericsMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
ConfigurationMetadata metadata = compile(AbstractGenericProperties.class, SimpleGenericProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("generic").fromSource(SimpleGenericProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("generic.name", String.class)
|
||||
.fromSource(SimpleGenericProperties.class).withDescription("Generic name.").withDefaultValue(null));
|
||||
assertThat(metadata).has(Metadata
|
||||
.withProperty("generic.mappings", "java.util.Map<java.lang.Integer,java.time.Duration>")
|
||||
.fromSource(SimpleGenericProperties.class).withDescription("Generic mappings.").withDefaultValue(null));
|
||||
.fromSource(SimpleGenericProperties.class)
|
||||
.withDescription("Generic name.")
|
||||
.withDefaultValue(null));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("generic.mappings", "java.util.Map<java.lang.Integer,java.time.Duration>")
|
||||
.fromSource(SimpleGenericProperties.class)
|
||||
.withDescription("Generic mappings.")
|
||||
.withDefaultValue(null));
|
||||
assertThat(metadata.getItems()).hasSize(3);
|
||||
}
|
||||
|
||||
@@ -54,11 +58,12 @@ class GenericsMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
void complexGenericProperties() {
|
||||
ConfigurationMetadata metadata = compile(ComplexGenericProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("generic").fromSource(ComplexGenericProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("generic.test").ofType(UpperBoundGenericPojo.class)
|
||||
.fromSource(ComplexGenericProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("generic.test")
|
||||
.ofType(UpperBoundGenericPojo.class)
|
||||
.fromSource(ComplexGenericProperties.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("generic.test.mappings", "java.util.Map<java.lang.Enum<T>,java.lang.String>")
|
||||
.fromSource(UpperBoundGenericPojo.class));
|
||||
.has(Metadata.withProperty("generic.test.mappings", "java.util.Map<java.lang.Enum<T>,java.lang.String>")
|
||||
.fromSource(UpperBoundGenericPojo.class));
|
||||
assertThat(metadata.getItems()).hasSize(3);
|
||||
}
|
||||
|
||||
@@ -67,11 +72,14 @@ class GenericsMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
ConfigurationMetadata metadata = compile(AbstractGenericProperties.class, UnresolvedGenericProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("generic").fromSource(UnresolvedGenericProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("generic.name", String.class)
|
||||
.fromSource(UnresolvedGenericProperties.class).withDescription("Generic name.").withDefaultValue(null));
|
||||
.fromSource(UnresolvedGenericProperties.class)
|
||||
.withDescription("Generic name.")
|
||||
.withDefaultValue(null));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("generic.mappings", "java.util.Map<java.lang.Number,java.lang.Object>")
|
||||
.fromSource(UnresolvedGenericProperties.class).withDescription("Generic mappings.")
|
||||
.withDefaultValue(null));
|
||||
.has(Metadata.withProperty("generic.mappings", "java.util.Map<java.lang.Number,java.lang.Object>")
|
||||
.fromSource(UnresolvedGenericProperties.class)
|
||||
.withDescription("Generic mappings.")
|
||||
.withDefaultValue(null));
|
||||
assertThat(metadata.getItems()).hasSize(3);
|
||||
}
|
||||
|
||||
@@ -79,24 +87,27 @@ class GenericsMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
void genericTypes() {
|
||||
ConfigurationMetadata metadata = compile(GenericConfig.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("generic")
|
||||
.ofType("org.springframework.boot.configurationsample.generic.GenericConfig"));
|
||||
.ofType("org.springframework.boot.configurationsample.generic.GenericConfig"));
|
||||
assertThat(metadata).has(Metadata.withGroup("generic.foo")
|
||||
.ofType("org.springframework.boot.configurationsample.generic.GenericConfig$Foo"));
|
||||
.ofType("org.springframework.boot.configurationsample.generic.GenericConfig$Foo"));
|
||||
assertThat(metadata).has(Metadata.withGroup("generic.foo.bar")
|
||||
.ofType("org.springframework.boot.configurationsample.generic.GenericConfig$Bar"));
|
||||
.ofType("org.springframework.boot.configurationsample.generic.GenericConfig$Bar"));
|
||||
assertThat(metadata).has(Metadata.withGroup("generic.foo.bar.biz")
|
||||
.ofType("org.springframework.boot.configurationsample.generic.GenericConfig$Bar$Biz"));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("generic.foo.name").ofType(String.class).fromSource(GenericConfig.Foo.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("generic.foo.string-to-bar").ofType(
|
||||
"java.util.Map<java.lang.String,org.springframework.boot.configurationsample.generic.GenericConfig$Bar<java.lang.Integer>>")
|
||||
.fromSource(GenericConfig.Foo.class));
|
||||
.ofType("org.springframework.boot.configurationsample.generic.GenericConfig$Bar$Biz"));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("generic.foo.name").ofType(String.class).fromSource(GenericConfig.Foo.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("generic.foo.string-to-bar")
|
||||
.ofType("java.util.Map<java.lang.String,org.springframework.boot.configurationsample.generic.GenericConfig$Bar<java.lang.Integer>>")
|
||||
.fromSource(GenericConfig.Foo.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("generic.foo.string-to-integer")
|
||||
.ofType("java.util.Map<java.lang.String,java.lang.Integer>").fromSource(GenericConfig.Foo.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("generic.foo.bar.name").ofType("java.lang.String")
|
||||
.fromSource(GenericConfig.Bar.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("generic.foo.bar.biz.name").ofType("java.lang.String")
|
||||
.fromSource(GenericConfig.Bar.Biz.class));
|
||||
.ofType("java.util.Map<java.lang.String,java.lang.Integer>")
|
||||
.fromSource(GenericConfig.Foo.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("generic.foo.bar.name")
|
||||
.ofType("java.lang.String")
|
||||
.fromSource(GenericConfig.Bar.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("generic.foo.bar.biz.name")
|
||||
.ofType("java.lang.String")
|
||||
.fromSource(GenericConfig.Bar.Biz.class));
|
||||
assertThat(metadata.getItems()).hasSize(9);
|
||||
}
|
||||
|
||||
@@ -105,9 +116,11 @@ class GenericsMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
ConfigurationMetadata metadata = compile(WildcardConfig.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("wildcard").ofType(WildcardConfig.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("wildcard.string-to-number")
|
||||
.ofType("java.util.Map<java.lang.String,? extends java.lang.Number>").fromSource(WildcardConfig.class));
|
||||
.ofType("java.util.Map<java.lang.String,? extends java.lang.Number>")
|
||||
.fromSource(WildcardConfig.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("wildcard.integers")
|
||||
.ofType("java.util.List<? super java.lang.Integer>").fromSource(WildcardConfig.class));
|
||||
.ofType("java.util.List<? super java.lang.Integer>")
|
||||
.fromSource(WildcardConfig.class));
|
||||
assertThat(metadata.getItems()).hasSize(3);
|
||||
}
|
||||
|
||||
@@ -115,8 +128,8 @@ class GenericsMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
void builderPatternWithGenericReturnType() {
|
||||
ConfigurationMetadata metadata = compile(ConcreteBuilderProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("builder").fromSource(ConcreteBuilderProperties.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("builder.number", Integer.class).fromSource(ConcreteBuilderProperties.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("builder.number", Integer.class).fromSource(ConcreteBuilderProperties.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("builder.description", String.class).fromSource(ConcreteBuilderProperties.class));
|
||||
assertThat(metadata.getItems()).hasSize(3);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@@ -35,7 +35,7 @@ class ImmutableNameAnnotationPropertiesTests extends AbstractMetadataGenerationT
|
||||
void immutableNameAnnotationProperties() {
|
||||
ConfigurationMetadata metadata = compile(ImmutableNameAnnotationProperties.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("named.import", String.class)
|
||||
.fromSource(ImmutableNameAnnotationProperties.class));
|
||||
.fromSource(ImmutableNameAnnotationProperties.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@@ -35,12 +35,15 @@ class ImmutablePropertiesMetadataGenerationTests extends AbstractMetadataGenerat
|
||||
void immutableSimpleProperties() {
|
||||
ConfigurationMetadata metadata = compile(ImmutableSimpleProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("immutable").fromSource(ImmutableSimpleProperties.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("immutable.the-name", String.class).fromSource(ImmutableSimpleProperties.class)
|
||||
.withDescription("The name of this simple properties.").withDefaultValue("boot"));
|
||||
assertThat(metadata).has(Metadata.withProperty("immutable.flag", Boolean.class).withDefaultValue(false)
|
||||
.fromSource(ImmutableSimpleProperties.class).withDescription("A simple flag.")
|
||||
.withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("immutable.the-name", String.class)
|
||||
.fromSource(ImmutableSimpleProperties.class)
|
||||
.withDescription("The name of this simple properties.")
|
||||
.withDefaultValue("boot"));
|
||||
assertThat(metadata).has(Metadata.withProperty("immutable.flag", Boolean.class)
|
||||
.withDefaultValue(false)
|
||||
.fromSource(ImmutableSimpleProperties.class)
|
||||
.withDescription("A simple flag.")
|
||||
.withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("immutable.comparator"));
|
||||
assertThat(metadata).has(Metadata.withProperty("immutable.counter"));
|
||||
assertThat(metadata.getItems()).hasSize(5);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@@ -41,14 +41,14 @@ class IncrementalBuildMetadataGenerationTests extends AbstractMetadataGeneration
|
||||
TestProject project = new TestProject(FooProperties.class, BarProperties.class);
|
||||
ConfigurationMetadata metadata = project.compile();
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("foo.counter").fromSource(FooProperties.class).withDefaultValue(0));
|
||||
.has(Metadata.withProperty("foo.counter").fromSource(FooProperties.class).withDefaultValue(0));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("bar.counter").fromSource(BarProperties.class).withDefaultValue(0));
|
||||
.has(Metadata.withProperty("bar.counter").fromSource(BarProperties.class).withDefaultValue(0));
|
||||
metadata = project.compile();
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("foo.counter").fromSource(FooProperties.class).withDefaultValue(0));
|
||||
.has(Metadata.withProperty("foo.counter").fromSource(FooProperties.class).withDefaultValue(0));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("bar.counter").fromSource(BarProperties.class).withDefaultValue(0));
|
||||
.has(Metadata.withProperty("bar.counter").fromSource(BarProperties.class).withDefaultValue(0));
|
||||
project.addSourceCode(BarProperties.class, BarProperties.class.getResourceAsStream("BarProperties.snippet"));
|
||||
metadata = project.compile();
|
||||
assertThat(metadata).has(Metadata.withProperty("bar.extra"));
|
||||
@@ -79,19 +79,19 @@ class IncrementalBuildMetadataGenerationTests extends AbstractMetadataGeneration
|
||||
TestProject project = new TestProject(FooProperties.class, BarProperties.class);
|
||||
ConfigurationMetadata metadata = project.compile();
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("foo.counter").fromSource(FooProperties.class).withDefaultValue(0));
|
||||
.has(Metadata.withProperty("foo.counter").fromSource(FooProperties.class).withDefaultValue(0));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("bar.counter").fromSource(BarProperties.class).withDefaultValue(0));
|
||||
.has(Metadata.withProperty("bar.counter").fromSource(BarProperties.class).withDefaultValue(0));
|
||||
assertThat(metadata).doesNotHave(Metadata.withProperty("bar.counter").fromSource(RenamedBarProperties.class));
|
||||
project.delete(BarProperties.class);
|
||||
project.add(RenamedBarProperties.class);
|
||||
metadata = project.compile();
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("foo.counter").fromSource(FooProperties.class).withDefaultValue(0));
|
||||
.has(Metadata.withProperty("foo.counter").fromSource(FooProperties.class).withDefaultValue(0));
|
||||
assertThat(metadata)
|
||||
.doesNotHave(Metadata.withProperty("bar.counter").fromSource(BarProperties.class).withDefaultValue(0));
|
||||
.doesNotHave(Metadata.withProperty("bar.counter").fromSource(BarProperties.class).withDefaultValue(0));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("bar.counter").withDefaultValue(0).fromSource(RenamedBarProperties.class));
|
||||
.has(Metadata.withProperty("bar.counter").withDefaultValue(0).fromSource(RenamedBarProperties.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@@ -128,8 +128,12 @@ class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
process(SimpleTypeProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(SimpleTypeProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "myString");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().hasName("test.my-string").hasType(String.class)
|
||||
.hasSourceType(SimpleTypeProperties.class).hasNoDescription().isNotDeprecated();
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.hasName("test.my-string")
|
||||
.hasType(String.class)
|
||||
.hasSourceType(SimpleTypeProperties.class)
|
||||
.hasNoDescription()
|
||||
.isNotDeprecated();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -138,9 +142,12 @@ class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
process(SimpleCollectionProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(SimpleCollectionProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "doubles");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().hasName("test.doubles")
|
||||
.hasType("java.util.List<java.lang.Double>").hasSourceType(SimpleCollectionProperties.class)
|
||||
.hasNoDescription().isNotDeprecated();
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.hasName("test.doubles")
|
||||
.hasType("java.util.List<java.lang.Double>")
|
||||
.hasSourceType(SimpleCollectionProperties.class)
|
||||
.hasNoDescription()
|
||||
.isNotDeprecated();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -149,10 +156,13 @@ class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
process(InnerClassProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(InnerClassProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "first");
|
||||
assertItemMetadata(metadataEnv, property).isGroup().hasName("test.first")
|
||||
.hasType("org.springframework.boot.configurationsample.specific.InnerClassProperties$Foo")
|
||||
.hasSourceType(InnerClassProperties.class).hasSourceMethod("getFirst()").hasNoDescription()
|
||||
.isNotDeprecated();
|
||||
assertItemMetadata(metadataEnv, property).isGroup()
|
||||
.hasName("test.first")
|
||||
.hasType("org.springframework.boot.configurationsample.specific.InnerClassProperties$Foo")
|
||||
.hasSourceType(InnerClassProperties.class)
|
||||
.hasSourceMethod("getFirst()")
|
||||
.hasNoDescription()
|
||||
.isNotDeprecated();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -172,8 +182,8 @@ class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
void javaBeanDeprecatedPropertyOnClass() {
|
||||
process(org.springframework.boot.configurationsample.simple.DeprecatedProperties.class,
|
||||
(roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(
|
||||
org.springframework.boot.configurationsample.simple.DeprecatedProperties.class);
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(org.springframework.boot.configurationsample.simple.DeprecatedProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "name");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().isDeprecatedWithNoInformation();
|
||||
});
|
||||
@@ -184,8 +194,9 @@ class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
process(DeprecatedSingleProperty.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(DeprecatedSingleProperty.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "name");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().isDeprecatedWithReason("renamed")
|
||||
.isDeprecatedWithReplacement("singledeprecated.new-name");
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.isDeprecatedWithReason("renamed")
|
||||
.isDeprecatedWithReplacement("singledeprecated.new-name");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -213,7 +224,7 @@ class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(SimpleProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "theName");
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.hasDescription("The name of this simple properties.");
|
||||
.hasDescription("The name of this simple properties.");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@@ -97,16 +97,18 @@ class LombokMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
void lombokInnerClassProperties() {
|
||||
ConfigurationMetadata metadata = compile(LombokInnerClassProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("config").fromSource(LombokInnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.first").ofType(LombokInnerClassProperties.Foo.class)
|
||||
.fromSource(LombokInnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.first")
|
||||
.ofType(LombokInnerClassProperties.Foo.class)
|
||||
.fromSource(LombokInnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.first.name"));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.first.bar.name"));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.second", LombokInnerClassProperties.Foo.class)
|
||||
.fromSource(LombokInnerClassProperties.class));
|
||||
.fromSource(LombokInnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.second.name"));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.second.bar.name"));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.third").ofType(SimpleLombokPojo.class)
|
||||
.fromSource(LombokInnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.third")
|
||||
.ofType(SimpleLombokPojo.class)
|
||||
.fromSource(LombokInnerClassProperties.class));
|
||||
// For some reason the annotation processor resolves a type for SimpleLombokPojo
|
||||
// that is resolved (compiled) and the source annotations are gone. Because we
|
||||
// don't see the @Data annotation anymore, no field is harvested. What is crazy is
|
||||
@@ -121,9 +123,10 @@ class LombokMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
void lombokInnerClassWithGetterProperties() {
|
||||
ConfigurationMetadata metadata = compile(LombokInnerClassWithGetterProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("config").fromSource(LombokInnerClassWithGetterProperties.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("config.first").ofType(LombokInnerClassWithGetterProperties.Foo.class)
|
||||
.fromSourceMethod("getFirst()").fromSource(LombokInnerClassWithGetterProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.first")
|
||||
.ofType(LombokInnerClassWithGetterProperties.Foo.class)
|
||||
.fromSourceMethod("getFirst()")
|
||||
.fromSource(LombokInnerClassWithGetterProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.first.name"));
|
||||
assertThat(metadata.getItems()).hasSize(3);
|
||||
}
|
||||
@@ -131,12 +134,15 @@ class LombokMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
private void assertSimpleLombokProperties(ConfigurationMetadata metadata, Class<?> source, String prefix) {
|
||||
assertThat(metadata).has(Metadata.withGroup(prefix).fromSource(source));
|
||||
assertThat(metadata).doesNotHave(Metadata.withProperty(prefix + ".id"));
|
||||
assertThat(metadata).has(Metadata.withProperty(prefix + ".name", String.class).fromSource(source)
|
||||
.withDescription("Name description."));
|
||||
assertThat(metadata).has(Metadata.withProperty(prefix + ".name", String.class)
|
||||
.fromSource(source)
|
||||
.withDescription("Name description."));
|
||||
assertThat(metadata).has(Metadata.withProperty(prefix + ".description"));
|
||||
assertThat(metadata).has(Metadata.withProperty(prefix + ".counter"));
|
||||
assertThat(metadata).has(Metadata.withProperty(prefix + ".number").fromSource(source).withDefaultValue(0)
|
||||
.withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty(prefix + ".number")
|
||||
.fromSource(source)
|
||||
.withDefaultValue(0)
|
||||
.withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty(prefix + ".items"));
|
||||
assertThat(metadata).doesNotHave(Metadata.withProperty(prefix + ".ignored"));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@@ -148,8 +148,12 @@ class LombokPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
process(LombokSimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(LombokSimpleProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "description");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().hasName("test.description").hasType(String.class)
|
||||
.hasSourceType(LombokSimpleProperties.class).hasNoDescription().isNotDeprecated();
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.hasName("test.description")
|
||||
.hasType(String.class)
|
||||
.hasSourceType(LombokSimpleProperties.class)
|
||||
.hasNoDescription()
|
||||
.isNotDeprecated();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -158,9 +162,12 @@ class LombokPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
process(LombokSimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(LombokSimpleProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "items");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().hasName("test.items")
|
||||
.hasType("java.util.List<java.lang.String>").hasSourceType(LombokSimpleProperties.class)
|
||||
.hasNoDescription().isNotDeprecated();
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.hasName("test.items")
|
||||
.hasType("java.util.List<java.lang.String>")
|
||||
.hasSourceType(LombokSimpleProperties.class)
|
||||
.hasNoDescription()
|
||||
.isNotDeprecated();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -172,10 +179,13 @@ class LombokPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
ExecutableElement getter = getMethod(ownerElement, "getThird");
|
||||
LombokPropertyDescriptor property = new LombokPropertyDescriptor(ownerElement, null, field, "third",
|
||||
field.asType(), getter, null);
|
||||
assertItemMetadata(metadataEnv, property).isGroup().hasName("test.third")
|
||||
.hasType("org.springframework.boot.configurationsample.lombok.SimpleLombokPojo")
|
||||
.hasSourceType(LombokInnerClassProperties.class).hasSourceMethod("getThird()").hasNoDescription()
|
||||
.isNotDeprecated();
|
||||
assertItemMetadata(metadataEnv, property).isGroup()
|
||||
.hasName("test.third")
|
||||
.hasType("org.springframework.boot.configurationsample.lombok.SimpleLombokPojo")
|
||||
.hasSourceType(LombokInnerClassProperties.class)
|
||||
.hasSourceMethod("getThird()")
|
||||
.hasNoDescription()
|
||||
.isNotDeprecated();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -184,10 +194,13 @@ class LombokPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
process(LombokInnerClassProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(LombokInnerClassProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "first");
|
||||
assertItemMetadata(metadataEnv, property).isGroup().hasName("test.first")
|
||||
.hasType("org.springframework.boot.configurationsample.lombok.LombokInnerClassProperties$Foo")
|
||||
.hasSourceType(LombokInnerClassProperties.class).hasSourceMethod(null).hasNoDescription()
|
||||
.isNotDeprecated();
|
||||
assertItemMetadata(metadataEnv, property).isGroup()
|
||||
.hasName("test.first")
|
||||
.hasType("org.springframework.boot.configurationsample.lombok.LombokInnerClassProperties$Foo")
|
||||
.hasSourceType(LombokInnerClassProperties.class)
|
||||
.hasSourceMethod(null)
|
||||
.hasNoDescription()
|
||||
.isNotDeprecated();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@@ -71,8 +71,11 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
ItemMetadata property = ItemMetadata.newProperty("simple", "flag", null, null, null, null, true, null);
|
||||
String additionalMetadata = buildAdditionalMetadata(property);
|
||||
ConfigurationMetadata metadata = compile(additionalMetadata, SimpleProperties.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.flag", Boolean.class).fromSource(SimpleProperties.class)
|
||||
.withDescription("A simple flag.").withDeprecation(null, null).withDefaultValue(true));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.flag", Boolean.class)
|
||||
.fromSource(SimpleProperties.class)
|
||||
.withDescription("A simple flag.")
|
||||
.withDeprecation(null, null)
|
||||
.withDefaultValue(true));
|
||||
assertThat(metadata.getItems()).hasSize(4);
|
||||
}
|
||||
|
||||
@@ -84,17 +87,23 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
ConfigurationMetadata metadata = compile(additionalMetadata, SimpleProperties.class,
|
||||
SimpleConflictingProperties.class);
|
||||
assertThat(metadata.getItems()).hasSize(6);
|
||||
List<ItemMetadata> items = metadata.getItems().stream().filter((item) -> item.getName().equals("simple.flag"))
|
||||
.toList();
|
||||
List<ItemMetadata> items = metadata.getItems()
|
||||
.stream()
|
||||
.filter((item) -> item.getName().equals("simple.flag"))
|
||||
.toList();
|
||||
assertThat(items).hasSize(2);
|
||||
ItemMetadata matchingProperty = items.stream().filter((item) -> item.getType().equals(Boolean.class.getName()))
|
||||
.findFirst().orElse(null);
|
||||
ItemMetadata matchingProperty = items.stream()
|
||||
.filter((item) -> item.getType().equals(Boolean.class.getName()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
assertThat(matchingProperty).isNotNull();
|
||||
assertThat(matchingProperty.getDefaultValue()).isEqualTo(true);
|
||||
assertThat(matchingProperty.getSourceType()).isEqualTo(SimpleProperties.class.getName());
|
||||
assertThat(matchingProperty.getDescription()).isEqualTo("A simple flag.");
|
||||
ItemMetadata nonMatchingProperty = items.stream()
|
||||
.filter((item) -> item.getType().equals(String.class.getName())).findFirst().orElse(null);
|
||||
.filter((item) -> item.getType().equals(String.class.getName()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
assertThat(nonMatchingProperty).isNotNull();
|
||||
assertThat(nonMatchingProperty.getDefaultValue()).isEqualTo("hello");
|
||||
assertThat(nonMatchingProperty.getSourceType()).isEqualTo(SimpleConflictingProperties.class.getName());
|
||||
@@ -108,7 +117,8 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
String additionalMetadata = buildAdditionalMetadata(property);
|
||||
ConfigurationMetadata metadata = compile(additionalMetadata, SimpleProperties.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.comparator", "java.util.Comparator<?>")
|
||||
.fromSource(SimpleProperties.class).withDescription("A nice comparator."));
|
||||
.fromSource(SimpleProperties.class)
|
||||
.withDescription("A nice comparator."));
|
||||
assertThat(metadata.getItems()).hasSize(4);
|
||||
}
|
||||
|
||||
@@ -118,9 +128,9 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
new ItemDeprecation("Don't use this.", "simple.complex-comparator", "error"));
|
||||
String additionalMetadata = buildAdditionalMetadata(property);
|
||||
ConfigurationMetadata metadata = compile(additionalMetadata, SimpleProperties.class);
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("simple.comparator", "java.util.Comparator<?>").fromSource(SimpleProperties.class)
|
||||
.withDeprecation("Don't use this.", "simple.complex-comparator", "error"));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.comparator", "java.util.Comparator<?>")
|
||||
.fromSource(SimpleProperties.class)
|
||||
.withDeprecation("Don't use this.", "simple.complex-comparator", "error"));
|
||||
assertThat(metadata.getItems()).hasSize(4);
|
||||
}
|
||||
|
||||
@@ -131,7 +141,8 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
String additionalMetadata = buildAdditionalMetadata(property);
|
||||
ConfigurationMetadata metadata = compile(additionalMetadata, DeprecatedSingleProperty.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("singledeprecated.name", String.class.getName())
|
||||
.fromSource(DeprecatedSingleProperty.class).withDeprecation("Don't use this.", "single.name"));
|
||||
.fromSource(DeprecatedSingleProperty.class)
|
||||
.withDeprecation("Don't use this.", "single.name"));
|
||||
assertThat(metadata.getItems()).hasSize(3);
|
||||
}
|
||||
|
||||
@@ -142,8 +153,8 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
String additionalMetadata = buildAdditionalMetadata(property);
|
||||
ConfigurationMetadata metadata = compile(additionalMetadata, DeprecatedSingleProperty.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("singledeprecated.name", String.class.getName())
|
||||
.fromSource(DeprecatedSingleProperty.class)
|
||||
.withDeprecation("renamed", "singledeprecated.new-name", "error"));
|
||||
.fromSource(DeprecatedSingleProperty.class)
|
||||
.withDeprecation("renamed", "singledeprecated.new-name", "error"));
|
||||
assertThat(metadata.getItems()).hasSize(3);
|
||||
}
|
||||
|
||||
@@ -151,8 +162,8 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
void mergeOfInvalidAdditionalMetadata() {
|
||||
String metadata = "Hello World";
|
||||
assertThatExceptionOfType(CompilationException.class)
|
||||
.isThrownBy(() -> compile(metadata, SimpleProperties.class))
|
||||
.withMessageContaining("Invalid additional meta-data");
|
||||
.isThrownBy(() -> compile(metadata, SimpleProperties.class))
|
||||
.withMessageContaining("Invalid additional meta-data");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -161,10 +172,12 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
new ItemHint.ValueHint("boot", "Bla bla"), new ItemHint.ValueHint("spring", null)));
|
||||
ConfigurationMetadata metadata = compile(hints, SimpleProperties.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.the-name", String.class)
|
||||
.fromSource(SimpleProperties.class).withDescription("The name of this simple properties.")
|
||||
.withDefaultValue("boot").withDeprecation(null, null));
|
||||
.fromSource(SimpleProperties.class)
|
||||
.withDescription("The name of this simple properties.")
|
||||
.withDefaultValue("boot")
|
||||
.withDeprecation(null, null));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withHint("simple.the-name").withValue(0, "boot", "Bla bla").withValue(1, "spring", null));
|
||||
.has(Metadata.withHint("simple.the-name").withValue(0, "boot", "Bla bla").withValue(1, "spring", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -173,8 +186,10 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
ItemHint.newHint("simple.theName", new ItemHint.ValueHint("boot", "Bla bla")));
|
||||
ConfigurationMetadata metadata = compile(hints, SimpleProperties.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.the-name", String.class)
|
||||
.fromSource(SimpleProperties.class).withDescription("The name of this simple properties.")
|
||||
.withDefaultValue("boot").withDeprecation(null, null));
|
||||
.fromSource(SimpleProperties.class)
|
||||
.withDescription("The name of this simple properties.")
|
||||
.withDefaultValue("boot")
|
||||
.withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withHint("simple.the-name").withValue(0, "boot", "Bla bla"));
|
||||
}
|
||||
|
||||
@@ -185,8 +200,10 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
new ItemHint.ValueProvider("second", null))));
|
||||
ConfigurationMetadata metadata = compile(hints, SimpleProperties.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.the-name", String.class)
|
||||
.fromSource(SimpleProperties.class).withDescription("The name of this simple properties.")
|
||||
.withDefaultValue("boot").withDeprecation(null, null));
|
||||
.fromSource(SimpleProperties.class)
|
||||
.withDescription("The name of this simple properties.")
|
||||
.withDefaultValue("boot")
|
||||
.withDeprecation(null, null));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withHint("simple.the-name").withProvider("first", "target", "org.foo").withProvider("second"));
|
||||
}
|
||||
@@ -196,8 +213,8 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
String deprecations = buildPropertyDeprecations(ItemMetadata.newProperty("simple", "wrongName",
|
||||
"java.lang.String", null, null, null, null, new ItemDeprecation("Lame name.", "simple.the-name")));
|
||||
ConfigurationMetadata metadata = compile(deprecations, SimpleProperties.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.wrong-name", String.class).withDeprecation("Lame name.",
|
||||
"simple.the-name"));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.wrong-name", String.class)
|
||||
.withDeprecation("Lame name.", "simple.the-name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@@ -53,7 +53,7 @@ class MetadataStoreTests {
|
||||
additionalMetadata.createNewFile();
|
||||
assertThat(this.metadataStore.locateAdditionalMetadataFile(
|
||||
new File(classesLocation, "META-INF/additional-spring-configuration-metadata.json")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
.isEqualTo(additionalMetadata);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,7 +67,7 @@ class MetadataStoreTests {
|
||||
additionalMetadata.createNewFile();
|
||||
assertThat(this.metadataStore.locateAdditionalMetadataFile(
|
||||
new File(classesLocation, "META-INF/additional-spring-configuration-metadata.json")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
.isEqualTo(additionalMetadata);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,7 +81,7 @@ class MetadataStoreTests {
|
||||
additionalMetadata.createNewFile();
|
||||
assertThat(this.metadataStore.locateAdditionalMetadataFile(
|
||||
new File(classesLocation, "META-INF/additional-spring-configuration-metadata.json")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
.isEqualTo(additionalMetadata);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@@ -60,7 +60,7 @@ class MethodBasedMetadataGenerationTests extends AbstractMetadataGenerationTests
|
||||
assertThat(metadata).has(Metadata.withGroup("foo").fromSource(config));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.name", String.class).fromSource(properties));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("foo.flag", Boolean.class).withDefaultValue(false).fromSource(properties));
|
||||
.has(Metadata.withProperty("foo.flag", Boolean.class).withDefaultValue(false).fromSource(properties));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +73,7 @@ class MethodBasedMetadataGenerationTests extends AbstractMetadataGenerationTests
|
||||
void invalidMethodConfig() {
|
||||
ConfigurationMetadata metadata = compile(InvalidMethodConfig.class);
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("something.name", String.class).fromSource(InvalidMethodConfig.class));
|
||||
.has(Metadata.withProperty("something.name", String.class).fromSource(InvalidMethodConfig.class));
|
||||
assertThat(metadata).isNotEqualTo(Metadata.withProperty("invalid.name"));
|
||||
}
|
||||
|
||||
@@ -81,22 +81,24 @@ class MethodBasedMetadataGenerationTests extends AbstractMetadataGenerationTests
|
||||
void methodAndClassConfig() {
|
||||
ConfigurationMetadata metadata = compile(MethodAndClassConfig.class);
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("conflict.name", String.class).fromSource(MethodAndClassConfig.Foo.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("conflict.flag", Boolean.class).withDefaultValue(false)
|
||||
.fromSource(MethodAndClassConfig.Foo.class));
|
||||
.has(Metadata.withProperty("conflict.name", String.class).fromSource(MethodAndClassConfig.Foo.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("conflict.flag", Boolean.class)
|
||||
.withDefaultValue(false)
|
||||
.fromSource(MethodAndClassConfig.Foo.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("conflict.value", String.class).fromSource(MethodAndClassConfig.class));
|
||||
.has(Metadata.withProperty("conflict.value", String.class).fromSource(MethodAndClassConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void singleConstructorMethodConfig() {
|
||||
ConfigurationMetadata metadata = compile(SingleConstructorMethodConfig.class);
|
||||
assertThat(metadata).doesNotHave(Metadata.withProperty("foo.my-service", Object.class)
|
||||
.fromSource(SingleConstructorMethodConfig.Foo.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("foo.name", String.class).fromSource(SingleConstructorMethodConfig.Foo.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class).withDefaultValue(false)
|
||||
.fromSource(SingleConstructorMethodConfig.Foo.class));
|
||||
.fromSource(SingleConstructorMethodConfig.Foo.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("foo.name", String.class).fromSource(SingleConstructorMethodConfig.Foo.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class)
|
||||
.withDefaultValue(false)
|
||||
.fromSource(SingleConstructorMethodConfig.Foo.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -111,9 +113,12 @@ class MethodBasedMetadataGenerationTests extends AbstractMetadataGenerationTests
|
||||
ConfigurationMetadata metadata = compile(type);
|
||||
assertThat(metadata).has(Metadata.withGroup("foo").fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.name", String.class)
|
||||
.fromSource(DeprecatedMethodConfig.Foo.class).withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class).withDefaultValue(false)
|
||||
.fromSource(DeprecatedMethodConfig.Foo.class).withDeprecation(null, null));
|
||||
.fromSource(DeprecatedMethodConfig.Foo.class)
|
||||
.withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class)
|
||||
.withDefaultValue(false)
|
||||
.fromSource(DeprecatedMethodConfig.Foo.class)
|
||||
.withDeprecation(null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -123,11 +128,12 @@ class MethodBasedMetadataGenerationTests extends AbstractMetadataGenerationTests
|
||||
ConfigurationMetadata metadata = compile(type);
|
||||
assertThat(metadata).has(Metadata.withGroup("foo").fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.name", String.class)
|
||||
.fromSource(org.springframework.boot.configurationsample.method.DeprecatedClassMethodConfig.Foo.class)
|
||||
.withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class).withDefaultValue(false)
|
||||
.fromSource(org.springframework.boot.configurationsample.method.DeprecatedClassMethodConfig.Foo.class)
|
||||
.withDeprecation(null, null));
|
||||
.fromSource(org.springframework.boot.configurationsample.method.DeprecatedClassMethodConfig.Foo.class)
|
||||
.withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class)
|
||||
.withDefaultValue(false)
|
||||
.fromSource(org.springframework.boot.configurationsample.method.DeprecatedClassMethodConfig.Foo.class)
|
||||
.withDeprecation(null, null));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@@ -73,13 +73,13 @@ class PropertyDescriptorResolverTests {
|
||||
PropertyDescriptorResolver resolver = new PropertyDescriptorResolver(metadataEnv);
|
||||
assertThat(resolver.resolve(type, null).map(PropertyDescriptor::getName)).containsExactly("third",
|
||||
"second", "first");
|
||||
assertThat(resolver.resolve(type, null).map(
|
||||
(descriptor) -> descriptor.getGetter().getEnclosingElement().getSimpleName().toString()))
|
||||
.containsExactly("HierarchicalProperties", "HierarchicalPropertiesParent",
|
||||
"HierarchicalPropertiesParent");
|
||||
assertThat(resolver.resolve(type, null)
|
||||
.map((descriptor) -> descriptor.resolveItemMetadata("test", metadataEnv))
|
||||
.map(ItemMetadata::getDefaultValue)).containsExactly("three", "two", "one");
|
||||
.map((descriptor) -> descriptor.getGetter().getEnclosingElement().getSimpleName().toString()))
|
||||
.containsExactly("HierarchicalProperties", "HierarchicalPropertiesParent",
|
||||
"HierarchicalPropertiesParent");
|
||||
assertThat(resolver.resolve(type, null)
|
||||
.map((descriptor) -> descriptor.resolveItemMetadata("test", metadataEnv))
|
||||
.map(ItemMetadata::getDefaultValue)).containsExactly("three", "two", "one");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ class PropertyDescriptorResolverTests {
|
||||
process(ImmutableDeducedConstructorBindingProperties.class,
|
||||
propertyNames((stream) -> assertThat(stream).containsExactly("theName", "flag")));
|
||||
process(ImmutableDeducedConstructorBindingProperties.class, properties((stream) -> assertThat(stream)
|
||||
.allMatch((predicate) -> predicate instanceof ConstructorParameterPropertyDescriptor)));
|
||||
.allMatch((predicate) -> predicate instanceof ConstructorParameterPropertyDescriptor)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -120,7 +120,7 @@ class PropertyDescriptorResolverTests {
|
||||
process(ImmutableSimpleProperties.class, propertyNames(
|
||||
(stream) -> assertThat(stream).containsExactly("theName", "flag", "comparator", "counter")));
|
||||
process(ImmutableSimpleProperties.class, properties((stream) -> assertThat(stream)
|
||||
.allMatch((predicate) -> predicate instanceof ConstructorParameterPropertyDescriptor)));
|
||||
.allMatch((predicate) -> predicate instanceof ConstructorParameterPropertyDescriptor)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -128,14 +128,14 @@ class PropertyDescriptorResolverTests {
|
||||
process(ImmutableClassConstructorBindingProperties.class,
|
||||
propertyNames((stream) -> assertThat(stream).containsExactly("name", "description")));
|
||||
process(ImmutableClassConstructorBindingProperties.class, properties((stream) -> assertThat(stream)
|
||||
.allMatch((predicate) -> predicate instanceof ConstructorParameterPropertyDescriptor)));
|
||||
.allMatch((predicate) -> predicate instanceof ConstructorParameterPropertyDescriptor)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void propertiesWithAutowiredConstructor() {
|
||||
process(AutowiredProperties.class, propertyNames((stream) -> assertThat(stream).containsExactly("theName")));
|
||||
process(AutowiredProperties.class, properties((stream) -> assertThat(stream)
|
||||
.allMatch((predicate) -> predicate instanceof JavaBeanPropertyDescriptor)));
|
||||
.allMatch((predicate) -> predicate instanceof JavaBeanPropertyDescriptor)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -143,7 +143,7 @@ class PropertyDescriptorResolverTests {
|
||||
process(ImmutableMultiConstructorProperties.class,
|
||||
propertyNames((stream) -> assertThat(stream).containsExactly("name", "description")));
|
||||
process(ImmutableMultiConstructorProperties.class, properties((stream) -> assertThat(stream)
|
||||
.allMatch((predicate) -> predicate instanceof ConstructorParameterPropertyDescriptor)));
|
||||
.allMatch((predicate) -> predicate instanceof ConstructorParameterPropertyDescriptor)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -154,7 +154,7 @@ class PropertyDescriptorResolverTests {
|
||||
propertyNames((stream) -> assertThat(stream).containsExactly("name", "description")));
|
||||
process(org.springframework.boot.configurationsample.immutable.DeprecatedImmutableMultiConstructorProperties.class,
|
||||
properties((stream) -> assertThat(stream)
|
||||
.allMatch((predicate) -> predicate instanceof ConstructorParameterPropertyDescriptor)));
|
||||
.allMatch((predicate) -> predicate instanceof ConstructorParameterPropertyDescriptor)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -197,8 +197,10 @@ class PropertyDescriptorResolverTests {
|
||||
internalConsumer, new MetadataGenerationEnvironmentFactory());
|
||||
SourceFile targetSource = SourceFile.forTestClass(target);
|
||||
List<SourceFile> additionalSource = additionalClasses.stream().map(SourceFile::forTestClass).toList();
|
||||
TestCompiler compiler = TestCompiler.forSystem().withProcessors(processor).withSources(targetSource)
|
||||
.withSources(additionalSource);
|
||||
TestCompiler compiler = TestCompiler.forSystem()
|
||||
.withProcessors(processor)
|
||||
.withSources(targetSource)
|
||||
.withSources(additionalSource);
|
||||
compiler.compile((compiled) -> {
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@@ -45,15 +45,19 @@ public abstract class PropertyDescriptorTests {
|
||||
}
|
||||
|
||||
protected ExecutableElement getMethod(TypeElement element, String name) {
|
||||
return ElementFilter.methodsIn(element.getEnclosedElements()).stream()
|
||||
.filter((method) -> ((Element) method).getSimpleName().toString().equals(name)).findFirst()
|
||||
.orElse(null);
|
||||
return ElementFilter.methodsIn(element.getEnclosedElements())
|
||||
.stream()
|
||||
.filter((method) -> ((Element) method).getSimpleName().toString().equals(name))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
protected VariableElement getField(TypeElement element, String name) {
|
||||
return ElementFilter.fieldsIn(element.getEnclosedElements()).stream()
|
||||
.filter((method) -> ((Element) method).getSimpleName().toString().equals(name)).findFirst()
|
||||
.orElse(null);
|
||||
return ElementFilter.fieldsIn(element.getEnclosedElements())
|
||||
.stream()
|
||||
.filter((method) -> ((Element) method).getSimpleName().toString().equals(name))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
protected ItemMetadataAssert assertItemMetadata(MetadataGenerationEnvironment metadataEnv,
|
||||
@@ -65,8 +69,9 @@ public abstract class PropertyDescriptorTests {
|
||||
BiConsumer<RoundEnvironmentTester, MetadataGenerationEnvironment> consumer) {
|
||||
TestableAnnotationProcessor<MetadataGenerationEnvironment> processor = new TestableAnnotationProcessor<>(
|
||||
consumer, new MetadataGenerationEnvironmentFactory());
|
||||
TestCompiler compiler = TestCompiler.forSystem().withProcessors(processor)
|
||||
.withSources(SourceFile.forTestClass(target));
|
||||
TestCompiler compiler = TestCompiler.forSystem()
|
||||
.withProcessors(processor)
|
||||
.withSources(SourceFile.forTestClass(target));
|
||||
compiler.compile((compiled) -> {
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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,8 @@ public class TestProject {
|
||||
*/
|
||||
public void delete(Class<?> type) {
|
||||
SourceFile[] newSources = this.sources.stream()
|
||||
.filter((sourceFile) -> !sourceFile.getPath().equals(SourceFile.forTestClass(type).getPath()))
|
||||
.toArray(SourceFile[]::new);
|
||||
.filter((sourceFile) -> !sourceFile.getPath().equals(SourceFile.forTestClass(type).getPath()))
|
||||
.toArray(SourceFile[]::new);
|
||||
this.sources = SourceFiles.of(newSources);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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,7 +44,7 @@ class TypeUtilsTests {
|
||||
void resolveTypeDescriptorOnConcreteClass() {
|
||||
process(SimpleGenericProperties.class, (roundEnv, typeUtils) -> {
|
||||
TypeDescriptor typeDescriptor = typeUtils
|
||||
.resolveTypeDescriptor(roundEnv.getRootElement(SimpleGenericProperties.class));
|
||||
.resolveTypeDescriptor(roundEnv.getRootElement(SimpleGenericProperties.class));
|
||||
assertThat(typeDescriptor.getGenerics().keySet().stream().map(Object::toString)).containsOnly("A", "B",
|
||||
"C");
|
||||
assertThat(typeDescriptor.resolveGeneric("A")).hasToString(String.class.getName());
|
||||
@@ -58,7 +58,7 @@ class TypeUtilsTests {
|
||||
void resolveTypeDescriptorOnIntermediateClass() {
|
||||
process(AbstractIntermediateGenericProperties.class, (roundEnv, typeUtils) -> {
|
||||
TypeDescriptor typeDescriptor = typeUtils
|
||||
.resolveTypeDescriptor(roundEnv.getRootElement(AbstractIntermediateGenericProperties.class));
|
||||
.resolveTypeDescriptor(roundEnv.getRootElement(AbstractIntermediateGenericProperties.class));
|
||||
assertThat(typeDescriptor.getGenerics().keySet().stream().map(Object::toString)).containsOnly("A", "B",
|
||||
"C");
|
||||
assertThat(typeDescriptor.resolveGeneric("A")).hasToString(String.class.getName());
|
||||
@@ -71,7 +71,7 @@ class TypeUtilsTests {
|
||||
void resolveTypeDescriptorWithOnlyGenerics() {
|
||||
process(AbstractGenericProperties.class, (roundEnv, typeUtils) -> {
|
||||
TypeDescriptor typeDescriptor = typeUtils
|
||||
.resolveTypeDescriptor(roundEnv.getRootElement(AbstractGenericProperties.class));
|
||||
.resolveTypeDescriptor(roundEnv.getRootElement(AbstractGenericProperties.class));
|
||||
assertThat(typeDescriptor.getGenerics().keySet().stream().map(Object::toString)).containsOnly("A", "B",
|
||||
"C");
|
||||
|
||||
@@ -80,8 +80,9 @@ class TypeUtilsTests {
|
||||
|
||||
private void process(Class<?> target, BiConsumer<RoundEnvironmentTester, TypeUtils> consumer) {
|
||||
TestableAnnotationProcessor<TypeUtils> processor = new TestableAnnotationProcessor<>(consumer, TypeUtils::new);
|
||||
TestCompiler compiler = TestCompiler.forSystem().withProcessors(processor)
|
||||
.withSources(SourceFile.forTestClass(target));
|
||||
TestCompiler compiler = TestCompiler.forSystem()
|
||||
.withProcessors(processor)
|
||||
.withSources(SourceFile.forTestClass(target));
|
||||
compiler.compile((compiled) -> {
|
||||
});
|
||||
}
|
||||
|
||||
@@ -50,8 +50,9 @@ public abstract class AbstractFieldValuesProcessorTests {
|
||||
@Test
|
||||
void getFieldValues() throws Exception {
|
||||
TestProcessor processor = new TestProcessor();
|
||||
TestCompiler compiler = TestCompiler.forSystem().withProcessors(processor)
|
||||
.withSources(SourceFile.forTestClass(FieldValues.class));
|
||||
TestCompiler compiler = TestCompiler.forSystem()
|
||||
.withProcessors(processor)
|
||||
.withSources(SourceFile.forTestClass(FieldValues.class));
|
||||
compiler.compile((compiled) -> {
|
||||
});
|
||||
Map<String, Object> values = processor.getValues();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@@ -55,8 +55,11 @@ class JsonMarshallerTests {
|
||||
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"));
|
||||
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));
|
||||
@@ -126,10 +129,10 @@ class JsonMarshallerTests {
|
||||
null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.bravo", "aaa", "java.lang.Integer", "com.example.Bar", null,
|
||||
null, null, null));
|
||||
metadata.add(
|
||||
ItemMetadata.newProperty("com.example.alpha", "ddd", null, "com.example.Bar", null, null, null, null));
|
||||
metadata.add(
|
||||
ItemMetadata.newProperty("com.example.alpha", "ccc", null, "com.example.Foo", null, null, null, null));
|
||||
metadata
|
||||
.add(ItemMetadata.newProperty("com.example.alpha", "ddd", null, "com.example.Bar", null, null, null, null));
|
||||
metadata
|
||||
.add(ItemMetadata.newProperty("com.example.alpha", "ccc", null, "com.example.Foo", null, null, null, null));
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
JsonMarshaller marshaller = new JsonMarshaller();
|
||||
marshaller.write(metadata, outputStream);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 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,8 +208,10 @@ public final class Metadata {
|
||||
}
|
||||
|
||||
private ItemMetadata findItem(ConfigurationMetadata metadata, String name) {
|
||||
List<ItemMetadata> candidates = metadata.getItems().stream()
|
||||
.filter((item) -> item.isOfItemType(this.itemType) && name.equals(item.getName())).toList();
|
||||
List<ItemMetadata> candidates = metadata.getItems()
|
||||
.stream()
|
||||
.filter((item) -> item.isOfItemType(this.itemType) && name.equals(item.getName()))
|
||||
.toList();
|
||||
if (candidates.size() > 1) {
|
||||
throw new IllegalStateException("More than one metadata item with name '" + name + "': " + candidates);
|
||||
}
|
||||
@@ -389,7 +391,7 @@ public final class Metadata {
|
||||
if (this.parameters != null) {
|
||||
for (Map.Entry<String, Object> entry : this.parameters.entrySet()) {
|
||||
if (!IsMapContaining.hasEntry(entry.getKey(), entry.getValue())
|
||||
.matches(valueProvider.getParameters())) {
|
||||
.matches(valueProvider.getParameters())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2023 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,10 +38,12 @@ public class RoundEnvironmentTester {
|
||||
* @return the {@link TypeElement}
|
||||
*/
|
||||
public TypeElement getRootElement(Class<?> type) {
|
||||
return (TypeElement) this.roundEnvironment.getRootElements().stream()
|
||||
.filter((element) -> element.toString().equals(type.getName())).findFirst()
|
||||
.orElseThrow(() -> new IllegalStateException("No element found for " + type
|
||||
+ " make sure it is included in the list of classes to compile"));
|
||||
return (TypeElement) this.roundEnvironment.getRootElements()
|
||||
.stream()
|
||||
.filter((element) -> element.toString().equals(type.getName()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new IllegalStateException(
|
||||
"No element found for " + type + " make sure it is included in the list of classes to compile"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ import org.springframework.boot.configurationsample.DeprecatedConfigurationPrope
|
||||
|
||||
/**
|
||||
* Configuration properties as record with deprecated property.
|
||||
*
|
||||
* @param alpha alpha property, deprecated
|
||||
* @param bravo bravo property
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
@ConfigurationProperties("deprecated-record")
|
||||
|
||||
Reference in New Issue
Block a user