diff --git a/.github/workflows/primary.yml b/.github/workflows/primary.yml index 6f651d8..36a0780 100644 --- a/.github/workflows/primary.yml +++ b/.github/workflows/primary.yml @@ -16,11 +16,12 @@ jobs: matrix: os: [macos-latest, windows-latest, ubuntu-latest] steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 + - uses: actions/checkout@v4 + - name: Set up JDK 21 + uses: actions/setup-java@v4 with: - java-version: 1.8 + distribution: 'zulu' + java-version: 21 - name: Test with Gradle run: ./gradlew test publish: @@ -30,12 +31,13 @@ jobs: if: github.ref == 'refs/heads/master' && always() steps: - uses: technote-space/workflow-conclusion-action@v2 - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 if: env.WORKFLOW_CONCLUSION == 'success' - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 + - name: Set up JDK 21 + uses: actions/setup-java@v4 with: - java-version: 1.8 + distribution: 'zulu' + java-version: 21 if: env.WORKFLOW_CONCLUSION == 'success' - name: Import GPG key id: import_gpg diff --git a/build.gradle b/build.gradle index a6d73b9..17bb3a4 100644 --- a/build.gradle +++ b/build.gradle @@ -27,8 +27,8 @@ ext { group project.ext.groupId version = project.ext.version mainClassName = "com.goterl.resourceloader.Main" -sourceCompatibility = JavaVersion.VERSION_19 -targetCompatibility = JavaVersion.VERSION_19 +sourceCompatibility = JavaVersion.VERSION_21 +targetCompatibility = JavaVersion.VERSION_21 repositories { @@ -41,7 +41,7 @@ dependencies { testImplementation "org.assertj:assertj-core:3.27.3" testImplementation "org.testng:testng:7.11.0" - testImplementation "org.mockito:mockito-core:4.1.0" + testImplementation "org.mockito:mockito-core:5.18.0" testImplementation "net.jodah:concurrentunit:0.4.6" testImplementation 'ch.qos.logback:logback-classic:1.5.18' } diff --git a/src/main/java/com/goterl/resourceloader/ResourceLoader.java b/src/main/java/com/goterl/resourceloader/ResourceLoader.java index 345051b..30be667 100644 --- a/src/main/java/com/goterl/resourceloader/ResourceLoader.java +++ b/src/main/java/com/goterl/resourceloader/ResourceLoader.java @@ -191,22 +191,21 @@ private File nestedExtract(File extractTo, String fullPath) throws IOException, */ private boolean isJarFile(URL jarUrl) { if (jarUrl != null) { - String[] split = jarUrl.getPath().split("(\\.jar/)"); - String path; - if (split.length == 1) { - path = jarUrl.getPath(); - } else { - path = split[0] + ".jar"; + String urlString = jarUrl.toString(); + + String[] split = urlString.split("(\\.jar/)"); + if (split.length > 1) { + urlString = split[0] + ".jar"; } - try (JarFile jarFile = new JarFile(path)) { + try (JarFile jarFile = new JarFile(new File(new URL(urlString).toURI()))) { // Successfully opened the jar file. Check if there's a manifest // This is probably not necessary Manifest manifest = jarFile.getManifest(); if (manifest != null) { return true; } - } catch (IOException | IllegalStateException | SecurityException e) { + } catch (IOException | IllegalStateException | SecurityException | URISyntaxException e) { logger.debug("This is not a JAR file due to {}", e.getMessage()); } } diff --git a/src/test/java/com/goterl/resourceloader/ResourceLoaderTest.java b/src/test/java/com/goterl/resourceloader/ResourceLoaderTest.java index 1aea82a..ca600b4 100644 --- a/src/test/java/com/goterl/resourceloader/ResourceLoaderTest.java +++ b/src/test/java/com/goterl/resourceloader/ResourceLoaderTest.java @@ -1,7 +1,5 @@ package com.goterl.resourceloader; -import org.testng.annotations.*; - import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -10,6 +8,10 @@ import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Files; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -65,16 +67,21 @@ public void jarUrlToFileUrlTest(String url, String expect) throws NoSuchMethodEx @DataProvider(name = "isJarFileTestData") public static Object[][] isjars() { String jarUrl = ResourceLoaderTest.class.getResource("/jarinjar.jar").toString(); + String jarUrlWithSpaces = ResourceLoaderTest.class.getResource("/jar with spaces.jar").toString(); String innerJarUrl = jarUrl + "/lazysodium.jar"; return new Object[][] { - { - jarUrl, - true - }, - { - innerJarUrl, - true - } + { + jarUrl, + true + }, + { + jarUrlWithSpaces, + true + }, + { + innerJarUrl, + true + } }; } @@ -83,7 +90,7 @@ public void isJarFileTest(String url, Boolean isJar) throws NoSuchMethodExceptio Method method = ResourceLoader.class.getDeclaredMethod("isJarFile", URL.class); method.setAccessible(true); Object result = method.invoke(new ResourceLoader(), new URL(url)); - assertThat(result).isEqualTo(true); + assertThat(result).isEqualTo(isJar); } @DataProvider(name = "nestedExtractTestData") diff --git a/src/test/java/com/goterl/resourceloader/SharedLibraryLoaderTest.java b/src/test/java/com/goterl/resourceloader/SharedLibraryLoaderTest.java index 6fc3cf4..cd9354f 100644 --- a/src/test/java/com/goterl/resourceloader/SharedLibraryLoaderTest.java +++ b/src/test/java/com/goterl/resourceloader/SharedLibraryLoaderTest.java @@ -47,7 +47,7 @@ public void testLoadingFromJarOrFileSystemParallel() throws TimeoutException, In } }); service.shutdown(); - service.awaitTermination(1, TimeUnit.MINUTES); + service.awaitTermination(30, TimeUnit.SECONDS); // Wait for resume() to be called twice waiter.await(2000, 2); @@ -76,7 +76,11 @@ private boolean verifyLoaded() { private String getLibraryPath() { if (Platform.isMac()) { - return "shared_libraries/mac/libsodium.dylib"; + if (Platform.isARM()) { + return "shared_libraries/mac_arm/libsodium.dylib"; + } else { + return "shared_libraries/mac/libsodium.dylib"; + } } if (Platform.isWindows()) { if (Platform.is64Bit()) { diff --git a/src/test/resources/jar with spaces.jar b/src/test/resources/jar with spaces.jar new file mode 120000 index 0000000..5b654ea --- /dev/null +++ b/src/test/resources/jar with spaces.jar @@ -0,0 +1 @@ +jarinjar.jar \ No newline at end of file diff --git a/src/test/resources/shared_libraries/armv6/libsodium.so b/src/test/resources/shared_libraries/armv6/libsodium.so index 2ea1068..5476d2c 100755 Binary files a/src/test/resources/shared_libraries/armv6/libsodium.so and b/src/test/resources/shared_libraries/armv6/libsodium.so differ diff --git a/src/test/resources/shared_libraries/linux/libsodium.so b/src/test/resources/shared_libraries/linux/libsodium.so index 3a136f9..0d88342 100755 Binary files a/src/test/resources/shared_libraries/linux/libsodium.so and b/src/test/resources/shared_libraries/linux/libsodium.so differ diff --git a/src/test/resources/shared_libraries/linux64/libsodium.so b/src/test/resources/shared_libraries/linux64/libsodium.so index f81d04f..a05e6d2 100755 Binary files a/src/test/resources/shared_libraries/linux64/libsodium.so and b/src/test/resources/shared_libraries/linux64/libsodium.so differ diff --git a/src/test/resources/shared_libraries/mac/libsodium.dylib b/src/test/resources/shared_libraries/mac/libsodium.dylib index 65a0023..22c78cf 100755 Binary files a/src/test/resources/shared_libraries/mac/libsodium.dylib and b/src/test/resources/shared_libraries/mac/libsodium.dylib differ diff --git a/src/test/resources/shared_libraries/mac_arm/libsodium.dylib b/src/test/resources/shared_libraries/mac_arm/libsodium.dylib new file mode 100755 index 0000000..d4f7c1a Binary files /dev/null and b/src/test/resources/shared_libraries/mac_arm/libsodium.dylib differ diff --git a/src/test/resources/shared_libraries/windows/libsodium.dll b/src/test/resources/shared_libraries/windows/libsodium.dll index f279d48..71a36b7 100755 Binary files a/src/test/resources/shared_libraries/windows/libsodium.dll and b/src/test/resources/shared_libraries/windows/libsodium.dll differ diff --git a/src/test/resources/shared_libraries/windows64/libsodium.dll b/src/test/resources/shared_libraries/windows64/libsodium.dll index a6bdc55..47a7089 100755 Binary files a/src/test/resources/shared_libraries/windows64/libsodium.dll and b/src/test/resources/shared_libraries/windows64/libsodium.dll differ