diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java index f703f9e5b2..4d65e633fb 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java @@ -124,6 +124,9 @@ public class ConfigurationMetadata { if (deprecation.getReplacement() != null) { matchingDeprecation.setReplacement(deprecation.getReplacement()); } + if (deprecation.getLevel() != null) { + matchingDeprecation.setLevel(deprecation.getLevel()); + } } } } diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ItemDeprecation.java b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ItemDeprecation.java index 5762cd3bf2..99038aef90 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ItemDeprecation.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ItemDeprecation.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,12 +28,20 @@ public class ItemDeprecation { private String replacement; + private String level; + public ItemDeprecation() { + this(null, null); } public ItemDeprecation(String reason, String replacement) { + this(reason, replacement, null); + } + + public ItemDeprecation(String reason, String replacement, String level) { this.reason = reason; this.replacement = replacement; + this.level = level; } public String getReason() { @@ -52,10 +60,19 @@ public class ItemDeprecation { this.replacement = replacement; } + public String getLevel() { + return this.level; + } + + public void setLevel(String level) { + this.level = level; + } + @Override public String toString() { return "ItemDeprecation{" + "reason='" + this.reason + '\'' + ", " - + "replacement='" + this.replacement + '\'' + '}'; + + "replacement='" + this.replacement + '\'' + ", " + + "level='" + this.level + '\'' + '}'; } @Override @@ -68,13 +85,15 @@ public class ItemDeprecation { } ItemDeprecation other = (ItemDeprecation) o; return nullSafeEquals(this.reason, other.reason) - && nullSafeEquals(this.replacement, other.replacement); + && nullSafeEquals(this.replacement, other.replacement) + && nullSafeEquals(this.level, other.level); } @Override public int hashCode() { int result = nullSafeHashCode(this.reason); result = 31 * result + nullSafeHashCode(this.replacement); + result = 31 * result + nullSafeHashCode(this.level); return result; } diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/JsonConverter.java b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/JsonConverter.java index 130bad2a75..fcfeee74ac 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/JsonConverter.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/JsonConverter.java @@ -67,6 +67,9 @@ class JsonConverter { if (deprecation != null) { jsonObject.put("deprecated", true); // backward compatibility JSONObject deprecationJsonObject = new JSONObject(); + if (deprecation.getLevel() != null) { + deprecationJsonObject.put("level", deprecation.getLevel()); + } if (deprecation.getReason() != null) { deprecationJsonObject.put("reason", deprecation.getReason()); } diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/JsonMarshaller.java b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/JsonMarshaller.java index 0c6d65b2b8..9cc77ee9cd 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/JsonMarshaller.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/JsonMarshaller.java @@ -108,6 +108,7 @@ public class JsonMarshaller { if (object.has("deprecation")) { JSONObject deprecationJsonObject = object.getJSONObject("deprecation"); ItemDeprecation deprecation = new ItemDeprecation(); + deprecation.setLevel(deprecationJsonObject.optString("level", null)); deprecation.setReason(deprecationJsonObject.optString("reason", null)); deprecation .setReplacement(deprecationJsonObject.optString("replacement", null)); diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java index 7c36f3995d..119eb80ec4 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java @@ -542,13 +542,15 @@ public class ConfigurationMetadataAnnotationProcessorTests { public void mergeExistingPropertyDeprecation() throws Exception { ItemMetadata property = ItemMetadata.newProperty("simple", "comparator", null, null, null, null, null, - new ItemDeprecation("Don't use this.", "simple.complex-comparator")); + new ItemDeprecation("Don't use this.", "simple.complex-comparator", + "error")); writeAdditionalMetadata(property); ConfigurationMetadata metadata = compile(SimpleProperties.class); assertThat(metadata) .has(Metadata.withProperty("simple.comparator", "java.util.Comparator") .fromSource(SimpleProperties.class) - .withDeprecation("Don't use this.", "simple.complex-comparator")); + .withDeprecation("Don't use this.", "simple.complex-comparator", + "error")); assertThat(metadata.getItems()).hasSize(4); } @@ -566,6 +568,19 @@ public class ConfigurationMetadataAnnotationProcessorTests { assertThat(metadata.getItems()).hasSize(3); } + @Test + public void mergeExistingPropertyDeprecationOverrideLevel() throws Exception { + ItemMetadata property = ItemMetadata.newProperty("singledeprecated", "name", null, + null, null, null, null, new ItemDeprecation(null, null, "error")); + writeAdditionalMetadata(property); + ConfigurationMetadata metadata = compile(DeprecatedSingleProperty.class); + assertThat(metadata).has( + Metadata.withProperty("singledeprecated.name", String.class.getName()) + .fromSource(DeprecatedSingleProperty.class) + .withDeprecation("renamed", "singledeprecated.new-name", "error")); + assertThat(metadata.getItems()).hasSize(3); + } + @Test public void mergeOfInvalidAdditionalMetadata() throws IOException { File additionalMetadataFile = createAdditionalMetadataFile(); diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/Metadata.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/Metadata.java index 5d40fc9cef..81f1082b72 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/Metadata.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/Metadata.java @@ -202,9 +202,14 @@ public final class Metadata { } public MetadataItemCondition withDeprecation(String reason, String replacement) { + return withDeprecation(reason, replacement, null); + } + + public MetadataItemCondition withDeprecation(String reason, String replacement, + String level) { return new MetadataItemCondition(this.itemType, this.name, this.type, this.sourceType, this.sourceMethod, this.description, - this.defaultValue, new ItemDeprecation(reason, replacement)); + this.defaultValue, new ItemDeprecation(reason, replacement, level)); } public MetadataItemCondition withNoDeprecation() {