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
cc221885
Commit
cc221885
authored
Jan 21, 2015
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'gh-2361'
parents
0025be87
606ea497
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
10 deletions
+85
-10
ConfigurationMetadataAnnotationProcessor.java
...onprocessor/ConfigurationMetadataAnnotationProcessor.java
+6
-4
ConfigurationMetadataAnnotationProcessorTests.java
...cessor/ConfigurationMetadataAnnotationProcessorTests.java
+69
-4
TestCompiler.java
...ngframework/boot/configurationprocessor/TestCompiler.java
+10
-2
No files found.
spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java
View file @
cc221885
/*
/*
* Copyright 2012-201
4
the original author or authors.
* Copyright 2012-201
5
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.
...
@@ -393,9 +393,11 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
...
@@ -393,9 +393,11 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
// Gradle keeps things separate
// Gradle keeps things separate
String
path
=
file
.
getPath
();
String
path
=
file
.
getPath
();
int
index
=
path
.
lastIndexOf
(
CLASSES_FOLDER
);
int
index
=
path
.
lastIndexOf
(
CLASSES_FOLDER
);
path
=
path
.
substring
(
0
,
index
)
+
RESOURCES_FOLDER
if
(
index
>=
0
)
{
+
path
.
substring
(
index
+
CLASSES_FOLDER
.
length
());
path
=
path
.
substring
(
0
,
index
)
+
RESOURCES_FOLDER
file
=
new
File
(
path
);
+
path
.
substring
(
index
+
CLASSES_FOLDER
.
length
());
file
=
new
File
(
path
);
}
}
}
return
(
file
.
exists
()
?
new
FileInputStream
(
file
)
:
fileObject
.
toUri
().
toURL
()
return
(
file
.
exists
()
?
new
FileInputStream
(
file
)
:
fileObject
.
toUri
().
toURL
()
.
openStream
());
.
openStream
());
...
...
spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java
View file @
cc221885
/*
/*
* Copyright 2012-201
4
the original author or authors.
* Copyright 2012-201
5
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.
...
@@ -16,16 +16,23 @@
...
@@ -16,16 +16,23 @@
package
org
.
springframework
.
boot
.
configurationprocessor
;
package
org
.
springframework
.
boot
.
configurationprocessor
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.io.IOException
;
import
javax.annotation.processing.SupportedAnnotationTypes
;
import
javax.annotation.processing.SupportedAnnotationTypes
;
import
javax.annotation.processing.SupportedSourceVersion
;
import
javax.annotation.processing.SupportedSourceVersion
;
import
javax.lang.model.SourceVersion
;
import
javax.lang.model.SourceVersion
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
org.junit.Before
;
import
org.junit.Rule
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.rules.TemporaryFolder
;
import
org.junit.rules.TemporaryFolder
;
import
org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata
;
import
org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata
;
import
org.springframework.boot.configurationprocessor.metadata.JsonMarshaller
;
import
org.springframework.boot.configurationsample.lombok.LombokExplicitProperties
;
import
org.springframework.boot.configurationsample.lombok.LombokExplicitProperties
;
import
org.springframework.boot.configurationsample.lombok.LombokSimpleDataProperties
;
import
org.springframework.boot.configurationsample.lombok.LombokSimpleDataProperties
;
import
org.springframework.boot.configurationsample.lombok.LombokSimpleProperties
;
import
org.springframework.boot.configurationsample.lombok.LombokSimpleProperties
;
...
@@ -59,12 +66,20 @@ import static org.springframework.boot.configurationprocessor.ConfigurationMetad
...
@@ -59,12 +66,20 @@ import static org.springframework.boot.configurationprocessor.ConfigurationMetad
*
*
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Phillip Webb
* @author Phillip Webb
* @author Andy Wilkinson
*/
*/
public
class
ConfigurationMetadataAnnotationProcessorTests
{
public
class
ConfigurationMetadataAnnotationProcessorTests
{
@Rule
@Rule
public
TemporaryFolder
temporaryFolder
=
new
TemporaryFolder
();
public
TemporaryFolder
temporaryFolder
=
new
TemporaryFolder
();
private
TestCompiler
compiler
;
@Before
public
void
createCompiler
()
throws
IOException
{
this
.
compiler
=
new
TestCompiler
(
this
.
temporaryFolder
);
}
@Test
@Test
public
void
notAnnotated
()
throws
Exception
{
public
void
notAnnotated
()
throws
Exception
{
ConfigurationMetadata
metadata
=
compile
(
NotAnnotated
.
class
);
ConfigurationMetadata
metadata
=
compile
(
NotAnnotated
.
class
);
...
@@ -307,6 +322,36 @@ public class ConfigurationMetadataAnnotationProcessorTests {
...
@@ -307,6 +322,36 @@ public class ConfigurationMetadataAnnotationProcessorTests {
assertSimpleLombokProperties
(
metadata
,
LombokExplicitProperties
.
class
,
"explicit"
);
assertSimpleLombokProperties
(
metadata
,
LombokExplicitProperties
.
class
,
"explicit"
);
}
}
@Test
public
void
mergingOfAdditionalMetadata
()
throws
Exception
{
File
metaInfFolder
=
new
File
(
this
.
compiler
.
getOutputLocation
(),
"META-INF"
);
metaInfFolder
.
mkdirs
();
File
additionalMetadataFile
=
new
File
(
metaInfFolder
,
"additional-spring-configuration-metadata.json"
);
additionalMetadataFile
.
createNewFile
();
JSONObject
property
=
new
JSONObject
();
property
.
put
(
"name"
,
"foo"
);
property
.
put
(
"type"
,
"java.lang.String"
);
property
.
put
(
"sourceType"
,
AdditionalMetadata
.
class
.
getName
());
JSONArray
properties
=
new
JSONArray
();
properties
.
put
(
property
);
JSONObject
additionalMetadata
=
new
JSONObject
();
additionalMetadata
.
put
(
"properties"
,
properties
);
FileWriter
writer
=
new
FileWriter
(
additionalMetadataFile
);
additionalMetadata
.
write
(
writer
);
writer
.
flush
();
ConfigurationMetadata
metadata
=
compile
(
SimpleProperties
.
class
);
assertThat
(
metadata
,
containsProperty
(
"simple.comparator"
));
assertThat
(
metadata
,
containsProperty
(
"foo"
,
String
.
class
)
.
fromSource
(
AdditionalMetadata
.
class
));
}
private
void
assertSimpleLombokProperties
(
ConfigurationMetadata
metadata
,
private
void
assertSimpleLombokProperties
(
ConfigurationMetadata
metadata
,
Class
<?>
source
,
String
prefix
)
{
Class
<?>
source
,
String
prefix
)
{
assertThat
(
metadata
,
containsGroup
(
prefix
).
fromSource
(
source
));
assertThat
(
metadata
,
containsGroup
(
prefix
).
fromSource
(
source
));
...
@@ -324,13 +369,13 @@ public class ConfigurationMetadataAnnotationProcessorTests {
...
@@ -324,13 +369,13 @@ public class ConfigurationMetadataAnnotationProcessorTests {
private
ConfigurationMetadata
compile
(
Class
<?>...
types
)
throws
IOException
{
private
ConfigurationMetadata
compile
(
Class
<?>...
types
)
throws
IOException
{
TestConfigurationMetadataAnnotationProcessor
processor
=
new
TestConfigurationMetadataAnnotationProcessor
();
TestConfigurationMetadataAnnotationProcessor
processor
=
new
TestConfigurationMetadataAnnotationProcessor
();
new
TestCompiler
(
this
.
temporaryFolder
)
.
getTask
(
types
).
call
(
processor
);
this
.
compiler
.
getTask
(
types
).
call
(
processor
);
return
processor
.
getMetadata
();
return
processor
.
getMetadata
();
}
}
@SupportedAnnotationTypes
({
"*"
})
@SupportedAnnotationTypes
({
"*"
})
@SupportedSourceVersion
(
SourceVersion
.
RELEASE_6
)
@SupportedSourceVersion
(
SourceVersion
.
RELEASE_6
)
private
static
class
TestConfigurationMetadataAnnotationProcessor
extends
private
class
TestConfigurationMetadataAnnotationProcessor
extends
ConfigurationMetadataAnnotationProcessor
{
ConfigurationMetadataAnnotationProcessor
{
static
final
String
CONFIGURATION_PROPERTIES_ANNOTATION
=
"org.springframework.boot.configurationsample.ConfigurationProperties"
;
static
final
String
CONFIGURATION_PROPERTIES_ANNOTATION
=
"org.springframework.boot.configurationsample.ConfigurationProperties"
;
...
@@ -351,7 +396,23 @@ public class ConfigurationMetadataAnnotationProcessorTests {
...
@@ -351,7 +396,23 @@ public class ConfigurationMetadataAnnotationProcessorTests {
@Override
@Override
protected
void
writeMetaData
(
ConfigurationMetadata
metadata
)
{
protected
void
writeMetaData
(
ConfigurationMetadata
metadata
)
{
this
.
metadata
=
metadata
;
super
.
writeMetaData
(
metadata
);
try
{
File
metadataFile
=
new
File
(
ConfigurationMetadataAnnotationProcessorTests
.
this
.
compiler
.
getOutputLocation
(),
"META-INF/spring-configuration-metadata.json"
);
if
(
metadataFile
.
isFile
())
{
this
.
metadata
=
new
JsonMarshaller
().
read
(
new
FileInputStream
(
metadataFile
));
}
else
{
this
.
metadata
=
metadata
;
}
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"Failed to read metadata from disk"
,
e
);
}
}
}
public
ConfigurationMetadata
getMetadata
()
{
public
ConfigurationMetadata
getMetadata
()
{
...
@@ -360,4 +421,8 @@ public class ConfigurationMetadataAnnotationProcessorTests {
...
@@ -360,4 +421,8 @@ public class ConfigurationMetadataAnnotationProcessorTests {
}
}
private
static
class
AdditionalMetadata
{
}
}
}
spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/TestCompiler.java
View file @
cc221885
/*
/*
* Copyright 2012-201
4
the original author or authors.
* Copyright 2012-201
5
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.
...
@@ -35,6 +35,7 @@ import org.junit.rules.TemporaryFolder;
...
@@ -35,6 +35,7 @@ import org.junit.rules.TemporaryFolder;
*
*
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Phillip Webb
* @author Phillip Webb
* @author Andy Wilkinson
*/
*/
public
class
TestCompiler
{
public
class
TestCompiler
{
...
@@ -42,6 +43,8 @@ public class TestCompiler {
...
@@ -42,6 +43,8 @@ public class TestCompiler {
private
final
StandardJavaFileManager
fileManager
;
private
final
StandardJavaFileManager
fileManager
;
private
final
File
outputLocation
;
public
TestCompiler
(
TemporaryFolder
temporaryFolder
)
throws
IOException
{
public
TestCompiler
(
TemporaryFolder
temporaryFolder
)
throws
IOException
{
this
(
ToolProvider
.
getSystemJavaCompiler
(),
temporaryFolder
);
this
(
ToolProvider
.
getSystemJavaCompiler
(),
temporaryFolder
);
}
}
...
@@ -50,7 +53,8 @@ public class TestCompiler {
...
@@ -50,7 +53,8 @@ public class TestCompiler {
throws
IOException
{
throws
IOException
{
this
.
compiler
=
compiler
;
this
.
compiler
=
compiler
;
this
.
fileManager
=
compiler
.
getStandardFileManager
(
null
,
null
,
null
);
this
.
fileManager
=
compiler
.
getStandardFileManager
(
null
,
null
,
null
);
Iterable
<?
extends
File
>
temp
=
Arrays
.
asList
(
temporaryFolder
.
newFolder
());
this
.
outputLocation
=
temporaryFolder
.
newFolder
();
Iterable
<?
extends
File
>
temp
=
Arrays
.
asList
(
this
.
outputLocation
);
this
.
fileManager
.
setLocation
(
StandardLocation
.
CLASS_OUTPUT
,
temp
);
this
.
fileManager
.
setLocation
(
StandardLocation
.
CLASS_OUTPUT
,
temp
);
this
.
fileManager
.
setLocation
(
StandardLocation
.
SOURCE_OUTPUT
,
temp
);
this
.
fileManager
.
setLocation
(
StandardLocation
.
SOURCE_OUTPUT
,
temp
);
}
}
...
@@ -61,6 +65,10 @@ public class TestCompiler {
...
@@ -61,6 +65,10 @@ public class TestCompiler {
null
,
null
,
null
,
javaFileObjects
));
null
,
null
,
null
,
javaFileObjects
));
}
}
public
File
getOutputLocation
()
{
return
this
.
outputLocation
;
}
private
Iterable
<?
extends
JavaFileObject
>
getJavaFileObjects
(
Class
<?>...
types
)
{
private
Iterable
<?
extends
JavaFileObject
>
getJavaFileObjects
(
Class
<?>...
types
)
{
File
[]
files
=
new
File
[
types
.
length
];
File
[]
files
=
new
File
[
types
.
length
];
for
(
int
i
=
0
;
i
<
types
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
types
.
length
;
i
++)
{
...
...
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