Add 'deprecated' field to configuration meta-data
Update the ConfigurationMetadataAnnotationProcessor to detect the @Deprecated annotation on getters or setters. Fixes gh-1846
This commit is contained in:
@@ -76,11 +76,12 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
containsProperty("simple.the-name", String.class)
|
||||
.fromSource(SimpleProperties.class)
|
||||
.withDescription("The name of this simple properties.")
|
||||
.withDefaultValue("boot"));
|
||||
.withDefaultValue("boot").withDeprecated());
|
||||
assertThat(
|
||||
metadata,
|
||||
containsProperty("simple.flag", Boolean.class).fromSource(
|
||||
SimpleProperties.class).withDescription("A simple flag."));
|
||||
containsProperty("simple.flag", Boolean.class)
|
||||
.fromSource(SimpleProperties.class)
|
||||
.withDescription("A simple flag.").withDeprecated());
|
||||
assertThat(metadata, containsProperty("simple.comparator"));
|
||||
assertThat(metadata, not(containsProperty("simple.counter")));
|
||||
assertThat(metadata, not(containsProperty("simple.size")));
|
||||
|
||||
@@ -68,18 +68,22 @@ public class ConfigurationMetadataMatchers {
|
||||
|
||||
private final Object defaultValue;
|
||||
|
||||
private final boolean deprecated;
|
||||
|
||||
public ContainsItemMatcher(ItemType itemType, String name) {
|
||||
this(itemType, name, null, null, null, null);
|
||||
this(itemType, name, null, null, null, null, false);
|
||||
}
|
||||
|
||||
public ContainsItemMatcher(ItemType itemType, String name, String type,
|
||||
Class<?> sourceType, String description, Object defaultValue) {
|
||||
Class<?> sourceType, String description, Object defaultValue,
|
||||
boolean deprecated) {
|
||||
this.itemType = itemType;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.sourceType = sourceType;
|
||||
this.description = description;
|
||||
this.defaultValue = defaultValue;
|
||||
this.deprecated = deprecated;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,6 +108,9 @@ public class ConfigurationMetadataMatchers {
|
||||
&& !this.description.equals(itemMetadata.getDescription())) {
|
||||
return false;
|
||||
}
|
||||
if (this.deprecated != itemMetadata.isDeprecated()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -134,31 +141,39 @@ public class ConfigurationMetadataMatchers {
|
||||
if (this.description != null) {
|
||||
description.appendText(" description ").appendValue(this.description);
|
||||
}
|
||||
if (this.deprecated) {
|
||||
description.appendText(" deprecated ").appendValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public ContainsItemMatcher ofType(Class<?> dataType) {
|
||||
return new ContainsItemMatcher(this.itemType, this.name, dataType.getName(),
|
||||
this.sourceType, this.description, this.defaultValue);
|
||||
this.sourceType, this.description, this.defaultValue, this.deprecated);
|
||||
}
|
||||
|
||||
public ContainsItemMatcher ofDataType(String dataType) {
|
||||
return new ContainsItemMatcher(this.itemType, this.name, dataType,
|
||||
this.sourceType, this.description, this.defaultValue);
|
||||
this.sourceType, this.description, this.defaultValue, this.deprecated);
|
||||
}
|
||||
|
||||
public ContainsItemMatcher fromSource(Class<?> sourceType) {
|
||||
return new ContainsItemMatcher(this.itemType, this.name, this.type,
|
||||
sourceType, this.description, this.defaultValue);
|
||||
sourceType, this.description, this.defaultValue, this.deprecated);
|
||||
}
|
||||
|
||||
public ContainsItemMatcher withDescription(String description) {
|
||||
return new ContainsItemMatcher(this.itemType, this.name, this.type,
|
||||
this.sourceType, description, this.defaultValue);
|
||||
this.sourceType, description, this.defaultValue, this.deprecated);
|
||||
}
|
||||
|
||||
public Matcher<? super ConfigurationMetadata> withDefaultValue(Object defaultValue) {
|
||||
public ContainsItemMatcher withDefaultValue(Object defaultValue) {
|
||||
return new ContainsItemMatcher(this.itemType, this.name, this.type,
|
||||
this.sourceType, this.description, defaultValue);
|
||||
this.sourceType, this.description, defaultValue, this.deprecated);
|
||||
}
|
||||
|
||||
public ContainsItemMatcher withDeprecated() {
|
||||
return new ContainsItemMatcher(this.itemType, this.name, this.type,
|
||||
this.sourceType, this.description, this.defaultValue, true);
|
||||
}
|
||||
|
||||
private ItemMetadata getFirstPropertyWithName(ConfigurationMetadata metadata,
|
||||
|
||||
@@ -38,11 +38,13 @@ public class JsonMarshallerTests {
|
||||
public void marshallAndUnmarshal() throws IOException {
|
||||
ConfigurationMetadata metadata = new ConfigurationMetadata();
|
||||
metadata.add(ItemMetadata.newProperty("a", "b", StringBuffer.class.getName(),
|
||||
InputStream.class.getName(), "sourceMethod", "desc", "x"));
|
||||
metadata.add(ItemMetadata
|
||||
.newProperty("b.c.d", null, null, null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("c", null, null, null, null, null, 123));
|
||||
metadata.add(ItemMetadata.newProperty("d", null, null, null, null, null, true));
|
||||
InputStream.class.getName(), "sourceMethod", "desc", "x", true));
|
||||
metadata.add(ItemMetadata.newProperty("b.c.d", null, null, null, null, null,
|
||||
null, false));
|
||||
metadata.add(ItemMetadata.newProperty("c", null, null, null, null, null, 123,
|
||||
false));
|
||||
metadata.add(ItemMetadata.newProperty("d", null, null, null, null, null, true,
|
||||
false));
|
||||
metadata.add(ItemMetadata.newGroup("d", null, null, null));
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
JsonMarshaller marshaller = new JsonMarshaller();
|
||||
@@ -52,7 +54,7 @@ public class JsonMarshallerTests {
|
||||
outputStream.toByteArray()));
|
||||
assertThat(read,
|
||||
containsProperty("a.b", StringBuffer.class).fromSource(InputStream.class)
|
||||
.withDescription("desc").withDefaultValue("x"));
|
||||
.withDescription("desc").withDefaultValue("x").withDeprecated());
|
||||
assertThat(read, containsProperty("b.c.d"));
|
||||
assertThat(read, containsProperty("c").withDefaultValue(123));
|
||||
assertThat(read, containsProperty("d").withDefaultValue(true));
|
||||
|
||||
@@ -58,10 +58,12 @@ public class SimpleProperties {
|
||||
return this.theName;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setTheName(String name) {
|
||||
this.theName = name;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isFlag() {
|
||||
return this.flag;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user