Skip to content

Commit

Permalink
- Fixed separators to also work on Windows (#2233)
Browse files Browse the repository at this point in the history
- Added missing `--add-opens=java.base/java.security=ALL-UNNAMED`
 - Added proper closing of AddonClassLoader
  • Loading branch information
Baterka authored Nov 25, 2023
1 parent 5de7302 commit 13c339e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
22 changes: 8 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -371,29 +371,23 @@
--add-opens java.base/java.math=ALL-UNNAMED
--add-opens java.base/java.io=ALL-UNNAMED
--add-opens java.base/java.util=ALL-UNNAMED
--add-opens
java.base/java.util.stream=ALL-UNNAMED
--add-opens java.base/java.util.stream=ALL-UNNAMED
--add-opens java.base/java.text=ALL-UNNAMED
--add-opens
java.base/java.util.regex=ALL-UNNAMED
--add-opens
java.base/java.nio.channels.spi=ALL-UNNAMED
--add-opens java.base/java.util.regex=ALL-UNNAMED
--add-opens java.base/java.nio.channels.spi=ALL-UNNAMED
--add-opens java.base/sun.nio.ch=ALL-UNNAMED
--add-opens java.base/java.net=ALL-UNNAMED
--add-opens
java.base/java.util.concurrent=ALL-UNNAMED
--add-opens java.base/java.util.concurrent=ALL-UNNAMED
--add-opens java.base/sun.nio.fs=ALL-UNNAMED
--add-opens java.base/sun.nio.cs=ALL-UNNAMED
--add-opens java.base/java.nio.file=ALL-UNNAMED
--add-opens
java.base/java.nio.charset=ALL-UNNAMED
--add-opens
java.base/java.lang.reflect=ALL-UNNAMED
--add-opens
java.logging/java.util.logging=ALL-UNNAMED
--add-opens java.base/java.nio.charset=ALL-UNNAMED
--add-opens java.base/java.lang.reflect=ALL-UNNAMED
--add-opens java.logging/java.util.logging=ALL-UNNAMED
--add-opens java.base/java.lang.ref=ALL-UNNAMED
--add-opens java.base/java.util.jar=ALL-UNNAMED
--add-opens java.base/java.util.zip=ALL-UNNAMED
--add-opens=java.base/java.security=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/world/bentobox/bentobox/api/addons/Addon.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public File saveResource(String jarResource, File destinationFolder, boolean rep
throw new IllegalArgumentException("ResourcePath cannot be null or empty");
}

jarResource = jarResource.replace('\\', '/');
jarResource = jarResource.replace("\\", File.separator).replace("/", File.separator);
try (JarFile jar = new JarFile(file)) {
JarEntry jarConfig = jar.getJarEntry(jarResource);
if (jarConfig != null) {
Expand Down Expand Up @@ -308,7 +308,7 @@ public YamlConfiguration getYamlFromJar(String jarResource) throws IOException,
throw new IllegalArgumentException("jarResource cannot be null or empty");
}
YamlConfiguration result = new YamlConfiguration();
jarResource = jarResource.replace('\\', '/');
jarResource = jarResource.replace("\\", File.separator).replace("/", File.separator);
try (JarFile jar = new JarFile(file)) {
JarEntry jarConfig = jar.getJarEntry(jarResource);
if (jarConfig != null) {
Expand All @@ -330,7 +330,7 @@ public InputStream getResource(String jarResource) {
throw new IllegalArgumentException("ResourcePath cannot be null or empty");
}

jarResource = jarResource.replace('\\', '/');
jarResource = jarResource.replace("\\", File.separator).replace("/", File.separator);
try (JarFile jar = new JarFile(file)) {
JarEntry jarConfig = jar.getJarEntry(jarResource);
if (jarConfig != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,40 +300,44 @@ public void testAsDescriptionUnknownIconMaterial() {
* Test method for {@link world.bentobox.bentobox.api.addons.AddonClassLoader#findClass(java.lang.String)}.
*/
@Test
public void testFindClassString() throws MalformedURLException {
public void testFindClassString() throws IOException {
acl = new AddonClassLoader(testAddon, am, jarFile);
assertNull(acl.findClass(""));
assertNull(acl.findClass("world.bentobox.bentobox"));
acl.close();
}

/**
* Test method for {@link world.bentobox.bentobox.api.addons.AddonClassLoader#findClass(java.lang.String, boolean)}.
*/
@Test
public void testFindClassStringBoolean() throws MalformedURLException {
public void testFindClassStringBoolean() throws IOException {
acl = new AddonClassLoader(testAddon, am, jarFile);
assertNull(acl.findClass("", false));
assertNull(acl.findClass("world.bentobox.bentobox", false));
acl.close();
}

/**
* Test method for {@link world.bentobox.bentobox.api.addons.AddonClassLoader#getAddon()}.
*/
@Test
public void testGetAddon() throws MalformedURLException {
public void testGetAddon() throws IOException {
acl = new AddonClassLoader(testAddon, am, jarFile);
Addon addon = acl.getAddon();
assertEquals(addon, testAddon);
acl.close();
}

/**
* Test method for {@link world.bentobox.bentobox.api.addons.AddonClassLoader#getClasses()}.
*/
@Test
public void testGetClasses() throws MalformedURLException {
public void testGetClasses() throws IOException {
acl = new AddonClassLoader(testAddon, am, jarFile);
Set<String> set = acl.getClasses();
assertTrue(set.isEmpty());
acl.close();
}

}

0 comments on commit 13c339e

Please sign in to comment.