This commit is contained in:
@@ -8,7 +8,8 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- uses: actions/setup-java@v4
|
- name: Setup Java
|
||||||
|
uses: actions/setup-java@v4
|
||||||
with:
|
with:
|
||||||
distribution: graalvm
|
distribution: graalvm
|
||||||
java-version: 21
|
java-version: 21
|
||||||
|
@@ -27,6 +27,7 @@ allprojects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
testRuntimeOnly project(':jwo-test-module')
|
||||||
testImplementation catalog.junit.jupiter.api
|
testImplementation catalog.junit.jupiter.api
|
||||||
testImplementation catalog.junit.jupiter.params
|
testImplementation catalog.junit.jupiter.params
|
||||||
testRuntimeOnly catalog.junit.jupiter.engine
|
testRuntimeOnly catalog.junit.jupiter.engine
|
||||||
@@ -97,7 +98,6 @@ ext {
|
|||||||
setProperty('jpms.module.name', 'net.woggioni.jwo')
|
setProperty('jpms.module.name', 'net.woggioni.jwo')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
pathClassloaderTest
|
pathClassloaderTest
|
||||||
zipTestBundle {
|
zipTestBundle {
|
||||||
@@ -144,5 +144,3 @@ test {
|
|||||||
'--add-opens', 'java.base/sun.nio.fs=ALL-UNNAMED',
|
'--add-opens', 'java.base/sun.nio.fs=ALL-UNNAMED',
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -3,6 +3,6 @@ org.gradle.parallel=true
|
|||||||
org.gradle.caching=true
|
org.gradle.caching=true
|
||||||
|
|
||||||
gitea.maven.url = https://gitea.woggioni.net/api/packages/woggioni/maven
|
gitea.maven.url = https://gitea.woggioni.net/api/packages/woggioni/maven
|
||||||
jwo.version = 2024.12.31
|
jwo.version = 2025.01.09
|
||||||
lys.version = 2024.12.28
|
lys.version = 2025.01.08
|
||||||
guice.version = 5.0.1
|
guice.version = 5.0.1
|
||||||
|
7
jwo-test-module/build.gradle
Normal file
7
jwo-test-module/build.gradle
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java-library'
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
modularity.inferModulePath = true
|
||||||
|
}
|
3
jwo-test-module/src/main/java/module-info.java
Normal file
3
jwo-test-module/src/main/java/module-info.java
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
open module net.woggioni.jwo.test.module {
|
||||||
|
exports my.test.resource;
|
||||||
|
}
|
4
jwo-test-module/src/main/java/my/test/resource/Foo.java
Normal file
4
jwo-test-module/src/main/java/my/test/resource/Foo.java
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
package my.test.resource;
|
||||||
|
|
||||||
|
public class Foo {
|
||||||
|
}
|
@@ -0,0 +1 @@
|
|||||||
|
test
|
31
jwo-test/build.gradle
Normal file
31
jwo-test/build.gradle
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java-library'
|
||||||
|
alias(catalog.plugins.lombok)
|
||||||
|
}
|
||||||
|
|
||||||
|
import org.gradle.api.attributes.LibraryElements
|
||||||
|
import static org.gradle.api.attributes.LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE
|
||||||
|
import static org.gradle.api.attributes.LibraryElements.JAR
|
||||||
|
|
||||||
|
configurations {
|
||||||
|
testImplementation {
|
||||||
|
attributes {
|
||||||
|
attribute(LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements.class, JAR))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
testRuntimeClasspath {
|
||||||
|
attributes {
|
||||||
|
attribute(LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements.class, JAR))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
modularity.inferModulePath = true
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
testImplementation project(':jwo-test-module')
|
||||||
|
testImplementation project(':')
|
||||||
|
}
|
6
jwo-test/src/test/java/module-info.java
Normal file
6
jwo-test/src/test/java/module-info.java
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
open module net.woggioni.jwo.unit.test {
|
||||||
|
requires net.woggioni.jwo;
|
||||||
|
requires net.woggioni.jwo.test.module;
|
||||||
|
requires org.junit.jupiter.api;
|
||||||
|
requires static lombok;
|
||||||
|
}
|
@@ -0,0 +1,29 @@
|
|||||||
|
package net.woggioni.jwo.test;
|
||||||
|
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import net.woggioni.jwo.JWO;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
public class JpmsUrlTest {
|
||||||
|
@Test
|
||||||
|
@SneakyThrows
|
||||||
|
public void test() {
|
||||||
|
JWO.registerUrlProtocolHandler();
|
||||||
|
final var module = getClass().getModule();
|
||||||
|
final var url = new URL("jpms://net.woggioni.jwo.test.module/my/test/resource/file.txt");
|
||||||
|
System.out.println(module.getName());
|
||||||
|
System.out.println(url.getHost());
|
||||||
|
System.out.println(url.getPath());
|
||||||
|
final var baos = new ByteArrayOutputStream();
|
||||||
|
try(final var is = url.openConnection().getInputStream()) {
|
||||||
|
JWO.copy(is, baos);
|
||||||
|
}
|
||||||
|
final var content = baos.toString(StandardCharsets.UTF_8);
|
||||||
|
Assertions.assertEquals("test", content);
|
||||||
|
}
|
||||||
|
}
|
@@ -25,6 +25,8 @@ dependencyResolutionManagement {
|
|||||||
|
|
||||||
rootProject.name = 'jwo'
|
rootProject.name = 'jwo'
|
||||||
|
|
||||||
include('benchmark')
|
include 'benchmark'
|
||||||
include('jmath')
|
include 'jmath'
|
||||||
include('jmath-benchmark')
|
include 'jmath-benchmark'
|
||||||
|
include 'jwo-test'
|
||||||
|
include 'jwo-test-module'
|
@@ -1,6 +1,7 @@
|
|||||||
package net.woggioni.jwo;
|
package net.woggioni.jwo;
|
||||||
|
|
||||||
import java.io.FilterOutputStream;
|
import java.io.FilterOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -14,6 +15,7 @@ public class UncloseableOutputStream extends FilterOutputStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() throws IOException {
|
||||||
|
flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,5 +10,7 @@ public class UncloseableWriter extends FilterWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {}
|
public void close() throws IOException {
|
||||||
|
flush();
|
||||||
|
}
|
||||||
}
|
}
|
@@ -7,5 +7,6 @@ module net.woggioni.jwo {
|
|||||||
exports net.woggioni.jwo;
|
exports net.woggioni.jwo;
|
||||||
exports net.woggioni.jwo.exception;
|
exports net.woggioni.jwo.exception;
|
||||||
exports net.woggioni.jwo.url.classpath;
|
exports net.woggioni.jwo.url.classpath;
|
||||||
|
exports net.woggioni.jwo.url.jpms;
|
||||||
exports net.woggioni.jwo.xml;
|
exports net.woggioni.jwo.xml;
|
||||||
}
|
}
|
52
src/main/java9/net/woggioni/jwo/url/jpms/Handler.java
Normal file
52
src/main/java9/net/woggioni/jwo/url/jpms/Handler.java
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
package net.woggioni.jwo.url.jpms;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.lang.Module;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.net.URLStreamHandler;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class Handler extends URLStreamHandler {
|
||||||
|
private final ClassLoader classLoader;
|
||||||
|
|
||||||
|
public Handler() {
|
||||||
|
this.classLoader = getClass().getClassLoader();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Handler(ClassLoader classLoader) {
|
||||||
|
this.classLoader = classLoader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected URLConnection openConnection(URL u) throws IOException {
|
||||||
|
final Module thisModule = getClass().getModule();
|
||||||
|
final Module sourceModule = Optional.ofNullable(thisModule)
|
||||||
|
.map(Module::getLayer)
|
||||||
|
.flatMap(layer -> {
|
||||||
|
final String moduleName = u.getHost();
|
||||||
|
return layer.findModule(moduleName);
|
||||||
|
}).orElse(thisModule);
|
||||||
|
return new ModuleResourceURLConnection(u, sourceModule);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ModuleResourceURLConnection extends URLConnection {
|
||||||
|
private final Module module;
|
||||||
|
|
||||||
|
private ModuleResourceURLConnection(URL url, Module module) {
|
||||||
|
super(url);
|
||||||
|
this.module = module;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connect() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream getInputStream() throws IOException {
|
||||||
|
return module.getResourceAsStream(getURL().getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
26
src/test/java/net/woggioni/jwo/url/JpmsUrlTest.java
Normal file
26
src/test/java/net/woggioni/jwo/url/JpmsUrlTest.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package net.woggioni.jwo.url;
|
||||||
|
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import net.woggioni.jwo.JWO;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
public class JpmsUrlTest {
|
||||||
|
@Test
|
||||||
|
@SneakyThrows
|
||||||
|
public void test() {
|
||||||
|
JWO.registerUrlProtocolHandler();
|
||||||
|
final var module = getClass().getModule();
|
||||||
|
final var url = new URL("jpms://net.woggioni.jwo.test.module/my/test/resource/file.txt");
|
||||||
|
final var baos = new ByteArrayOutputStream();
|
||||||
|
try(final var is = url.openConnection().getInputStream()) {
|
||||||
|
JWO.copy(is, baos);
|
||||||
|
}
|
||||||
|
final var content = baos.toString(StandardCharsets.UTF_8);
|
||||||
|
Assertions.assertEquals("test", content);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user