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
3664895f
Commit
3664895f
authored
Jul 12, 2015
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
fd0b1c63
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
42 additions
and
42 deletions
+42
-42
appendix-configuration-metadata.adoc
...cs/src/main/asciidoc/appendix-configuration-metadata.adoc
+6
-6
ItemHint.java
...mework/boot/configurationprocessor/metadata/ItemHint.java
+8
-8
JsonMarshaller.java
.../boot/configurationprocessor/metadata/JsonMarshaller.java
+12
-12
ConfigurationMetadataAnnotationProcessorTests.java
...cessor/ConfigurationMetadataAnnotationProcessorTests.java
+2
-2
ConfigurationMetadataMatchers.java
...configurationprocessor/ConfigurationMetadataMatchers.java
+12
-12
JsonMarshallerTests.java
.../configurationprocessor/metadata/JsonMarshallerTests.java
+2
-2
No files found.
spring-boot-docs/src/main/asciidoc/appendix-configuration-metadata.adoc
View file @
3664895f
...
@@ -217,8 +217,8 @@ The JSON object contained in the `hints` array can contain the following attribu
...
@@ -217,8 +217,8 @@ The JSON object contained in the `hints` array can contain the following attribu
the value and may have a description
the value and may have a description
|`providers`
|`providers`
|
ProviderHint
[]
|
ValueProvider
[]
| A list of providers as defined by the `Value
Hint
` object (see below). Each entry defines
| A list of providers as defined by the `Value
Provider
` object (see below). Each entry defines
the name of the provider and its parameters, if any.
the name of the provider and its parameters, if any.
|===
|===
...
@@ -283,7 +283,7 @@ property, you can provide additional meta-data that:
...
@@ -283,7 +283,7 @@ property, you can provide additional meta-data that:
can discover the list of potential values based on the project's context.
can discover the list of potential values based on the project's context.
==== Value hint
s
==== Value hint
The `name` attribute of each hint refers to the `name` of a property. In the initial
The `name` attribute of each hint refers to the `name` of a property. In the initial
example above, we provide 3 values for the `server.tomcat.compression` property: `on`,
example above, we provide 3 values for the `server.tomcat.compression` property: `on`,
`off` and `force`.
`off` and `force`.
...
@@ -330,7 +330,7 @@ the most effective approach to auto-completion if your IDE supports it.
...
@@ -330,7 +330,7 @@ the most effective approach to auto-completion if your IDE supports it.
====
Provider hints
====
Value provider
Providers are a powerful way of attaching semantics to a property. We define in the section
Providers are a powerful way of attaching semantics to a property. We define in the section
below the official providers that you can use for your own hints. Bare in mind however that
below the official providers that you can use for your own hints. Bare in mind however that
your favorite IDE may implement some of these or none of them. It could eventually provide
your favorite IDE may implement some of these or none of them. It could eventually provide
...
@@ -345,7 +345,7 @@ The table below summarizes the list of supported providers:
...
@@ -345,7 +345,7 @@ The table below summarizes the list of supported providers:
|Name | Description
|Name | Description
|`any`
|`any`
|Permit any additional value
s
to be provided.
|Permit any additional value to be provided.
|`class-reference`
|`class-reference`
|Auto-complete the classes available in the project. Usually constrained by a base
|Auto-complete the classes available in the project. Usually constrained by a base
...
@@ -363,7 +363,7 @@ The table below summarizes the list of supported providers:
...
@@ -363,7 +363,7 @@ The table below summarizes the list of supported providers:
by a base class that is specified via the `target` parameter.
by a base class that is specified via the `target` parameter.
|`spring-profile-name`
|`spring-profile-name`
|Auto-complete the available profile names in the project.
|Auto-complete the available
Spring
profile names in the project.
|===
|===
...
...
spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ItemHint.java
View file @
3664895f
...
@@ -40,14 +40,14 @@ public class ItemHint implements Comparable<ItemHint> {
...
@@ -40,14 +40,14 @@ public class ItemHint implements Comparable<ItemHint> {
private
final
List
<
ValueHint
>
values
;
private
final
List
<
ValueHint
>
values
;
private
final
List
<
ProviderHint
>
providers
;
private
final
List
<
ValueProvider
>
providers
;
public
ItemHint
(
String
name
,
List
<
ValueHint
>
values
,
List
<
ProviderHint
>
providers
)
{
public
ItemHint
(
String
name
,
List
<
ValueHint
>
values
,
List
<
ValueProvider
>
providers
)
{
this
.
name
=
toCanonicalName
(
name
);
this
.
name
=
toCanonicalName
(
name
);
this
.
values
=
(
values
!=
null
?
new
ArrayList
<
ValueHint
>(
values
)
this
.
values
=
(
values
!=
null
?
new
ArrayList
<
ValueHint
>(
values
)
:
new
ArrayList
<
ValueHint
>());
:
new
ArrayList
<
ValueHint
>());
this
.
providers
=
(
providers
!=
null
?
new
ArrayList
<
ProviderHint
>(
providers
)
this
.
providers
=
(
providers
!=
null
?
new
ArrayList
<
ValueProvider
>(
providers
)
:
new
ArrayList
<
ProviderHint
>());
:
new
ArrayList
<
ValueProvider
>());
}
}
private
String
toCanonicalName
(
String
name
)
{
private
String
toCanonicalName
(
String
name
)
{
...
@@ -68,7 +68,7 @@ public class ItemHint implements Comparable<ItemHint> {
...
@@ -68,7 +68,7 @@ public class ItemHint implements Comparable<ItemHint> {
return
Collections
.
unmodifiableList
(
this
.
values
);
return
Collections
.
unmodifiableList
(
this
.
values
);
}
}
public
List
<
ProviderHint
>
getProviders
()
{
public
List
<
ValueProvider
>
getProviders
()
{
return
Collections
.
unmodifiableList
(
this
.
providers
);
return
Collections
.
unmodifiableList
(
this
.
providers
);
}
}
...
@@ -79,7 +79,7 @@ public class ItemHint implements Comparable<ItemHint> {
...
@@ -79,7 +79,7 @@ public class ItemHint implements Comparable<ItemHint> {
public
static
ItemHint
newHint
(
String
name
,
ValueHint
...
values
)
{
public
static
ItemHint
newHint
(
String
name
,
ValueHint
...
values
)
{
return
new
ItemHint
(
name
,
Arrays
.
asList
(
values
),
return
new
ItemHint
(
name
,
Arrays
.
asList
(
values
),
Collections
.<
ProviderHint
>
emptyList
());
Collections
.<
ValueProvider
>
emptyList
());
}
}
@Override
@Override
...
@@ -115,13 +115,13 @@ public class ItemHint implements Comparable<ItemHint> {
...
@@ -115,13 +115,13 @@ public class ItemHint implements Comparable<ItemHint> {
}
}
public
static
class
ProviderHint
{
public
static
class
ValueProvider
{
private
final
String
name
;
private
final
String
name
;
private
final
Map
<
String
,
Object
>
parameters
;
private
final
Map
<
String
,
Object
>
parameters
;
public
ProviderHint
(
String
name
,
Map
<
String
,
Object
>
parameters
)
{
public
ValueProvider
(
String
name
,
Map
<
String
,
Object
>
parameters
)
{
this
.
name
=
name
;
this
.
name
=
name
;
this
.
parameters
=
parameters
;
this
.
parameters
=
parameters
;
}
}
...
...
spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/JsonMarshaller.java
View file @
3664895f
...
@@ -107,20 +107,20 @@ public class JsonMarshaller {
...
@@ -107,20 +107,20 @@ public class JsonMarshaller {
}
}
if
(!
hint
.
getProviders
().
isEmpty
())
{
if
(!
hint
.
getProviders
().
isEmpty
())
{
JSONArray
providersArray
=
new
JSONArray
();
JSONArray
providersArray
=
new
JSONArray
();
for
(
ItemHint
.
ProviderHint
providerHint
:
hint
.
getProviders
())
{
for
(
ItemHint
.
ValueProvider
valueProvider
:
hint
.
getProviders
())
{
JSONObject
providerHint
Object
=
new
JSONOrderedObject
();
JSONObject
valueProvider
Object
=
new
JSONOrderedObject
();
providerHintObject
.
put
(
"name"
,
providerHint
.
getName
());
valueProviderObject
.
put
(
"name"
,
valueProvider
.
getName
());
if
(
providerHint
.
getParameters
()
!=
null
if
(
valueProvider
.
getParameters
()
!=
null
&&
!
providerHint
.
getParameters
().
isEmpty
())
{
&&
!
valueProvider
.
getParameters
().
isEmpty
())
{
JSONObject
parametersObject
=
new
JSONOrderedObject
();
JSONObject
parametersObject
=
new
JSONOrderedObject
();
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
providerHint
.
getParameters
()
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
valueProvider
.
getParameters
()
.
entrySet
())
{
.
entrySet
())
{
parametersObject
.
put
(
entry
.
getKey
(),
parametersObject
.
put
(
entry
.
getKey
(),
extractItemValue
(
entry
.
getValue
()));
extractItemValue
(
entry
.
getValue
()));
}
}
providerHint
Object
.
put
(
"parameters"
,
parametersObject
);
valueProvider
Object
.
put
(
"parameters"
,
parametersObject
);
}
}
providersArray
.
put
(
providerHint
Object
);
providersArray
.
put
(
valueProvider
Object
);
}
}
jsonObject
.
put
(
"providers"
,
providersArray
);
jsonObject
.
put
(
"providers"
,
providersArray
);
}
}
...
@@ -203,11 +203,11 @@ public class JsonMarshaller {
...
@@ -203,11 +203,11 @@ public class JsonMarshaller {
values
.
add
(
toValueHint
((
JSONObject
)
valuesArray
.
get
(
i
)));
values
.
add
(
toValueHint
((
JSONObject
)
valuesArray
.
get
(
i
)));
}
}
}
}
List
<
ItemHint
.
ProviderHint
>
providers
=
new
ArrayList
<
ItemHint
.
ProviderHint
>();
List
<
ItemHint
.
ValueProvider
>
providers
=
new
ArrayList
<
ItemHint
.
ValueProvider
>();
if
(
object
.
has
(
"providers"
))
{
if
(
object
.
has
(
"providers"
))
{
JSONArray
providersObject
=
object
.
getJSONArray
(
"providers"
);
JSONArray
providersObject
=
object
.
getJSONArray
(
"providers"
);
for
(
int
i
=
0
;
i
<
providersObject
.
length
();
i
++)
{
for
(
int
i
=
0
;
i
<
providersObject
.
length
();
i
++)
{
providers
.
add
(
to
ProviderHint
((
JSONObject
)
providersObject
.
get
(
i
)));
providers
.
add
(
to
ValueProvider
((
JSONObject
)
providersObject
.
get
(
i
)));
}
}
}
}
return
new
ItemHint
(
name
,
values
,
providers
);
return
new
ItemHint
(
name
,
values
,
providers
);
...
@@ -219,7 +219,7 @@ public class JsonMarshaller {
...
@@ -219,7 +219,7 @@ public class JsonMarshaller {
return
new
ItemHint
.
ValueHint
(
value
,
description
);
return
new
ItemHint
.
ValueHint
(
value
,
description
);
}
}
private
ItemHint
.
ProviderHint
toProviderHint
(
JSONObject
object
)
{
private
ItemHint
.
ValueProvider
toValueProvider
(
JSONObject
object
)
{
String
name
=
object
.
getString
(
"name"
);
String
name
=
object
.
getString
(
"name"
);
Map
<
String
,
Object
>
parameters
=
new
HashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
parameters
=
new
HashMap
<
String
,
Object
>();
if
(
object
.
has
(
"parameters"
))
{
if
(
object
.
has
(
"parameters"
))
{
...
@@ -230,7 +230,7 @@ public class JsonMarshaller {
...
@@ -230,7 +230,7 @@ public class JsonMarshaller {
parameters
.
put
(
key
,
value
);
parameters
.
put
(
key
,
value
);
}
}
}
}
return
new
ItemHint
.
ProviderHint
(
name
,
parameters
);
return
new
ItemHint
.
ValueProvider
(
name
,
parameters
);
}
}
private
Object
readItemValue
(
Object
value
)
{
private
Object
readItemValue
(
Object
value
)
{
...
...
spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java
View file @
3664895f
...
@@ -384,9 +384,9 @@ public class ConfigurationMetadataAnnotationProcessorTests {
...
@@ -384,9 +384,9 @@ public class ConfigurationMetadataAnnotationProcessorTests {
public
void
mergingOfHintWithProvider
()
throws
Exception
{
public
void
mergingOfHintWithProvider
()
throws
Exception
{
writeAdditionalHints
(
new
ItemHint
(
"simple.theName"
,
writeAdditionalHints
(
new
ItemHint
(
"simple.theName"
,
Collections
.<
ItemHint
.
ValueHint
>
emptyList
(),
Arrays
.
asList
(
Collections
.<
ItemHint
.
ValueHint
>
emptyList
(),
Arrays
.
asList
(
new
ItemHint
.
ProviderHint
(
"first"
,
Collections
new
ItemHint
.
ValueProvider
(
"first"
,
Collections
.<
String
,
Object
>
singletonMap
(
"target"
,
"org.foo"
)),
.<
String
,
Object
>
singletonMap
(
"target"
,
"org.foo"
)),
new
ItemHint
.
ProviderHint
(
"second"
,
null
))));
new
ItemHint
.
ValueProvider
(
"second"
,
null
))));
ConfigurationMetadata
metadata
=
compile
(
SimpleProperties
.
class
);
ConfigurationMetadata
metadata
=
compile
(
SimpleProperties
.
class
);
assertThat
(
metadata
,
assertThat
(
metadata
,
containsHint
(
"simple.the-name"
)
containsHint
(
"simple.the-name"
)
...
...
spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataMatchers.java
View file @
3664895f
...
@@ -209,15 +209,15 @@ public class ConfigurationMetadataMatchers {
...
@@ -209,15 +209,15 @@ public class ConfigurationMetadataMatchers {
private
final
List
<
ValueHintMatcher
>
values
;
private
final
List
<
ValueHintMatcher
>
values
;
private
final
List
<
ProviderHint
Matcher
>
providers
;
private
final
List
<
ValueProvider
Matcher
>
providers
;
public
ContainsHintMatcher
(
String
name
)
{
public
ContainsHintMatcher
(
String
name
)
{
this
(
name
,
new
ArrayList
<
ValueHintMatcher
>(),
this
(
name
,
new
ArrayList
<
ValueHintMatcher
>(),
new
ArrayList
<
ProviderHint
Matcher
>());
new
ArrayList
<
ValueProvider
Matcher
>());
}
}
public
ContainsHintMatcher
(
String
name
,
List
<
ValueHintMatcher
>
values
,
public
ContainsHintMatcher
(
String
name
,
List
<
ValueHintMatcher
>
values
,
List
<
ProviderHint
Matcher
>
providers
)
{
List
<
ValueProvider
Matcher
>
providers
)
{
this
.
name
=
name
;
this
.
name
=
name
;
this
.
values
=
values
;
this
.
values
=
values
;
this
.
providers
=
providers
;
this
.
providers
=
providers
;
...
@@ -238,7 +238,7 @@ public class ConfigurationMetadataMatchers {
...
@@ -238,7 +238,7 @@ public class ConfigurationMetadataMatchers {
return
false
;
return
false
;
}
}
}
}
for
(
ProviderHint
Matcher
provider
:
this
.
providers
)
{
for
(
ValueProvider
Matcher
provider
:
this
.
providers
)
{
if
(!
provider
.
matches
(
itemHint
))
{
if
(!
provider
.
matches
(
itemHint
))
{
return
false
;
return
false
;
}
}
...
@@ -277,9 +277,9 @@ public class ConfigurationMetadataMatchers {
...
@@ -277,9 +277,9 @@ public class ConfigurationMetadataMatchers {
public
ContainsHintMatcher
withProvider
(
int
index
,
String
provider
,
public
ContainsHintMatcher
withProvider
(
int
index
,
String
provider
,
Map
<
String
,
Object
>
parameters
)
{
Map
<
String
,
Object
>
parameters
)
{
List
<
ProviderHintMatcher
>
providers
=
new
ArrayList
<
ProviderHint
Matcher
>(
List
<
ValueProviderMatcher
>
providers
=
new
ArrayList
<
ValueProvider
Matcher
>(
this
.
providers
);
this
.
providers
);
providers
.
add
(
new
ProviderHint
Matcher
(
index
,
provider
,
parameters
));
providers
.
add
(
new
ValueProvider
Matcher
(
index
,
provider
,
parameters
));
return
new
ContainsHintMatcher
(
this
.
name
,
this
.
values
,
providers
);
return
new
ContainsHintMatcher
(
this
.
name
,
this
.
values
,
providers
);
}
}
...
@@ -347,12 +347,12 @@ public class ConfigurationMetadataMatchers {
...
@@ -347,12 +347,12 @@ public class ConfigurationMetadataMatchers {
}
}
public
static
class
ProviderHint
Matcher
extends
BaseMatcher
<
ItemHint
>
{
public
static
class
ValueProvider
Matcher
extends
BaseMatcher
<
ItemHint
>
{
private
final
int
index
;
private
final
int
index
;
private
final
String
name
;
private
final
String
name
;
private
final
Map
<
String
,
Object
>
parameters
;
private
final
Map
<
String
,
Object
>
parameters
;
public
ProviderHint
Matcher
(
int
index
,
String
name
,
Map
<
String
,
Object
>
parameters
)
{
public
ValueProvider
Matcher
(
int
index
,
String
name
,
Map
<
String
,
Object
>
parameters
)
{
this
.
index
=
index
;
this
.
index
=
index
;
this
.
name
=
name
;
this
.
name
=
name
;
this
.
parameters
=
parameters
;
this
.
parameters
=
parameters
;
...
@@ -364,14 +364,14 @@ public class ConfigurationMetadataMatchers {
...
@@ -364,14 +364,14 @@ public class ConfigurationMetadataMatchers {
if
(
this
.
index
+
1
>
hint
.
getProviders
().
size
())
{
if
(
this
.
index
+
1
>
hint
.
getProviders
().
size
())
{
return
false
;
return
false
;
}
}
ItemHint
.
ProviderHint
providerHint
=
hint
.
getProviders
().
get
(
this
.
index
);
ItemHint
.
ValueProvider
valueProvider
=
hint
.
getProviders
().
get
(
this
.
index
);
if
(
this
.
name
!=
null
&&
!
this
.
name
.
equals
(
providerHint
.
getName
()))
{
if
(
this
.
name
!=
null
&&
!
this
.
name
.
equals
(
valueProvider
.
getName
()))
{
return
false
;
return
false
;
}
}
if
(
this
.
parameters
!=
null
)
{
if
(
this
.
parameters
!=
null
)
{
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
this
.
parameters
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
this
.
parameters
.
entrySet
())
{
if
(!
IsMapContaining
.
hasEntry
(
entry
.
getKey
(),
entry
.
getValue
())
if
(!
IsMapContaining
.
hasEntry
(
entry
.
getKey
(),
entry
.
getValue
())
.
matches
(
providerHint
.
getParameters
()))
{
.
matches
(
valueProvider
.
getParameters
()))
{
return
false
;
return
false
;
}
}
}
}
...
@@ -381,7 +381,7 @@ public class ConfigurationMetadataMatchers {
...
@@ -381,7 +381,7 @@ public class ConfigurationMetadataMatchers {
@Override
@Override
public
void
describeTo
(
Description
description
)
{
public
void
describeTo
(
Description
description
)
{
description
.
appendText
(
"
provider hint
"
);
description
.
appendText
(
"
value provider
"
);
if
(
this
.
name
!=
null
)
{
if
(
this
.
name
!=
null
)
{
description
.
appendText
(
" name "
).
appendValue
(
this
.
name
);
description
.
appendText
(
" name "
).
appendValue
(
this
.
name
);
}
}
...
...
spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/JsonMarshallerTests.java
View file @
3664895f
...
@@ -58,9 +58,9 @@ public class JsonMarshallerTests {
...
@@ -58,9 +58,9 @@ public class JsonMarshallerTests {
metadata
.
add
(
ItemHint
.
newHint
(
"a.b"
));
metadata
.
add
(
ItemHint
.
newHint
(
"a.b"
));
metadata
.
add
(
ItemHint
.
newHint
(
"c"
,
new
ItemHint
.
ValueHint
(
123
,
"hey"
),
metadata
.
add
(
ItemHint
.
newHint
(
"c"
,
new
ItemHint
.
ValueHint
(
123
,
"hey"
),
new
ItemHint
.
ValueHint
(
456
,
null
)));
new
ItemHint
.
ValueHint
(
456
,
null
)));
metadata
.
add
(
new
ItemHint
(
"d"
,
null
,
Arrays
.
asList
(
new
ItemHint
.
ProviderHint
(
metadata
.
add
(
new
ItemHint
(
"d"
,
null
,
Arrays
.
asList
(
new
ItemHint
.
ValueProvider
(
"first"
,
Collections
.<
String
,
Object
>
singletonMap
(
"target"
,
"foo"
)),
"first"
,
Collections
.<
String
,
Object
>
singletonMap
(
"target"
,
"foo"
)),
new
ItemHint
.
ProviderHint
(
"second"
,
null
))));
new
ItemHint
.
ValueProvider
(
"second"
,
null
))));
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
JsonMarshaller
marshaller
=
new
JsonMarshaller
();
JsonMarshaller
marshaller
=
new
JsonMarshaller
();
marshaller
.
write
(
metadata
,
outputStream
);
marshaller
.
write
(
metadata
,
outputStream
);
...
...
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