Skip to content

Commit

Permalink
Fix handling of error level deprecations that were not a warning prev…
Browse files Browse the repository at this point in the history
…iously
  • Loading branch information
wilkinsona committed Mar 25, 2024
1 parent 4e62aae commit 64af1e3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 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.
Expand Down Expand Up @@ -34,17 +34,16 @@ record Difference(DifferenceType type, ConfigurationMetadataProperty oldProperty

static Difference compute(ConfigurationMetadataProperty oldProperty, ConfigurationMetadataProperty newProperty) {
if (newProperty == null) {
if (!(oldProperty.isDeprecated() && oldProperty.getDeprecation().getLevel() == Level.ERROR)) {
return new Difference(DifferenceType.DELETED, oldProperty, null);
}
return null;
}
if (newProperty.isDeprecated() && !oldProperty.isDeprecated()) {
return new Difference(DifferenceType.DEPRECATED, oldProperty, newProperty);
Level oldLevel = (oldProperty.getDeprecation() != null) ? oldProperty.getDeprecation().getLevel() : null;
return (oldLevel != Level.ERROR) ? new Difference(DifferenceType.DELETED, oldProperty, null) : null;
}
if (oldProperty.isDeprecated() && oldProperty.getDeprecation().getLevel() == Level.WARNING
&& newProperty.isDeprecated() && newProperty.getDeprecation().getLevel() == Level.ERROR) {
return new Difference(DifferenceType.DELETED, oldProperty, newProperty);
if (newProperty.isDeprecated()) {
Level newLevel = newProperty.getDeprecation().getLevel();
Level oldLevel = (oldProperty.getDeprecation() != null) ? oldProperty.getDeprecation().getLevel() : null;
if (newLevel != oldLevel) {
return new Difference((newLevel == Level.ERROR) ? DifferenceType.DELETED : DifferenceType.DEPRECATED,
oldProperty, newProperty);
}
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 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.
Expand Down Expand Up @@ -38,7 +38,7 @@ void diffContainsDifferencesBetweenLeftAndRightInputs() {
assertThat(differences).isNotNull();
assertThat(differences.oldVersionNumber()).isEqualTo("1.0");
assertThat(differences.newVersionNumber()).isEqualTo("2.0");
assertThat(differences.differences()).hasSize(4);
assertThat(differences.differences()).hasSize(5);
List<Difference> added = differences.differences()
.stream()
.filter((difference) -> difference.type() == DifferenceType.ADDED)
Expand All @@ -49,7 +49,7 @@ void diffContainsDifferencesBetweenLeftAndRightInputs() {
.stream()
.filter((difference) -> difference.type() == DifferenceType.DELETED)
.toList();
assertThat(deleted).hasSize(2)
assertThat(deleted).hasSize(3)
.anySatisfy((entry) -> assertProperty(entry.oldProperty(), "test.delete", String.class, "delete"))
.anySatisfy(
(entry) -> assertProperty(entry.newProperty(), "test.delete.deprecated", String.class, "delete"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
"deprecation": {
"level": "warning"
}
},
{
"name": "test.deprecate.straight-to-error",
"type": "java.lang.String",
"description": "Test deprecate straight to error.",
"defaultValue": "delete"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"description": "Test deprecate.",
"defaultValue": "wrong",
"deprecation": {
"level": "error"
"level": "warning"
}
},
{
Expand All @@ -31,6 +31,16 @@
"replacement": "test.add",
"reason": "it was just bad"
}
},
{
"name": "test.deprecate.straight-to-error",
"type": "java.lang.String",
"description": "Test deprecate straight to error.",
"defaultValue": "delete",
"deprecation": {
"level": "error",
"reason": "removed from third-party code"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ Configuration property changes between `1.0` and `2.0`

== Deprecated in 2.0

_None_.
|======================
| Key | Replacement | Reason

| `test.deprecate`
|
|
|======================



Expand Down Expand Up @@ -32,4 +38,8 @@ _None_.
| `test.delete.deprecated`
| `test.add`
| it was just bad

| `test.deprecate.straight-to-error`
|
| removed from third-party code
|======================

0 comments on commit 64af1e3

Please sign in to comment.