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
778e3eb0
Commit
778e3eb0
authored
Jun 24, 2015
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
bc932173
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
43 deletions
+38
-43
appendix-configuration-metadata.adoc
...cs/src/main/asciidoc/appendix-configuration-metadata.adoc
+7
-1
ItemHint.java
...mework/boot/configurationprocessor/metadata/ItemHint.java
+12
-12
JsonMarshaller.java
.../boot/configurationprocessor/metadata/JsonMarshaller.java
+0
-2
ConfigurationMetadataAnnotationProcessorTests.java
...cessor/ConfigurationMetadataAnnotationProcessorTests.java
+9
-10
ConfigurationMetadataMatchers.java
...configurationprocessor/ConfigurationMetadataMatchers.java
+8
-17
JsonMarshallerTests.java
.../configurationprocessor/metadata/JsonMarshallerTests.java
+2
-1
No files found.
spring-boot-docs/src/main/asciidoc/appendix-configuration-metadata.adoc
View file @
778e3eb0
...
...
@@ -98,6 +98,7 @@ given property. When configuring the `server.tomcat.compression` property, a too
use it to offer some auto-completion help for the `off`, `on` and `force` values.
[[configuration-metadata-group-attributes]]
==== Group Attributes
The JSON object contained in the `groups` array can contain the following attributes:
...
...
@@ -189,6 +190,7 @@ The JSON object contained in the `properties` array can contain the following at
|===
[[configuration-metadata-hints-attributes]]
==== Hint Attributes
The JSON object contained in the `hints` array can contain the following attributes:
...
...
@@ -238,8 +240,10 @@ appear multiple times within a meta-data file. For example, Spring Boot binds
offering overlap of property names. Consumers of meta-data should take care to ensure
that they support such scenarios.
=== Providing manual hints
[[configuration-metadata-providing-manual-hints]]
=== Providing manual hints
To improve the user experience and further assist the user in configuring a given
property, you can provide additional meta-data that describes the list of potential
values for a property.
...
...
@@ -252,6 +256,8 @@ If your property is of type `Map`, you can provide hints for both the keys and t
values (but not for the map itself). The special `.keys` and `.values` suffixes must
be used to refer to the keys and the values respectively.
[[configuration-metadata-annotation-processor]]
=== Generating your own meta-data using the annotation processor
You can easily generate your own configuration meta-data file from items annotated with
...
...
spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ItemHint.java
View file @
778e3eb0
...
...
@@ -22,13 +22,13 @@ import java.util.Collections;
import
java.util.List
;
/**
* Provide hints on an {@link ItemMetadata}. Defines the list of possible values for
*
a
particular item as {@link ItemHint.ValueHint} instances.
* Provide hints on an {@link ItemMetadata}. Defines the list of possible values for
a
* particular item as {@link ItemHint.ValueHint} instances.
* <p>
* The {@code name} of the hint is the name of the related property with one major
* exception for map types as both the keys and values of the map can have hints. In
*
such a case, the hint should be suffixed by ".key" or ".values" respectively. Creating
*
a
hint for a map using its property name is therefore invalid.
* exception for map types as both the keys and values of the map can have hints. In
such
*
a case, the hint should be suffixed by ".key" or ".values" respectively. Creating a
* hint for a map using its property name is therefore invalid.
*
* @author Stephane Nicoll
* @since 1.3.0
...
...
@@ -73,13 +73,12 @@ public class ItemHint implements Comparable<ItemHint> {
@Override
public
String
toString
()
{
return
"ItemHint{"
+
"name='"
+
this
.
name
+
'\''
+
", values="
+
this
.
values
+
'}'
;
return
"ItemHint{"
+
"name='"
+
this
.
name
+
'\''
+
", values="
+
this
.
values
+
'}'
;
}
public
static
class
ValueHint
{
private
final
Object
value
;
private
final
String
description
;
...
...
@@ -99,9 +98,10 @@ public class ItemHint implements Comparable<ItemHint> {
@Override
public
String
toString
()
{
return
"ValueHint{"
+
"value="
+
this
.
value
+
", description='"
+
this
.
description
+
'\''
+
'}'
;
return
"ValueHint{"
+
"value="
+
this
.
value
+
", description='"
+
this
.
description
+
'\''
+
'}'
;
}
}
}
spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/JsonMarshaller.java
View file @
778e3eb0
...
...
@@ -106,7 +106,6 @@ public class JsonMarshaller {
return
jsonObject
;
}
private
void
putIfPresent
(
JSONObject
jsonObject
,
String
name
,
Object
value
)
{
if
(
value
!=
null
)
{
jsonObject
.
put
(
name
,
value
);
...
...
@@ -192,7 +191,6 @@ public class JsonMarshaller {
return
new
ItemHint
.
ValueHint
(
value
,
description
);
}
private
Object
readItemValue
(
Object
value
)
{
if
(
value
instanceof
JSONArray
)
{
JSONArray
array
=
(
JSONArray
)
value
;
...
...
spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java
View file @
778e3eb0
...
...
@@ -350,24 +350,23 @@ public class ConfigurationMetadataAnnotationProcessorTests {
@Test
public
void
mergingOfSimpleHint
()
throws
Exception
{
writeAdditionalHints
(
ItemHint
.
newHint
(
"simple.the-name"
,
new
ItemHint
.
ValueHint
(
"boot"
,
"Bla bla"
),
new
ItemHint
.
ValueHint
(
"spring"
,
null
)));
writeAdditionalHints
(
ItemHint
.
newHint
(
"simple.the-name"
,
new
ItemHint
.
ValueHint
(
"boot"
,
"Bla bla"
),
new
ItemHint
.
ValueHint
(
"spring"
,
null
)));
ConfigurationMetadata
metadata
=
compile
(
SimpleProperties
.
class
);
assertThat
(
metadata
,
containsHint
(
"simple.the-name"
)
.
withValue
(
0
,
"boot"
,
"Bla bla"
)
.
withValue
(
1
,
"spring"
,
null
));
assertThat
(
metadata
,
containsHint
(
"simple.the-name"
)
.
withValue
(
0
,
"boot"
,
"Bla bla"
)
.
withValue
(
1
,
"spring"
,
null
));
}
@Test
public
void
mergingOfHintWithNonCanonicalName
()
throws
Exception
{
writeAdditionalHints
(
ItemHint
.
newHint
(
"simple.theName"
,
new
ItemHint
.
ValueHint
(
"boot"
,
"Bla bla"
)));
writeAdditionalHints
(
ItemHint
.
newHint
(
"simple.theName"
,
new
ItemHint
.
ValueHint
(
"boot"
,
"Bla bla"
)));
ConfigurationMetadata
metadata
=
compile
(
SimpleProperties
.
class
);
assertThat
(
metadata
,
containsHint
(
"simple.the-name"
)
.
withValue
(
0
,
"boot"
,
"Bla bla"
));
assertThat
(
metadata
,
containsHint
(
"simple.the-name"
)
.
withValue
(
0
,
"boot"
,
"Bla bla"
));
}
@Test
...
...
spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataMatchers.java
View file @
778e3eb0
...
...
@@ -241,8 +241,7 @@ public class ConfigurationMetadataMatchers {
description
.
appendText
(
"missing hint "
+
this
.
name
);
}
else
{
description
.
appendText
(
"was hint "
).
appendValue
(
itemHint
);
description
.
appendText
(
"was hint "
).
appendValue
(
itemHint
);
}
}
...
...
@@ -260,8 +259,7 @@ public class ConfigurationMetadataMatchers {
return
new
ContainsHintMatcher
(
this
.
name
,
values
);
}
private
ItemHint
getFirstHintWithName
(
ConfigurationMetadata
metadata
,
String
name
)
{
private
ItemHint
getFirstHintWithName
(
ConfigurationMetadata
metadata
,
String
name
)
{
for
(
ItemHint
hint
:
metadata
.
getHints
())
{
if
(
name
.
equals
(
hint
.
getName
()))
{
return
hint
;
...
...
@@ -273,8 +271,11 @@ public class ConfigurationMetadataMatchers {
}
public
static
class
ValueHintMatcher
extends
BaseMatcher
<
ItemHint
>
{
private
final
int
index
;
private
final
Object
value
;
private
final
String
description
;
public
ValueHintMatcher
(
int
index
,
Object
value
,
String
description
)
{
...
...
@@ -290,12 +291,11 @@ public class ConfigurationMetadataMatchers {
return
false
;
}
ItemHint
.
ValueHint
valueHint
=
hint
.
getValues
().
get
(
this
.
index
);
if
(
this
.
value
!=
null
&&
!
this
.
value
.
equals
(
valueHint
.
getValue
()))
{
if
(
this
.
value
!=
null
&&
!
this
.
value
.
equals
(
valueHint
.
getValue
()))
{
return
false
;
}
if
(
this
.
description
!=
null
&&
!
this
.
description
.
equals
(
valueHint
.
getDescription
()))
{
&&
!
this
.
description
.
equals
(
valueHint
.
getDescription
()))
{
return
false
;
}
return
true
;
...
...
@@ -303,7 +303,7 @@ public class ConfigurationMetadataMatchers {
@Override
public
void
describeTo
(
Description
description
)
{
description
.
appendText
(
"value hint at index '"
+
this
.
index
+
"'"
);
description
.
appendText
(
"value hint at index '"
+
this
.
index
+
"'"
);
if
(
this
.
value
!=
null
)
{
description
.
appendText
(
" value "
).
appendValue
(
this
.
value
);
}
...
...
@@ -312,15 +312,6 @@ public class ConfigurationMetadataMatchers {
}
}
private
ItemHint
.
ValueHint
getValueHint
(
ItemHint
hint
)
{
for
(
ItemHint
.
ValueHint
valueHint
:
hint
.
getValues
())
{
if
(
this
.
value
.
equals
(
valueHint
.
getValue
()))
{
return
valueHint
;
}
}
return
null
;
}
}
}
spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/JsonMarshallerTests.java
View file @
778e3eb0
...
...
@@ -74,7 +74,8 @@ public class JsonMarshallerTests {
containsProperty
(
"f"
).
withDefaultValue
(
is
(
new
boolean
[]
{
true
,
false
})));
assertThat
(
read
,
containsGroup
(
"d"
));
assertThat
(
read
,
containsHint
(
"a.b"
));
assertThat
(
read
,
containsHint
(
"c"
).
withValue
(
0
,
123
,
"hey"
).
withValue
(
1
,
456
,
null
));
assertThat
(
read
,
containsHint
(
"c"
).
withValue
(
0
,
123
,
"hey"
).
withValue
(
1
,
456
,
null
));
}
}
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