diff --git a/src/main/java/io/github/classgraph/ClasspathElementModule.java b/src/main/java/io/github/classgraph/ClasspathElementModule.java index 45513732f..2912c0323 100644 --- a/src/main/java/io/github/classgraph/ClasspathElementModule.java +++ b/src/main/java/io/github/classgraph/ClasspathElementModule.java @@ -183,6 +183,20 @@ ClassfileReader openClassfile() throws IOException { return new ClassfileReader(open(), this); } + @Override + public URI getURI() { + try { + ModuleReaderProxy localModuleReaderProxy = moduleReaderProxyRecycler.acquire(); + try { + return localModuleReaderProxy.find(resourcePath); + } finally { + moduleReaderProxyRecycler.recycle(localModuleReaderProxy); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + @Override public InputStream open() throws IOException { if (skipClasspathElement) { diff --git a/src/main/java/io/github/classgraph/ModuleReaderProxy.java b/src/main/java/io/github/classgraph/ModuleReaderProxy.java index 7819fdbf7..f866edec4 100644 --- a/src/main/java/io/github/classgraph/ModuleReaderProxy.java +++ b/src/main/java/io/github/classgraph/ModuleReaderProxy.java @@ -31,6 +31,7 @@ import java.io.Closeable; import java.io.IOException; import java.io.InputStream; +import java.net.URI; import java.nio.ByteBuffer; import java.util.List; @@ -183,4 +184,27 @@ public void release(final ByteBuffer byteBuffer) { reflectionUtils.invokeMethod(/* throwException = */ true, moduleReader, "release", ByteBuffer.class, byteBuffer); } -} \ No newline at end of file + + /** + * Use the proxied ModuleReader to find the named resource as a URI. + * + * @param path + * The path to the resource to open. + * @return A {@link URI} for the resource. + * @throws SecurityException + * If the module cannot be accessed. + */ + public URI find(final String path) { + final Object /* Optional */ optionalURI = reflectionUtils.invokeMethod(/* throwException = */ true, moduleReader, "find", String.class, + path); + if (optionalURI == null) { + throw new IllegalArgumentException("Got null result from ModuleReader#find(String)"); + } + final URI uri = (URI) reflectionUtils.invokeMethod(/* throwException = */ true, + optionalURI, "get"); + if (uri == null) { + throw new IllegalArgumentException("Got null result from ModuleReader#find(String).get()"); + } + return uri; + } +}