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
f9c74d98
Commit
f9c74d98
authored
Apr 15, 2019
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.1.x'
Closes gh-16565
parents
84df37fd
e99deb95
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
105 additions
and
23 deletions
+105
-23
ConfigurationMetadataRepositoryJsonBuilder.java
...nmetadata/ConfigurationMetadataRepositoryJsonBuilder.java
+2
-10
RawConfigurationMetadata.java
.../boot/configurationmetadata/RawConfigurationMetadata.java
+12
-11
ConfigurationMetadataRepositoryJsonBuilderTests.java
...data/ConfigurationMetadataRepositoryJsonBuilderTests.java
+26
-1
JsonReaderTests.java
...framework/boot/configurationmetadata/JsonReaderTests.java
+20
-1
configuration-metadata-multi-groups.json
...sources/metadata/configuration-metadata-multi-groups.json
+45
-0
No files found.
spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/ConfigurationMetadataRepositoryJsonBuilder.java
View file @
f9c74d98
/*
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
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.
...
@@ -108,7 +108,7 @@ public final class ConfigurationMetadataRepositoryJsonBuilder {
...
@@ -108,7 +108,7 @@ public final class ConfigurationMetadataRepositoryJsonBuilder {
SimpleConfigurationMetadataRepository
repository
=
new
SimpleConfigurationMetadataRepository
();
SimpleConfigurationMetadataRepository
repository
=
new
SimpleConfigurationMetadataRepository
();
repository
.
add
(
metadata
.
getSources
());
repository
.
add
(
metadata
.
getSources
());
for
(
ConfigurationMetadataItem
item
:
metadata
.
getItems
())
{
for
(
ConfigurationMetadataItem
item
:
metadata
.
getItems
())
{
ConfigurationMetadataSource
source
=
getSource
(
metadata
,
item
);
ConfigurationMetadataSource
source
=
metadata
.
getSource
(
item
);
repository
.
add
(
item
,
source
);
repository
.
add
(
item
,
source
);
}
}
Map
<
String
,
ConfigurationMetadataProperty
>
allProperties
=
repository
Map
<
String
,
ConfigurationMetadataProperty
>
allProperties
=
repository
...
@@ -146,14 +146,6 @@ public final class ConfigurationMetadataRepositoryJsonBuilder {
...
@@ -146,14 +146,6 @@ public final class ConfigurationMetadataRepositoryJsonBuilder {
property
.
getHints
().
getKeyProviders
().
addAll
(
hint
.
getValueProviders
());
property
.
getHints
().
getKeyProviders
().
addAll
(
hint
.
getValueProviders
());
}
}
private
ConfigurationMetadataSource
getSource
(
RawConfigurationMetadata
metadata
,
ConfigurationMetadataItem
item
)
{
if
(
item
.
getSourceType
()
!=
null
)
{
return
metadata
.
getSource
(
item
.
getSourceType
());
}
return
null
;
}
/**
/**
* Create a new builder instance using {@link StandardCharsets#UTF_8} as the default
* Create a new builder instance using {@link StandardCharsets#UTF_8} as the default
* charset and the specified json resource.
* charset and the specified json resource.
...
...
spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/RawConfigurationMetadata.java
View file @
f9c74d98
/*
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
9
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.
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
package
org
.
springframework
.
boot
.
configurationmetadata
;
package
org
.
springframework
.
boot
.
configurationmetadata
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -48,13 +49,16 @@ class RawConfigurationMetadata {
...
@@ -48,13 +49,16 @@ class RawConfigurationMetadata {
return
this
.
sources
;
return
this
.
sources
;
}
}
public
ConfigurationMetadataSource
getSource
(
String
type
)
{
public
ConfigurationMetadataSource
getSource
(
ConfigurationMetadataItem
item
)
{
for
(
ConfigurationMetadataSource
source
:
this
.
sources
)
{
if
(
item
.
getSourceType
()
==
null
)
{
if
(
type
.
equals
(
source
.
getType
()))
{
return
null
;
return
source
;
}
}
}
return
null
;
return
this
.
sources
.
stream
()
.
filter
((
candidate
)
->
item
.
getSourceType
().
equals
(
candidate
.
getType
())
&&
item
.
getId
().
startsWith
(
candidate
.
getGroupId
()))
.
max
(
Comparator
.
comparingInt
((
candidate
)
->
candidate
.
getGroupId
().
length
()))
.
orElse
(
null
);
}
}
public
List
<
ConfigurationMetadataItem
>
getItems
()
{
public
List
<
ConfigurationMetadataItem
>
getItems
()
{
...
@@ -72,10 +76,7 @@ class RawConfigurationMetadata {
...
@@ -72,10 +76,7 @@ class RawConfigurationMetadata {
*/
*/
private
void
resolveName
(
ConfigurationMetadataItem
item
)
{
private
void
resolveName
(
ConfigurationMetadataItem
item
)
{
item
.
setName
(
item
.
getId
());
// fallback
item
.
setName
(
item
.
getId
());
// fallback
if
(
item
.
getSourceType
()
==
null
)
{
ConfigurationMetadataSource
source
=
getSource
(
item
);
return
;
}
ConfigurationMetadataSource
source
=
getSource
(
item
.
getSourceType
());
if
(
source
!=
null
)
{
if
(
source
!=
null
)
{
String
groupId
=
source
.
getGroupId
();
String
groupId
=
source
.
getGroupId
();
String
dottedPrefix
=
groupId
+
"."
;
String
dottedPrefix
=
groupId
+
"."
;
...
...
spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/ConfigurationMetadataRepositoryJsonBuilderTests.java
View file @
f9c74d98
/*
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
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.
...
@@ -129,6 +129,31 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
...
@@ -129,6 +129,31 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
}
}
}
}
@Test
public
void
multiGroups
()
throws
IOException
{
try
(
InputStream
in
=
getInputStreamFor
(
"multi-groups"
))
{
ConfigurationMetadataRepository
repo
=
ConfigurationMetadataRepositoryJsonBuilder
.
create
(
in
).
build
();
assertThat
(
repo
.
getAllGroups
()).
containsOnlyKeys
(
"test.group.one.retry"
,
"test.group.two.retry"
,
"test.group.one.retry.specific"
);
ConfigurationMetadataGroup
one
=
repo
.
getAllGroups
()
.
get
(
"test.group.one.retry"
);
assertThat
(
one
.
getSources
()).
containsOnlyKeys
(
"com.example.Retry"
);
assertThat
(
one
.
getProperties
())
.
containsOnlyKeys
(
"test.group.one.retry.enabled"
);
ConfigurationMetadataGroup
two
=
repo
.
getAllGroups
()
.
get
(
"test.group.two.retry"
);
assertThat
(
two
.
getSources
()).
containsOnlyKeys
(
"com.example.Retry"
);
assertThat
(
two
.
getProperties
())
.
containsOnlyKeys
(
"test.group.two.retry.enabled"
);
ConfigurationMetadataGroup
oneSpecific
=
repo
.
getAllGroups
()
.
get
(
"test.group.one.retry.specific"
);
assertThat
(
oneSpecific
.
getSources
()).
containsOnlyKeys
(
"com.example.Retry"
);
assertThat
(
oneSpecific
.
getProperties
())
.
containsOnlyKeys
(
"test.group.one.retry.specific.enabled"
);
}
}
@Test
@Test
public
void
builderInstancesAreIsolated
()
throws
IOException
{
public
void
builderInstancesAreIsolated
()
throws
IOException
{
try
(
InputStream
foo
=
getInputStreamFor
(
"foo"
);
try
(
InputStream
foo
=
getInputStreamFor
(
"foo"
);
...
...
spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/JsonReaderTests.java
View file @
f9c74d98
/*
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
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.
...
@@ -199,6 +199,25 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests {
...
@@ -199,6 +199,25 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests {
.
isEqualTo
(
Deprecation
.
Level
.
WARNING
);
.
isEqualTo
(
Deprecation
.
Level
.
WARNING
);
}
}
@Test
public
void
multiGroupsMetadata
()
throws
IOException
{
RawConfigurationMetadata
rawMetadata
=
readFor
(
"multi-groups"
);
List
<
ConfigurationMetadataItem
>
items
=
rawMetadata
.
getItems
();
assertThat
(
items
).
hasSize
(
3
);
ConfigurationMetadataItem
item
=
items
.
get
(
0
);
assertThat
(
item
.
getName
()).
isEqualTo
(
"enabled"
);
assertThat
(
item
.
getSourceType
()).
isEqualTo
(
"com.example.Retry"
);
ConfigurationMetadataItem
item2
=
items
.
get
(
1
);
assertThat
(
item2
.
getName
()).
isEqualTo
(
"enabled"
);
assertThat
(
item2
.
getSourceType
()).
isEqualTo
(
"com.example.Retry"
);
ConfigurationMetadataItem
item3
=
items
.
get
(
2
);
assertThat
(
item3
.
getName
()).
isEqualTo
(
"enabled"
);
assertThat
(
item3
.
getSourceType
()).
isEqualTo
(
"com.example.Retry"
);
}
RawConfigurationMetadata
readFor
(
String
path
)
throws
IOException
{
RawConfigurationMetadata
readFor
(
String
path
)
throws
IOException
{
return
this
.
reader
.
read
(
getInputStreamFor
(
path
),
DEFAULT_CHARSET
);
return
this
.
reader
.
read
(
getInputStreamFor
(
path
),
DEFAULT_CHARSET
);
}
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/src/test/resources/metadata/configuration-metadata-multi-groups.json
0 → 100644
View file @
f9c74d98
{
"groups"
:
[
{
"name"
:
"test.group.one.retry"
,
"type"
:
"com.example.Retry"
,
"sourceType"
:
"org.acme.config.TestApp"
,
"sourceMethod"
:
"one()"
},
{
"name"
:
"test.group.two.retry"
,
"type"
:
"com.example.Retry"
,
"sourceType"
:
"org.acme.config.TestApp"
,
"sourceMethod"
:
"two()"
},
{
"name"
:
"test.group.one.retry.specific"
,
"type"
:
"com.example.Retry"
,
"sourceType"
:
"org.acme.config.TestApp"
,
"sourceMethod"
:
"two()"
}
],
"properties"
:
[
{
"name"
:
"test.group.one.retry.enabled"
,
"type"
:
"java.lang.Boolean"
,
"description"
:
"Whether publishing retries are enabled."
,
"sourceType"
:
"com.example.Retry"
,
"defaultValue"
:
false
},
{
"name"
:
"test.group.two.retry.enabled"
,
"type"
:
"java.lang.Boolean"
,
"description"
:
"Whether publishing retries are enabled."
,
"sourceType"
:
"com.example.Retry"
,
"defaultValue"
:
false
},
{
"name"
:
"test.group.one.retry.specific.enabled"
,
"type"
:
"java.lang.Boolean"
,
"description"
:
"Whether publishing retries are enabled."
,
"sourceType"
:
"com.example.Retry"
,
"defaultValue"
:
false
}
]
}
\ 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