Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Quafadas committed Jan 23, 2024
1 parent 50a18ee commit 176e9bd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tests/jvm/src/test/scala/DriverJar.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,12 @@ public static URI getDriverResourceURI() throws URISyntaxException {
return classloader.getResource("driver/" + platformDir()).toURI();
}


void extractDriverToTempDir() throws URISyntaxException, IOException {
URI originalUri = getDriverResourceURI();
URI uri = maybeExtractNestedJar(originalUri);

@SuppressWarnings("resource")
// Create zip filesystem if loading from jar.
try (FileSystem fileSystem = "jar".equals(uri.getScheme()) ? initFileSystem(uri) : null) {
Path srcRoot = Paths.get(uri);
Expand Down Expand Up @@ -163,6 +165,7 @@ void extractDriverToTempDir() throws URISyntaxException, IOException {
}
}


private URI maybeExtractNestedJar(final URI uri) throws URISyntaxException {
if (!"jar".equals(uri.getScheme())) {
return uri;
Expand All @@ -174,14 +177,16 @@ private URI maybeExtractNestedJar(final URI uri) throws URISyntaxException {
}
String innerJar = String.join(JAR_URL_SEPARATOR, parts[0], parts[1]);
URI jarUri = new URI(innerJar);

@SuppressWarnings("resource")
try (FileSystem fs = FileSystems.newFileSystem(jarUri, Collections.emptyMap())) {
Path fromPath = Paths.get(jarUri);
Path toPath = driverTempDir.resolve(fromPath.getFileName().toString());
Files.copy(fromPath, toPath);
toPath.toFile().deleteOnExit();
return new URI("jar:" + toPath.toUri() + JAR_URL_SEPARATOR + parts[2]);
} catch (IOException e) {
fs.close();
//fs.close();
throw new RuntimeException("Failed to extract driver's nested .jar from " + jarUri + "; full uri: " + uri, e);
}
}
Expand Down

0 comments on commit 176e9bd

Please sign in to comment.