fixed issue with URL stream handler

This commit is contained in:
2022-08-05 15:13:42 +08:00
parent 3f4c5f52e8
commit 40bd8e71bd
7 changed files with 26 additions and 7 deletions

View File

@@ -3,7 +3,7 @@ publishMavenRepositoryUrl=https://mvn.woggioni.net/
lys-gradle-plugins.version = 2022.06 lys-gradle-plugins.version = 2022.06
version.envelope=2022.06 version.envelope=2022.08
version.gradle=7.5 version.gradle=7.5
version.lombok=1.18.22 version.lombok=1.18.22
version.junitJupiter=5.7.2 version.junitJupiter=5.7.2

View File

@@ -59,6 +59,7 @@ public class Launcher {
@SneakyThrows @SneakyThrows
public static void main(String[] args) { public static void main(String[] args) {
Enumeration<URL> it = Launcher.class.getClassLoader().getResources(Constants.SYSTEM_PROPERTIES_FILE); Enumeration<URL> it = Launcher.class.getClassLoader().getResources(Constants.SYSTEM_PROPERTIES_FILE);
JarFile.registerUrlProtocolHandler();
while (it.hasMoreElements()) { while (it.hasMoreElements()) {
URL url = it.nextElement(); URL url = it.nextElement();
Properties properties = new Properties(); Properties properties = new Properties();

View File

@@ -38,7 +38,7 @@ import java.util.regex.Pattern;
* @since 1.0.0 * @since 1.0.0
* @see JarFile#registerUrlProtocolHandler() * @see JarFile#registerUrlProtocolHandler()
*/ */
public class Handler extends URLStreamHandler { public abstract class AbstractHandler extends URLStreamHandler {
// NOTE: in order to be found as a URL protocol handler, this class must be public, // NOTE: in order to be found as a URL protocol handler, this class must be public,
// must be named Handler and must be in a package ending '.jar' // must be named Handler and must be in a package ending '.jar'
@@ -75,11 +75,11 @@ public class Handler extends URLStreamHandler {
private URLStreamHandler fallbackHandler; private URLStreamHandler fallbackHandler;
public Handler() { public AbstractHandler() {
this(null); this(null);
} }
public Handler(JarFile jarFile) { public AbstractHandler(JarFile jarFile) {
this.jarFile = jarFile; this.jarFile = jarFile;
} }

View File

@@ -16,6 +16,8 @@
package net.woggioni.envelope.loader; package net.woggioni.envelope.loader;
import net.woggioni.envelope.loader.jar.Handler;
import java.io.File; import java.io.File;
import java.io.FilePermission; import java.io.FilePermission;
import java.io.IOException; import java.io.IOException;
@@ -60,7 +62,7 @@ public class JarFile extends AbstractJarFile implements Iterable<java.util.jar.J
private static final String PROTOCOL_HANDLER = "java.protocol.handler.pkgs"; private static final String PROTOCOL_HANDLER = "java.protocol.handler.pkgs";
private static final String HANDLERS_PACKAGE = "net.woggioni.xclassloader.jar"; private static final String HANDLERS_PACKAGE = "net.woggioni.envelope.loader";
private static final Bytes.AsciiBytes META_INF = new Bytes.AsciiBytes("META-INF/"); private static final Bytes.AsciiBytes META_INF = new Bytes.AsciiBytes("META-INF/");
@@ -444,7 +446,7 @@ public class JarFile extends AbstractJarFile implements Iterable<java.util.jar.J
* {@link URLStreamHandler} will be located to deal with jar URLs. * {@link URLStreamHandler} will be located to deal with jar URLs.
*/ */
public static void registerUrlProtocolHandler() { public static void registerUrlProtocolHandler() {
Handler.captureJarContextUrl(); AbstractHandler.captureJarContextUrl();
String handlers = System.getProperty(PROTOCOL_HANDLER, ""); String handlers = System.getProperty(PROTOCOL_HANDLER, "");
System.setProperty(PROTOCOL_HANDLER, System.setProperty(PROTOCOL_HANDLER,
((handlers == null || handlers.isEmpty()) ? HANDLERS_PACKAGE : handlers + "|" + HANDLERS_PACKAGE)); ((handlers == null || handlers.isEmpty()) ? HANDLERS_PACKAGE : handlers + "|" + HANDLERS_PACKAGE));

View File

@@ -0,0 +1,15 @@
package net.woggioni.envelope.loader.jar;
import net.woggioni.envelope.loader.AbstractHandler;
import net.woggioni.envelope.loader.JarFile;
public class Handler extends AbstractHandler {
public Handler() {
super();
}
public Handler(JarFile jarFile) {
super(jarFile);
}
}

View File

@@ -2,4 +2,5 @@ module net.woggioni.envelope.loader {
requires java.logging; requires java.logging;
requires static lombok; requires static lombok;
exports net.woggioni.envelope.loader; exports net.woggioni.envelope.loader;
exports net.woggioni.envelope.loader.jar;
} }

View File

@@ -2,7 +2,7 @@ package net.woggioni.envelope.loader;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import net.woggioni.envelope.loader.JarFile; import net.woggioni.envelope.loader.JarFile;
import net.woggioni.envelope.loader.Handler; import net.woggioni.envelope.loader.jar.Handler;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;