Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 10 additions & 8 deletions .github/workflows/primary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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'
}
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/com/goterl/resourceloader/ResourceLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
29 changes: 18 additions & 11 deletions src/test/java/com/goterl/resourceloader/ResourceLoaderTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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
}
};
}

Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()) {
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/jar with spaces.jar
Binary file modified src/test/resources/shared_libraries/armv6/libsodium.so
Binary file not shown.
Binary file modified src/test/resources/shared_libraries/linux/libsodium.so
Binary file not shown.
Binary file modified src/test/resources/shared_libraries/linux64/libsodium.so
Binary file not shown.
Binary file modified src/test/resources/shared_libraries/mac/libsodium.dylib
Binary file not shown.
Binary file not shown.
Binary file modified src/test/resources/shared_libraries/windows/libsodium.dll
Binary file not shown.
Binary file modified src/test/resources/shared_libraries/windows64/libsodium.dll
Binary file not shown.