Add since attribute to @DeprecatedConfigurationProperty annotation
Closes gh-36482
This commit is contained in:
@@ -57,6 +57,7 @@ import org.springframework.boot.configurationprocessor.metadata.ItemMetadata;
|
||||
* @author Phillip Webb
|
||||
* @author Kris De Volder
|
||||
* @author Jonas Keßler
|
||||
* @author Scott Frederick
|
||||
* @since 1.2.0
|
||||
*/
|
||||
@SupportedAnnotationTypes({ ConfigurationMetadataAnnotationProcessor.AUTO_CONFIGURATION_ANNOTATION,
|
||||
@@ -322,16 +323,11 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
}
|
||||
|
||||
private String getPrefix(AnnotationMirror annotation) {
|
||||
Map<String, Object> elementValues = this.metadataEnv.getAnnotationElementValues(annotation);
|
||||
Object prefix = elementValues.get("prefix");
|
||||
if (prefix != null && !"".equals(prefix)) {
|
||||
return (String) prefix;
|
||||
String prefix = this.metadataEnv.getAnnotationElementStringValue(annotation, "prefix");
|
||||
if (prefix != null) {
|
||||
return prefix;
|
||||
}
|
||||
Object value = elementValues.get("value");
|
||||
if (value != null && !"".equals(value)) {
|
||||
return (String) value;
|
||||
}
|
||||
return null;
|
||||
return this.metadataEnv.getAnnotationElementStringValue(annotation, "value");
|
||||
}
|
||||
|
||||
protected ConfigurationMetadata writeMetadata() throws Exception {
|
||||
|
||||
@@ -49,6 +49,7 @@ import org.springframework.boot.configurationprocessor.metadata.ItemDeprecation;
|
||||
* Provide utilities to detect and validate configuration properties.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
class MetadataGenerationEnvironment {
|
||||
|
||||
@@ -174,14 +175,13 @@ class MetadataGenerationEnvironment {
|
||||
AnnotationMirror annotation = getAnnotation(element, this.deprecatedConfigurationPropertyAnnotation);
|
||||
String reason = null;
|
||||
String replacement = null;
|
||||
String since = null;
|
||||
if (annotation != null) {
|
||||
Map<String, Object> elementValues = getAnnotationElementValues(annotation);
|
||||
reason = (String) elementValues.get("reason");
|
||||
replacement = (String) elementValues.get("replacement");
|
||||
reason = getAnnotationElementStringValue(annotation, "reason");
|
||||
replacement = getAnnotationElementStringValue(annotation, "replacement");
|
||||
since = getAnnotationElementStringValue(annotation, "since");
|
||||
}
|
||||
reason = (reason == null || reason.isEmpty()) ? null : reason;
|
||||
replacement = (replacement == null || replacement.isEmpty()) ? null : replacement;
|
||||
return new ItemDeprecation(reason, replacement);
|
||||
return new ItemDeprecation(reason, replacement, since);
|
||||
}
|
||||
|
||||
boolean hasConstructorBindingAnnotation(ExecutableElement element) {
|
||||
@@ -279,6 +279,16 @@ class MetadataGenerationEnvironment {
|
||||
return values;
|
||||
}
|
||||
|
||||
String getAnnotationElementStringValue(AnnotationMirror annotation, String name) {
|
||||
return annotation.getElementValues()
|
||||
.entrySet()
|
||||
.stream()
|
||||
.filter((element) -> element.getKey().getSimpleName().toString().equals(name))
|
||||
.map((element) -> asString(getAnnotationValue(element.getValue())))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private Object getAnnotationValue(AnnotationValue annotationValue) {
|
||||
Object value = annotationValue.getValue();
|
||||
if (value instanceof List) {
|
||||
@@ -289,6 +299,10 @@ class MetadataGenerationEnvironment {
|
||||
return value;
|
||||
}
|
||||
|
||||
private String asString(Object value) {
|
||||
return (value == null || value.toString().isEmpty()) ? null : (String) value;
|
||||
}
|
||||
|
||||
TypeElement getConfigurationPropertiesAnnotationElement() {
|
||||
return this.elements.getTypeElement(this.configurationPropertiesAnnotation);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ class PropertyDescriptorResolver {
|
||||
private String getParameterName(VariableElement parameter) {
|
||||
AnnotationMirror nameAnnotation = this.environment.getNameAnnotation(parameter);
|
||||
if (nameAnnotation != null) {
|
||||
return (String) this.environment.getAnnotationElementValues(nameAnnotation).get("value");
|
||||
return this.environment.getAnnotationElementStringValue(nameAnnotation, "value");
|
||||
}
|
||||
return parameter.getSimpleName().toString();
|
||||
}
|
||||
|
||||
@@ -136,6 +136,9 @@ public class ConfigurationMetadata {
|
||||
if (deprecation.getLevel() != null) {
|
||||
matchingDeprecation.setLevel(deprecation.getLevel());
|
||||
}
|
||||
if (deprecation.getSince() != null) {
|
||||
matchingDeprecation.setSince(deprecation.getSince());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package org.springframework.boot.configurationprocessor.metadata;
|
||||
* Describe an item deprecation.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Scott Frederick
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public class ItemDeprecation {
|
||||
@@ -28,19 +29,22 @@ public class ItemDeprecation {
|
||||
|
||||
private String replacement;
|
||||
|
||||
private String since;
|
||||
|
||||
private String level;
|
||||
|
||||
public ItemDeprecation() {
|
||||
this(null, null);
|
||||
this(null, null, null);
|
||||
}
|
||||
|
||||
public ItemDeprecation(String reason, String replacement) {
|
||||
this(reason, replacement, null);
|
||||
public ItemDeprecation(String reason, String replacement, String since) {
|
||||
this(reason, replacement, since, null);
|
||||
}
|
||||
|
||||
public ItemDeprecation(String reason, String replacement, String level) {
|
||||
public ItemDeprecation(String reason, String replacement, String since, String level) {
|
||||
this.reason = reason;
|
||||
this.replacement = replacement;
|
||||
this.since = since;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
@@ -60,6 +64,14 @@ public class ItemDeprecation {
|
||||
this.replacement = replacement;
|
||||
}
|
||||
|
||||
public String getSince() {
|
||||
return this.since;
|
||||
}
|
||||
|
||||
public void setSince(String since) {
|
||||
this.since = since;
|
||||
}
|
||||
|
||||
public String getLevel() {
|
||||
return this.level;
|
||||
}
|
||||
@@ -78,7 +90,7 @@ public class ItemDeprecation {
|
||||
}
|
||||
ItemDeprecation other = (ItemDeprecation) o;
|
||||
return nullSafeEquals(this.reason, other.reason) && nullSafeEquals(this.replacement, other.replacement)
|
||||
&& nullSafeEquals(this.level, other.level);
|
||||
&& nullSafeEquals(this.level, other.level) && nullSafeEquals(this.since, other.since);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,13 +98,14 @@ public class ItemDeprecation {
|
||||
int result = nullSafeHashCode(this.reason);
|
||||
result = 31 * result + nullSafeHashCode(this.replacement);
|
||||
result = 31 * result + nullSafeHashCode(this.level);
|
||||
result = 31 * result + nullSafeHashCode(this.since);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ItemDeprecation{reason='" + this.reason + '\'' + ", replacement='" + this.replacement + '\''
|
||||
+ ", level='" + this.level + '\'' + '}';
|
||||
+ ", level='" + this.level + '\'' + ", since='" + this.since + '\'' + '}';
|
||||
}
|
||||
|
||||
private boolean nullSafeEquals(Object o1, Object o2) {
|
||||
|
||||
@@ -83,6 +83,9 @@ class JsonConverter {
|
||||
if (deprecation.getReplacement() != null) {
|
||||
deprecationJsonObject.put("replacement", deprecation.getReplacement());
|
||||
}
|
||||
if (deprecation.getSince() != null) {
|
||||
deprecationJsonObject.put("since", deprecation.getSince());
|
||||
}
|
||||
jsonObject.put("deprecation", deprecationJsonObject);
|
||||
}
|
||||
return jsonObject;
|
||||
|
||||
@@ -105,6 +105,7 @@ public class JsonMarshaller {
|
||||
deprecation.setLevel(deprecationJsonObject.optString("level", null));
|
||||
deprecation.setReason(deprecationJsonObject.optString("reason", null));
|
||||
deprecation.setReplacement(deprecationJsonObject.optString("replacement", null));
|
||||
deprecation.setSince(deprecationJsonObject.optString("since", null));
|
||||
return deprecation;
|
||||
}
|
||||
return object.optBoolean("deprecated") ? new ItemDeprecation() : null;
|
||||
|
||||
Reference in New Issue
Block a user