Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
bdd532cc
Commit
bdd532cc
authored
Jan 29, 2018
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clarify when a property was not renamed due to an incompatible type
Closes gh-11794
parent
43e5e83d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
4 deletions
+39
-4
PropertiesMigrationReport.java
...ontext/properties/migrator/PropertiesMigrationReport.java
+14
-4
PropertiesMigrationReporterTests.java
...properties/migrator/PropertiesMigrationReporterTests.java
+12
-0
config-error-no-compatible-type.properties
...sources/config/config-error-no-compatible-type.properties
+1
-0
type-conversion-metadata.json
...src/test/resources/metadata/type-conversion-metadata.json
+12
-0
No files found.
spring-boot-project/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReport.java
View file @
bdd532cc
...
...
@@ -25,6 +25,7 @@ import java.util.function.Function;
import
java.util.stream.Collectors
;
import
org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty
;
import
org.springframework.boot.configurationmetadata.Deprecation
;
import
org.springframework.util.StringUtils
;
/**
...
...
@@ -74,10 +75,7 @@ class PropertiesMigrationReport {
StringBuilder
report
=
new
StringBuilder
();
report
.
append
(
String
.
format
(
"%nThe use of configuration keys that are no longer "
+
"supported was found in the environment:%n%n"
));
append
(
report
,
content
,
(
metadata
)
->
"Reason: "
+
(
StringUtils
.
hasText
(
metadata
.
getDeprecation
().
getShortReason
())
?
metadata
.
getDeprecation
().
getShortReason
()
:
"none"
));
append
(
report
,
content
,
this
::
determineReason
);
report
.
append
(
String
.
format
(
"%n"
));
report
.
append
(
"Please refer to the migration guide or reference guide for "
+
"potential alternatives."
);
...
...
@@ -85,6 +83,18 @@ class PropertiesMigrationReport {
return
report
.
toString
();
}
private
String
determineReason
(
ConfigurationMetadataProperty
metadata
)
{
Deprecation
deprecation
=
metadata
.
getDeprecation
();
if
(
StringUtils
.
hasText
(
deprecation
.
getShortReason
()))
{
return
deprecation
.
getShortReason
();
}
if
(
StringUtils
.
hasText
(
deprecation
.
getReplacement
()))
{
return
String
.
format
(
"Reason: Replacement key '%s' uses an incompatible "
+
"target type"
,
deprecation
.
getReplacement
());
}
return
"none"
;
}
private
Map
<
String
,
List
<
PropertyMigration
>>
getContent
(
Function
<
LegacyProperties
,
List
<
PropertyMigration
>>
extractor
)
{
return
this
.
content
.
entrySet
().
stream
()
...
...
spring-boot-project/spring-boot-properties-migrator/src/test/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReporterTests.java
View file @
bdd532cc
...
...
@@ -141,6 +141,18 @@ public class PropertiesMigrationReporterTests {
assertMappedProperty
(
propertySource
,
"test.mapped.ttl"
,
5678L
,
null
);
}
@Test
public
void
reasonIsProvidedIfPropertyCouldNotBeRenamed
()
throws
IOException
{
this
.
environment
.
getPropertySources
().
addFirst
(
loadPropertySource
(
"test"
,
"config/config-error-no-compatible-type.properties"
));
String
report
=
createErrorReport
(
loadRepository
(
"metadata/type-conversion-metadata.json"
));
assertThat
(
report
).
isNotNull
();
assertThat
(
report
).
containsSubsequence
(
"Property source 'test'"
,
"wrong.inconvertible"
,
"Line: 1"
,
"Reason: Replacement key "
+
"'test.inconvertible' uses an incompatible target type"
);
}
private
List
<
String
>
mapToNames
(
PropertySources
sources
)
{
List
<
String
>
names
=
new
ArrayList
<>();
for
(
PropertySource
<?>
source
:
sources
)
{
...
...
spring-boot-project/spring-boot-properties-migrator/src/test/resources/config/config-error-no-compatible-type.properties
0 → 100644
View file @
bdd532cc
wrong.inconvertible
=
abc
spring-boot-project/spring-boot-properties-migrator/src/test/resources/metadata/type-conversion-metadata.json
View file @
bdd532cc
...
...
@@ -12,6 +12,10 @@
"name"
:
"test.mapped"
,
"type"
:
"java.util.Map<java.lang.String, java.time.Duration>"
},
{
"name"
:
"test.inconvertible"
,
"type"
:
"com.example.One"
},
{
"name"
:
"test.cache-seconds"
,
"type"
:
"java.lang.Integer"
,
...
...
@@ -35,6 +39,14 @@
"replacement"
:
"test.mapped.ttl"
,
"level"
:
"error"
}
},
{
"name"
:
"wrong.inconvertible"
,
"type"
:
"com.example.Two"
,
"deprecation"
:
{
"replacement"
:
"test.inconvertible"
,
"level"
:
"error"
}
}
]
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment