Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ private static String unencodeResourceURIToFilePath(@NotNull final String resour
.decode(resource.replaceAll("\\+", "%2B"), Charsets.UTF_8.name())
.replaceFirst("jar:", "")
.replaceFirst("file:", "")
.replaceFirst("resource:", "")
.replaceAll("!.*", "");
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
Expand Down Expand Up @@ -217,6 +218,8 @@ private String resolveFilesystemPath() {
private String getResourcePath() {
if (path.contains(".jar!")) {
resourcePath = extractClassPathResourceToTempLocation(this.path);
} else if (this.path.startsWith("resource:")) {
this.resourcePath = extractClassPathGraalVMResourceToTempLocation(this.path);
} else {
resourcePath = unencodeResourceURIToFilePath(path);
}
Expand Down Expand Up @@ -270,6 +273,54 @@ private String extractClassPathResourceToTempLocation(final String hostPath) {
}
}

private String extractClassPathGraalVMResourceToTempLocation(String hostPath) {
File tmpLocation = createTempDirectory();
//noinspection ResultOfMethodCallIgnored
tmpLocation.delete();

String urldecodedResourcePath = unencodeResourceURIToFilePath(hostPath);
if (urldecodedResourcePath.startsWith("/")) {
urldecodedResourcePath = urldecodedResourcePath.replaceFirst("/", "");
}

try {
log.debug(
"Copying classpath GraalVM resource(s) from {} to {} to permit Docker to bind",
hostPath,
tmpLocation
);

try (
InputStream is = Thread
.currentThread()
.getContextClassLoader()
.getResourceAsStream(urldecodedResourcePath)
) {
if (is == null) {
throw new IllegalStateException(
urldecodedResourcePath +
" not found in classpath, probably need to update GraalVM's reachability-metadata.json"
);
}
Files.copy(is, tmpLocation.toPath());
}
} catch (IOException e) {
throw new IllegalStateException(
"Failed to process GraalVM file when extracting classpath resource: " + hostPath,
e
);
}

// Mark temporary files/dirs for deletion at JVM shutdown
deleteOnExit(tmpLocation.toPath());

try {
return tmpLocation.getCanonicalPath();
} catch (IOException e) {
throw new IllegalStateException(e);
}
}

private File createTempDirectory() {
try {
if (SystemUtils.IS_OS_MAC) {
Expand Down
Loading