Locate additional metadata when using Gradle 4
Closes gh-9758
This commit is contained in:
parent
aedeaa943a
commit
980b83c0d8
|
|
@ -110,18 +110,34 @@ public class MetadataStore {
|
||||||
|
|
||||||
private InputStream getAdditionalMetadataStream() throws IOException {
|
private InputStream getAdditionalMetadataStream() throws IOException {
|
||||||
// Most build systems will have copied the file to the class output location
|
// Most build systems will have copied the file to the class output location
|
||||||
FileObject fileObject = this.environment.getFiler()
|
FileObject fileObject = this.environment.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", ADDITIONAL_METADATA_PATH);
|
||||||
.getResource(StandardLocation.CLASS_OUTPUT, "", ADDITIONAL_METADATA_PATH);
|
|
||||||
File file = new File(fileObject.toUri());
|
File file = new File(fileObject.toUri());
|
||||||
|
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
// 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);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
path = path.substring(0, index) + RESOURCES_FOLDER
|
/*
|
||||||
+ path.substring(index + CLASSES_FOLDER.length());
|
Gradle 4 introduces a new 'java' directory which causes issues for one-to-one path mapping
|
||||||
file = new File(path);
|
of class locations and resources. Ensure resources can be found under '/build/resources/main'
|
||||||
|
rather than '/build/resources/java/main'.
|
||||||
|
*/
|
||||||
|
final String pathBeforeClassFolder = path.substring(0, index);
|
||||||
|
/*
|
||||||
|
In order to retrieve the the class output resource, we MUST pass in a relative path.
|
||||||
|
An empty path causes a InvalidArgumentException as it must be resolvable. In reality,
|
||||||
|
this means nothing since we are going to traverse upstream to its parent to locate
|
||||||
|
the 'main' directory.
|
||||||
|
*/
|
||||||
|
FileObject classOutputLocation = this.environment.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", "dummy");
|
||||||
|
File classesFolder = new File(classOutputLocation.toUri());
|
||||||
|
File resourcesFolder = new File(pathBeforeClassFolder + RESOURCES_FOLDER + '/' + classesFolder.getParentFile().getName());
|
||||||
|
file = new File(resourcesFolder, ADDITIONAL_METADATA_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return (file.exists() ? new FileInputStream(file)
|
return (file.exists() ? new FileInputStream(file)
|
||||||
: fileObject.toUri().toURL().openStream());
|
: fileObject.toUri().toURL().openStream());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue