Skip to content

Commit

Permalink
HSEARCH-4947 Make sure that nested jars can be read on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-bekhta authored and yrodiere committed Sep 19, 2023
1 parent c628f88 commit 11a84c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ else if ( "file".equals( codeSourceLocation.getProtocol() ) ) {
else {
// The URI points to a regular file, so hopefully an actual JAR file.
// We'll try to open a ZIP filesystem to work on the contents of the JAR file.
URI jarUri = new URI( "jar:file", null, path.toString(), null );
URI jarUri = new URI( "jar:file", null, path.toUri().getPath(), null );
tryInitJarFileSystem( jarUri );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ public void directory() throws Exception {
addSimpleClass( root );
} );

try ( URLClassLoader isolatedClassLoader = createIsolatedClassLoader( dirPath.toUri().toURL() ) ) {
URL dirPathUrl = dirPath.toUri().toURL();
try ( URLClassLoader isolatedClassLoader = createIsolatedClassLoader( dirPathUrl ) ) {
Class<?> classInIsolatedClassLoader = isolatedClassLoader.loadClass( SimpleClass.class.getName() );

// Check preconditions: this is the situation that we want to test.
URL location = classInIsolatedClassLoader.getProtectionDomain().getCodeSource().getLocation();
assertThat( location.getProtocol() ).isEqualTo( "file" );
assertThat( location.toExternalForm() ).contains( dirPath.toString() );
assertThat( location.toExternalForm() ).contains( dirPathUrl.toString() );

// Check that the JAR can be opened and that we can access other files within it
try ( CodeSource codeSource = new CodeSource( location ) ) {
Expand Down Expand Up @@ -86,13 +87,14 @@ public void jar_fileScheme() throws Exception {
addSimpleClass( root );
} );

try ( URLClassLoader isolatedClassLoader = createIsolatedClassLoader( jarPath.toUri().toURL() ) ) {
URL jarPathUrl = jarPath.toUri().toURL();
try ( URLClassLoader isolatedClassLoader = createIsolatedClassLoader( jarPathUrl ) ) {
Class<?> classInIsolatedClassLoader = isolatedClassLoader.loadClass( SimpleClass.class.getName() );

// Check preconditions: this is the situation that we want to test.
URL location = classInIsolatedClassLoader.getProtectionDomain().getCodeSource().getLocation();
assertThat( location.getProtocol() ).isEqualTo( "file" );
assertThat( location.toExternalForm() ).contains( jarPath.toString() );
assertThat( location.toExternalForm() ).contains( jarPathUrl.toString() );

// Check that the JAR can be opened and that we can access other files within it
try ( CodeSource codeSource = new CodeSource( location ) ) {
Expand Down Expand Up @@ -130,7 +132,7 @@ public void jar_jarScheme_classesInRoot() throws Exception {
URL location = classInIsolatedClassLoader.getProtectionDomain().getCodeSource().getLocation();
// For some reason the "jar" scheme gets replaced with "file"
assertThat( location.getProtocol() ).isEqualTo( "file" );
assertThat( location.toExternalForm() ).contains( jarPath.toString() );
assertThat( location.toExternalForm() ).contains( jarPath.toUri().toURL().toString() );

// Check that the JAR can be opened and that we can access other files within it
try ( CodeSource codeSource = new CodeSource( location ) ) {
Expand Down

0 comments on commit 11a84c9

Please sign in to comment.