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
d610f3c2
Commit
d610f3c2
authored
Apr 28, 2021
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Fix ordering of metadata entries"
See gh-26230
parent
3e34b0a6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
9 deletions
+38
-9
JsonConverter.java
...k/boot/configurationprocessor/metadata/JsonConverter.java
+9
-8
JsonMarshallerTests.java
.../configurationprocessor/metadata/JsonMarshallerTests.java
+29
-1
No files found.
spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/JsonConverter.java
View file @
d610f3c2
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
21
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.
...
...
@@ -160,21 +160,22 @@ class JsonConverter {
private
static
class
ItemMetadataComparator
implements
Comparator
<
ItemMetadata
>
{
private
final
Comparator
<
ItemMetadata
>
itemComparator
=
Comparator
.
comparing
(
this
::
isDeprecated
)
.
thenComparing
(
ItemMetadata:
:
get
Name
).
thenComparing
(
ItemMetadata:
:
getSourceType
);
private
static
final
Comparator
<
ItemMetadata
>
GROUP
=
Comparator
.
comparing
(
ItemMetadata:
:
getName
)
.
thenComparing
(
ItemMetadata:
:
get
SourceType
,
Comparator
.
nullsFirst
(
Comparator
.
naturalOrder
())
);
private
final
Comparator
<
ItemMetadata
>
groupComparator
=
Comparator
.
comparing
(
ItemMetadata:
:
getName
)
.
thenComparing
(
ItemMetadata:
:
getSourceType
);
private
static
final
Comparator
<
ItemMetadata
>
ITEM
=
Comparator
.
comparing
(
ItemMetadataComparator:
:
isDeprecated
)
.
thenComparing
(
ItemMetadata:
:
getName
)
.
thenComparing
(
ItemMetadata:
:
getSourceType
,
Comparator
.
nullsFirst
(
Comparator
.
naturalOrder
()));
@Override
public
int
compare
(
ItemMetadata
o1
,
ItemMetadata
o2
)
{
if
(
o1
.
isOfItemType
(
ItemType
.
GROUP
))
{
return
this
.
groupComparator
.
compare
(
o1
,
o2
);
return
GROUP
.
compare
(
o1
,
o2
);
}
return
this
.
itemComparator
.
compare
(
o1
,
o2
);
return
ITEM
.
compare
(
o1
,
o2
);
}
private
boolean
isDeprecated
(
ItemMetadata
item
)
{
private
static
boolean
isDeprecated
(
ItemMetadata
item
)
{
return
item
.
getDeprecation
()
!=
null
;
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/JsonMarshallerTests.java
View file @
d610f3c2
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
21
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.
...
...
@@ -139,4 +139,32 @@ class JsonMarshallerTests {
"com.example.Bar"
,
"\"com.example.bravo.aaa\""
,
"com.example.Foo"
);
}
@Test
void
orderingForSameGroupWithNullSourceType
()
throws
IOException
{
ConfigurationMetadata
metadata
=
new
ConfigurationMetadata
();
metadata
.
add
(
ItemMetadata
.
newGroup
(
"com.acme.alpha"
,
null
,
"com.example.Foo"
,
null
));
metadata
.
add
(
ItemMetadata
.
newGroup
(
"com.acme.alpha"
,
null
,
null
,
null
));
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
JsonMarshaller
marshaller
=
new
JsonMarshaller
();
marshaller
.
write
(
metadata
,
outputStream
);
String
json
=
outputStream
.
toString
();
assertThat
(
json
).
containsSubsequence
(
"\"groups\""
,
"\"name\": \"com.acme.alpha\""
,
"\"name\": \"com.acme.alpha\""
,
"\"sourceType\": \"com.example.Foo\""
);
}
@Test
void
orderingForSamePropertyNamesWithNullSourceType
()
throws
IOException
{
ConfigurationMetadata
metadata
=
new
ConfigurationMetadata
();
metadata
.
add
(
ItemMetadata
.
newProperty
(
"com.example.bravo"
,
"aaa"
,
"java.lang.Boolean"
,
null
,
null
,
null
,
null
,
null
));
metadata
.
add
(
ItemMetadata
.
newProperty
(
"com.example.bravo"
,
"aaa"
,
"java.lang.Integer"
,
"com.example.Bar"
,
null
,
null
,
null
,
null
));
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
JsonMarshaller
marshaller
=
new
JsonMarshaller
();
marshaller
.
write
(
metadata
,
outputStream
);
String
json
=
outputStream
.
toString
();
assertThat
(
json
).
containsSubsequence
(
"\"groups\""
,
"\"properties\""
,
"\"com.example.bravo.aaa\""
,
"\"java.lang.Boolean\""
,
"\"com.example.bravo.aaa\""
,
"\"java.lang.Integer\""
,
"\"com.example.Bar"
);
}
}
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