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
f1af8c55
Commit
f1af8c55
authored
Nov 05, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.1.x'
Closes gh-18889
parents
d8545bde
59bc3c56
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
16 deletions
+62
-16
ConfigurationMetadataAnnotationProcessor.java
...onprocessor/ConfigurationMetadataAnnotationProcessor.java
+22
-16
ConfigurationMetadataAnnotationProcessorTests.java
...cessor/ConfigurationMetadataAnnotationProcessorTests.java
+6
-0
RecursiveProperties.java
...ot/configurationsample/recursive/RecursiveProperties.java
+34
-0
No files found.
spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java
View file @
f1af8c55
...
@@ -25,6 +25,7 @@ import java.util.LinkedHashMap;
...
@@ -25,6 +25,7 @@ import java.util.LinkedHashMap;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.Stack
;
import
javax.annotation.processing.AbstractProcessor
;
import
javax.annotation.processing.AbstractProcessor
;
import
javax.annotation.processing.ProcessingEnvironment
;
import
javax.annotation.processing.ProcessingEnvironment
;
...
@@ -180,10 +181,10 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
...
@@ -180,10 +181,10 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
if
(
annotation
!=
null
)
{
if
(
annotation
!=
null
)
{
String
prefix
=
getPrefix
(
annotation
);
String
prefix
=
getPrefix
(
annotation
);
if
(
element
instanceof
TypeElement
)
{
if
(
element
instanceof
TypeElement
)
{
processAnnotatedTypeElement
(
prefix
,
(
TypeElement
)
element
);
processAnnotatedTypeElement
(
prefix
,
(
TypeElement
)
element
,
new
Stack
<
TypeElement
>()
);
}
}
else
if
(
element
instanceof
ExecutableElement
)
{
else
if
(
element
instanceof
ExecutableElement
)
{
processExecutableElement
(
prefix
,
(
ExecutableElement
)
element
);
processExecutableElement
(
prefix
,
(
ExecutableElement
)
element
,
new
Stack
<
TypeElement
>()
);
}
}
}
}
}
}
...
@@ -192,13 +193,13 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
...
@@ -192,13 +193,13 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
}
}
}
}
private
void
processAnnotatedTypeElement
(
String
prefix
,
TypeElement
element
)
{
private
void
processAnnotatedTypeElement
(
String
prefix
,
TypeElement
element
,
Stack
<
TypeElement
>
seen
)
{
String
type
=
this
.
metadataEnv
.
getTypeUtils
().
getQualifiedName
(
element
);
String
type
=
this
.
metadataEnv
.
getTypeUtils
().
getQualifiedName
(
element
);
this
.
metadataCollector
.
add
(
ItemMetadata
.
newGroup
(
prefix
,
type
,
type
,
null
));
this
.
metadataCollector
.
add
(
ItemMetadata
.
newGroup
(
prefix
,
type
,
type
,
null
));
processTypeElement
(
prefix
,
element
,
null
);
processTypeElement
(
prefix
,
element
,
null
,
seen
);
}
}
private
void
processExecutableElement
(
String
prefix
,
ExecutableElement
element
)
{
private
void
processExecutableElement
(
String
prefix
,
ExecutableElement
element
,
Stack
<
TypeElement
>
seen
)
{
if
((!
element
.
getModifiers
().
contains
(
Modifier
.
PRIVATE
))
if
((!
element
.
getModifiers
().
contains
(
Modifier
.
PRIVATE
))
&&
(
TypeKind
.
VOID
!=
element
.
getReturnType
().
getKind
()))
{
&&
(
TypeKind
.
VOID
!=
element
.
getReturnType
().
getKind
()))
{
Element
returns
=
this
.
processingEnv
.
getTypeUtils
().
asElement
(
element
.
getReturnType
());
Element
returns
=
this
.
processingEnv
.
getTypeUtils
().
asElement
(
element
.
getReturnType
());
...
@@ -213,22 +214,27 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
...
@@ -213,22 +214,27 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
}
}
else
{
else
{
this
.
metadataCollector
.
add
(
group
);
this
.
metadataCollector
.
add
(
group
);
processTypeElement
(
prefix
,
(
TypeElement
)
returns
,
element
);
processTypeElement
(
prefix
,
(
TypeElement
)
returns
,
element
,
seen
);
}
}
}
}
}
}
}
}
private
void
processTypeElement
(
String
prefix
,
TypeElement
element
,
ExecutableElement
source
)
{
private
void
processTypeElement
(
String
prefix
,
TypeElement
element
,
ExecutableElement
source
,
new
PropertyDescriptorResolver
(
this
.
metadataEnv
).
resolve
(
element
,
source
).
forEach
((
descriptor
)
->
{
Stack
<
TypeElement
>
seen
)
{
this
.
metadataCollector
.
add
(
descriptor
.
resolveItemMetadata
(
prefix
,
this
.
metadataEnv
));
if
(!
seen
.
contains
(
element
))
{
if
(
descriptor
.
isNested
(
this
.
metadataEnv
))
{
seen
.
push
(
element
);
TypeElement
nestedTypeElement
=
(
TypeElement
)
this
.
metadataEnv
.
getTypeUtils
()
new
PropertyDescriptorResolver
(
this
.
metadataEnv
).
resolve
(
element
,
source
).
forEach
((
descriptor
)
->
{
.
asElement
(
descriptor
.
getType
());
this
.
metadataCollector
.
add
(
descriptor
.
resolveItemMetadata
(
prefix
,
this
.
metadataEnv
));
String
nestedPrefix
=
ConfigurationMetadata
.
nestedPrefix
(
prefix
,
descriptor
.
getName
());
if
(
descriptor
.
isNested
(
this
.
metadataEnv
))
{
processTypeElement
(
nestedPrefix
,
nestedTypeElement
,
source
);
TypeElement
nestedTypeElement
=
(
TypeElement
)
this
.
metadataEnv
.
getTypeUtils
()
}
.
asElement
(
descriptor
.
getType
());
});
String
nestedPrefix
=
ConfigurationMetadata
.
nestedPrefix
(
prefix
,
descriptor
.
getName
());
processTypeElement
(
nestedPrefix
,
nestedTypeElement
,
source
,
seen
);
}
});
seen
.
pop
();
}
}
}
private
void
processEndpoint
(
Element
element
,
List
<
Element
>
annotations
)
{
private
void
processEndpoint
(
Element
element
,
List
<
Element
>
annotations
)
{
...
...
spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java
View file @
f1af8c55
...
@@ -20,6 +20,7 @@ import org.junit.jupiter.api.Test;
...
@@ -20,6 +20,7 @@ import org.junit.jupiter.api.Test;
import
org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata
;
import
org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata
;
import
org.springframework.boot.configurationprocessor.metadata.Metadata
;
import
org.springframework.boot.configurationprocessor.metadata.Metadata
;
import
org.springframework.boot.configurationsample.recursive.RecursiveProperties
;
import
org.springframework.boot.configurationsample.simple.ClassWithNestedProperties
;
import
org.springframework.boot.configurationsample.simple.ClassWithNestedProperties
;
import
org.springframework.boot.configurationsample.simple.DeprecatedFieldSingleProperty
;
import
org.springframework.boot.configurationsample.simple.DeprecatedFieldSingleProperty
;
import
org.springframework.boot.configurationsample.simple.DeprecatedSingleProperty
;
import
org.springframework.boot.configurationsample.simple.DeprecatedSingleProperty
;
...
@@ -361,4 +362,9 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
...
@@ -361,4 +362,9 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
.
withMessageContaining
(
"Compilation failed"
);
.
withMessageContaining
(
"Compilation failed"
);
}
}
@Test
void
recursivePropertiesDoNotCauseAStackOverflow
()
{
compile
(
RecursiveProperties
.
class
);
}
}
}
spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/recursive/RecursiveProperties.java
0 → 100644
View file @
f1af8c55
/*
* Copyright 2012-2018 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
.
configurationsample
.
recursive
;
import
org.springframework.boot.configurationsample.ConfigurationProperties
;
@ConfigurationProperties
(
"prefix"
)
public
class
RecursiveProperties
{
private
RecursiveProperties
recursive
;
public
RecursiveProperties
getRecursive
()
{
return
this
.
recursive
;
}
public
void
setRecursive
(
RecursiveProperties
recursive
)
{
this
.
recursive
=
recursive
;
}
}
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