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
6631136f
Commit
6631136f
authored
Jun 27, 2016
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.3.x'
parents
a5cddf79
17f8a244
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
19 deletions
+45
-19
ConfigurationMetadata.java
...onfigurationprocessor/metadata/ConfigurationMetadata.java
+18
-19
ConfigurationMetadataTests.java
...urationprocessor/metadata/ConfigurationMetadataTests.java
+12
-0
PropertiesConfigurationFactoryTests.java
...mework/boot/bind/PropertiesConfigurationFactoryTests.java
+15
-0
No files found.
spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java
View file @
6631136f
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
6
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.
...
...
@@ -17,11 +17,10 @@
package
org
.
springframework
.
boot
.
configurationprocessor
.
metadata
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.ListIterator
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.LinkedMultiValueMap
;
...
...
@@ -38,7 +37,7 @@ import org.springframework.util.ObjectUtils;
*/
public
class
ConfigurationMetadata
{
private
static
final
Pattern
CAMEL_CASE_PATTERN
=
Pattern
.
compile
(
"([^A-Z-])([A-Z])"
);
private
static
final
List
<
Character
>
SEPARATORS
=
Arrays
.
asList
(
'-'
,
'_'
);
private
final
MultiValueMap
<
String
,
ItemMetadata
>
items
;
...
...
@@ -160,23 +159,23 @@ public class ConfigurationMetadata {
}
static
String
toDashedCase
(
String
name
)
{
Matcher
matcher
=
CAMEL_CASE_PATTERN
.
matcher
(
name
);
StringBuffer
result
=
new
StringBuffer
();
while
(
matcher
.
find
())
{
matcher
.
appendReplacement
(
result
,
getDashed
(
matcher
));
}
matcher
.
appendTail
(
result
);
return
result
.
toString
().
toLowerCase
();
}
StringBuilder
sb
=
new
StringBuilder
();
Character
previous
=
null
;
for
(
char
current
:
name
.
toCharArray
())
{
if
(
SEPARATORS
.
contains
(
current
))
{
sb
.
append
(
"-"
);
}
else
if
(
Character
.
isUpperCase
(
current
)
&&
previous
!=
null
&&
!
SEPARATORS
.
contains
(
previous
))
{
sb
.
append
(
"-"
).
append
(
current
);
}
else
{
sb
.
append
(
current
);
}
previous
=
current
;
private
static
String
getDashed
(
Matcher
matcher
)
{
String
first
=
matcher
.
group
(
1
);
String
second
=
matcher
.
group
(
2
);
if
(
first
.
equals
(
"_"
))
{
// not a word for the binder
return
first
+
second
;
}
return
first
+
"-"
+
second
;
return
sb
.
toString
().
toLowerCase
()
;
}
private
static
<
T
extends
Comparable
<
T
>>
List
<
T
>
flattenValues
(
...
...
spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadataTests.java
View file @
6631136f
...
...
@@ -32,6 +32,16 @@ public class ConfigurationMetadataTests {
assertThat
(
toDashedCase
(
"simpleCamelCase"
)).
isEqualTo
(
"simple-camel-case"
);
}
@Test
public
void
toDashedCaseUpperCamelCaseSuffix
()
{
assertThat
(
toDashedCase
(
"myDLQ"
),
is
(
"my-d-l-q"
));
}
@Test
public
void
toDashedCaseUpperCamelCaseMiddle
()
{
assertThat
(
toDashedCase
(
"someDLQKey"
),
is
(
"some-d-l-q-key"
));
}
@Test
public
void
toDashedCaseWordsUnderscore
()
{
assertThat
(
toDashedCase
(
"Word_With_underscore"
))
...
...
@@ -62,6 +72,8 @@ public class ConfigurationMetadataTests {
@Test
public
void
toDashedCaseUppercase
()
{
assertThat
(
toDashedCase
(
"UPPERCASE"
)).
isEqualTo
(
"uppercase"
);
public
void
toDashedCaseMultipleUnderscores
()
{
assertThat
(
toDashedCase
(
"super___crazy"
),
is
(
"super---crazy"
));
}
@Test
...
...
spring-boot/src/test/java/org/springframework/boot/bind/PropertiesConfigurationFactoryTests.java
View file @
6631136f
...
...
@@ -170,6 +170,12 @@ public class PropertiesConfigurationFactoryTests {
assertThat
(
foo
.
fooBarURI
).
isEqualTo
(
"baz"
);
}
@Test
public
void
propertyWithAllUpperCaseInTheMiddleCanBeBound
()
throws
Exception
{
Foo
foo
=
createFoo
(
"foo-d-l-q-bar:baz"
);
assertEquals
(
"baz"
,
foo
.
fooDLQBar
);
}
private
Foo
createFoo
(
final
String
values
)
throws
Exception
{
setupFactory
();
return
bindFoo
(
values
);
...
...
@@ -204,6 +210,8 @@ public class PropertiesConfigurationFactoryTests {
private
String
fooBarURI
;
private
String
fooDLQBar
;
public
String
getSpringFooBaz
()
{
return
this
.
spring_foo_baz
;
}
...
...
@@ -244,6 +252,13 @@ public class PropertiesConfigurationFactoryTests {
this
.
fooBarURI
=
fooBarURI
;
}
public
String
getFooDLQBar
()
{
return
this
.
fooDLQBar
;
}
public
void
setFooDLQBar
(
String
fooDLQBar
)
{
this
.
fooDLQBar
=
fooDLQBar
;
}
}
}
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