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
3c8a9745
Commit
3c8a9745
authored
Feb 10, 2021
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.3.x' into 2.4.x
Closes gh-25176
parents
9da3b65f
b6d2da0f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
16 deletions
+56
-16
build.gradle
buildSrc/build.gradle
+1
-1
ConfigurationProperties.java
...oot/build/context/properties/ConfigurationProperties.java
+5
-15
ConfigurationPropertiesTests.java
...uild/context/properties/ConfigurationPropertiesTests.java
+41
-0
spring-configuration-metadata.json
...Src/src/test/resources/spring-configuration-metadata.json
+9
-0
No files found.
buildSrc/build.gradle
View file @
3c8a9745
...
@@ -23,7 +23,7 @@ dependencies {
...
@@ -23,7 +23,7 @@ dependencies {
implementation
(
"org.gradle:test-retry-gradle-plugin:1.1.9"
)
implementation
(
"org.gradle:test-retry-gradle-plugin:1.1.9"
)
implementation
(
"org.springframework:spring-core:5.2.2.RELEASE"
)
implementation
(
"org.springframework:spring-core:5.2.2.RELEASE"
)
implementation
(
"org.springframework:spring-web:5.2.2.RELEASE"
)
implementation
(
"org.springframework:spring-web:5.2.2.RELEASE"
)
implementation
(
"com.
google.code.gson:gson:2.8.5
"
)
implementation
(
"com.
fasterxml.jackson.core:jackson-databind:2.11.4
"
)
implementation
(
"io.spring.javaformat:spring-javaformat-gradle-plugin:${javaFormatVersion}"
)
implementation
(
"io.spring.javaformat:spring-javaformat-gradle-plugin:${javaFormatVersion}"
)
testImplementation
(
"org.assertj:assertj-core:3.11.1"
)
testImplementation
(
"org.assertj:assertj-core:3.11.1"
)
testImplementation
(
"org.apache.logging.log4j:log4j-core:2.12.1"
)
testImplementation
(
"org.apache.logging.log4j:log4j-core:2.12.1"
)
...
...
buildSrc/src/main/java/org/springframework/boot/build/context/properties/ConfigurationProperties.java
View file @
3c8a9745
/*
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -20,17 +20,13 @@ import java.io.File;
...
@@ -20,17 +20,13 @@ import java.io.File;
import
java.io.FileReader
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.Reader
;
import
java.io.Reader
;
import
java.lang.reflect.Type
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.function.Function
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
com.google.gson.Gson
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.google.gson.GsonBuilder
;
import
com.google.gson.reflect.TypeToken
;
import
org.gradle.api.file.FileCollection
;
/**
/**
* Configuration properties read from one or more
* Configuration properties read from one or more
...
@@ -40,20 +36,18 @@ import org.gradle.api.file.FileCollection;
...
@@ -40,20 +36,18 @@ import org.gradle.api.file.FileCollection;
*/
*/
final
class
ConfigurationProperties
{
final
class
ConfigurationProperties
{
private
static
final
Type
MAP_TYPE
=
new
MapTypeToken
().
getType
();
private
ConfigurationProperties
()
{
private
ConfigurationProperties
()
{
}
}
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
static
Map
<
String
,
ConfigurationProperty
>
fromFiles
(
FileCollection
files
)
{
static
Map
<
String
,
ConfigurationProperty
>
fromFiles
(
Iterable
<
File
>
files
)
{
List
<
ConfigurationProperty
>
configurationProperties
=
new
ArrayList
<>();
List
<
ConfigurationProperty
>
configurationProperties
=
new
ArrayList
<>();
try
{
try
{
Gson
gson
=
new
GsonBuilder
().
create
();
ObjectMapper
objectMapper
=
new
ObjectMapper
();
for
(
File
file
:
files
)
{
for
(
File
file
:
files
)
{
try
(
Reader
reader
=
new
FileReader
(
file
))
{
try
(
Reader
reader
=
new
FileReader
(
file
))
{
Map
<
String
,
Object
>
json
=
gson
.
fromJson
(
reader
,
MAP_TYPE
);
Map
<
String
,
Object
>
json
=
objectMapper
.
readValue
(
file
,
Map
.
class
);
List
<
Map
<
String
,
Object
>>
properties
=
(
List
<
Map
<
String
,
Object
>>)
json
.
get
(
"properties"
);
List
<
Map
<
String
,
Object
>>
properties
=
(
List
<
Map
<
String
,
Object
>>)
json
.
get
(
"properties"
);
for
(
Map
<
String
,
Object
>
property
:
properties
)
{
for
(
Map
<
String
,
Object
>
property
:
properties
)
{
String
name
=
(
String
)
property
.
get
(
"name"
);
String
name
=
(
String
)
property
.
get
(
"name"
);
...
@@ -74,8 +68,4 @@ final class ConfigurationProperties {
...
@@ -74,8 +68,4 @@ final class ConfigurationProperties {
}
}
}
}
private
static
final
class
MapTypeToken
extends
TypeToken
<
Map
<
String
,
Object
>>
{
}
}
}
buildSrc/src/test/java/org/springframework/boot/build/context/properties/ConfigurationPropertiesTests.java
0 → 100644
View file @
3c8a9745
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
build
.
context
.
properties
;
import
java.io.File
;
import
java.util.Arrays
;
import
java.util.Map
;
import
org.junit.jupiter.api.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ConfigurationProperties}
*
* @author Andy Wilkinson
*/
class
ConfigurationPropertiesTests
{
@Test
void
whenJsonHasAnIntegerDefaultValueThenItRemainsAnIntegerWhenRead
()
{
Map
<
String
,
ConfigurationProperty
>
properties
=
ConfigurationProperties
.
fromFiles
(
Arrays
.
asList
(
new
File
(
"src/test/resources/spring-configuration-metadata.json"
)));
assertThat
(
properties
.
get
(
"example.counter"
).
getDefaultValue
()).
isEqualTo
(
0
);
}
}
buildSrc/src/test/resources/spring-configuration-metadata.json
0 → 100644
View file @
3c8a9745
{
"properties"
:
[
{
"name"
:
"example.counter"
,
"type"
:
"java.lang.Integer"
,
"defaultValue"
:
0
}
]
}
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