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
8b53ff45
Commit
8b53ff45
authored
Jul 25, 2017
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x'
parents
484aac61
853cd2a0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
115 additions
and
11 deletions
+115
-11
MetadataStore.java
...gframework/boot/configurationprocessor/MetadataStore.java
+24
-11
MetadataStoreTests.java
...ework/boot/configurationprocessor/MetadataStoreTests.java
+91
-0
No files found.
spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/MetadataStore.java
View file @
8b53ff45
...
...
@@ -18,6 +18,7 @@ package org.springframework.boot.configurationprocessor;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
...
...
@@ -109,19 +110,31 @@ public class MetadataStore {
// Most build systems will have copied the file to the class output location
FileObject
fileObject
=
this
.
environment
.
getFiler
()
.
getResource
(
StandardLocation
.
CLASS_OUTPUT
,
""
,
ADDITIONAL_METADATA_PATH
);
File
file
=
new
File
(
fileObject
.
toUri
());
if
(!
file
.
exists
())
{
// Gradle keeps things separate
String
path
=
file
.
getPath
();
int
index
=
path
.
lastIndexOf
(
CLASSES_FOLDER
);
if
(
index
>=
0
)
{
path
=
path
.
substring
(
0
,
index
)
+
RESOURCES_FOLDER
+
path
.
substring
(
index
+
CLASSES_FOLDER
.
length
());
file
=
new
File
(
path
);
}
}
File
file
=
locateAdditionalMetadataFile
(
new
File
(
fileObject
.
toUri
()));
return
(
file
.
exists
()
?
new
FileInputStream
(
file
)
:
fileObject
.
toUri
().
toURL
().
openStream
());
}
File
locateAdditionalMetadataFile
(
File
standardLocation
)
throws
IOException
{
if
(
standardLocation
.
exists
())
{
return
standardLocation
;
}
return
new
File
(
locateGradleResourcesFolder
(
standardLocation
),
ADDITIONAL_METADATA_PATH
);
}
private
File
locateGradleResourcesFolder
(
File
standardAdditionalMetadataLocation
)
throws
FileNotFoundException
{
String
path
=
standardAdditionalMetadataLocation
.
getPath
();
int
index
=
path
.
lastIndexOf
(
CLASSES_FOLDER
);
if
(
index
<
0
)
{
throw
new
FileNotFoundException
();
}
String
buildFolderPath
=
path
.
substring
(
0
,
index
);
File
classOutputLocation
=
standardAdditionalMetadataLocation
.
getParentFile
()
.
getParentFile
();
return
new
File
(
buildFolderPath
,
RESOURCES_FOLDER
+
'/'
+
classOutputLocation
.
getName
());
}
}
spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/MetadataStoreTests.java
0 → 100644
View file @
8b53ff45
/*
* Copyright 2012-2017 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
*
* http://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
.
configurationprocessor
;
import
java.io.File
;
import
java.io.IOException
;
import
javax.annotation.processing.ProcessingEnvironment
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.rules.TemporaryFolder
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
* Tests for {@link MetadataStore}.
*
* @author Andy Wilkinson
*/
public
class
MetadataStoreTests
{
@Rule
public
final
TemporaryFolder
temp
=
new
TemporaryFolder
();
private
final
MetadataStore
metadataStore
=
new
MetadataStore
(
mock
(
ProcessingEnvironment
.
class
));
@Test
public
void
additionalMetadataIsLocatedInMavenBuild
()
throws
IOException
{
File
app
=
this
.
temp
.
newFolder
(
"app"
);
File
classesLocation
=
new
File
(
app
,
"target/classes"
);
File
metaInf
=
new
File
(
classesLocation
,
"META-INF"
);
metaInf
.
mkdirs
();
File
additionalMetadata
=
new
File
(
metaInf
,
"additional-spring-configuration-metadata.json"
);
additionalMetadata
.
createNewFile
();
assertThat
(
this
.
metadataStore
.
locateAdditionalMetadataFile
(
new
File
(
classesLocation
,
"META-INF/additional-spring-configuration-metadata.json"
)))
.
isEqualTo
(
additionalMetadata
);
}
@Test
public
void
additionalMetadataIsLocatedInGradle3Build
()
throws
IOException
{
File
app
=
this
.
temp
.
newFolder
(
"app"
);
File
classesLocation
=
new
File
(
app
,
"build/classes/main"
);
File
resourcesLocation
=
new
File
(
app
,
"build/resources/main"
);
File
metaInf
=
new
File
(
resourcesLocation
,
"META-INF"
);
metaInf
.
mkdirs
();
File
additionalMetadata
=
new
File
(
metaInf
,
"additional-spring-configuration-metadata.json"
);
additionalMetadata
.
createNewFile
();
assertThat
(
this
.
metadataStore
.
locateAdditionalMetadataFile
(
new
File
(
classesLocation
,
"META-INF/additional-spring-configuration-metadata.json"
)))
.
isEqualTo
(
additionalMetadata
);
}
@Test
public
void
additionalMetadataIsLocatedInGradle4Build
()
throws
IOException
{
File
app
=
this
.
temp
.
newFolder
(
"app"
);
File
classesLocation
=
new
File
(
app
,
"build/classes/java/main"
);
File
resourcesLocation
=
new
File
(
app
,
"build/resources/main"
);
File
metaInf
=
new
File
(
resourcesLocation
,
"META-INF"
);
metaInf
.
mkdirs
();
File
additionalMetadata
=
new
File
(
metaInf
,
"additional-spring-configuration-metadata.json"
);
additionalMetadata
.
createNewFile
();
assertThat
(
this
.
metadataStore
.
locateAdditionalMetadataFile
(
new
File
(
classesLocation
,
"META-INF/additional-spring-configuration-metadata.json"
)))
.
isEqualTo
(
additionalMetadata
);
}
}
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