Skip to content

Commit 51e22ab

Browse files
committed
Make ResourceURLConnection module aware
1 parent 12869fc commit 51e22ab

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Resources.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,11 @@ public static ResourceStorageEntry get(String moduleName, String resourceName) {
159159
return singleton().resources.get(Pair.create(moduleName, resourceName));
160160
}
161161

162-
private static URL createURL(String resourceName, int index) {
162+
private static URL createURL(String moduleName, String resourceName, int index) {
163163
try {
164-
return new URL(JavaNetSubstitutions.RESOURCE_PROTOCOL, null, -1, resourceName,
164+
String moduleNameNonNull = moduleName == null ? "" : moduleName;
165+
String filePart = moduleNameNonNull + ResourceURLConnection.MODULENAME_SEPARATOR + resourceName;
166+
return new URL(JavaNetSubstitutions.RESOURCE_PROTOCOL, null, -1, filePart,
165167
new URLStreamHandler() {
166168
@Override
167169
protected URLConnection openConnection(URL url) {
@@ -222,7 +224,7 @@ public static Enumeration<URL> createURLs(String moduleName, String resourceName
222224
int numberOfResources = entry.getData().size();
223225
List<URL> resourcesURLs = new ArrayList<>(numberOfResources);
224226
for (int index = 0; index < numberOfResources; index++) {
225-
resourcesURLs.add(createURL(canonicalResourceName, index));
227+
resourcesURLs.add(createURL(moduleName, canonicalResourceName, index));
226228
}
227229
return Collections.enumeration(resourcesURLs);
228230
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/resources/ResourceURLConnection.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
public class ResourceURLConnection extends URLConnection {
3939

40+
public static final char MODULENAME_SEPARATOR = '!';
41+
4042
private final URL url;
4143
private final int index;
4244
private byte[] data;
@@ -51,19 +53,19 @@ public ResourceURLConnection(URL url, int index) {
5153
this.index = index;
5254
}
5355

54-
private static String resolveName(String resourceName) {
55-
return resourceName.startsWith("/") ? resourceName.substring(1) : resourceName;
56-
}
57-
5856
@Override
5957
public void connect() {
6058
if (connected) {
6159
return;
6260
}
6361
connected = true;
64-
65-
String resourceName = resolveName(url.getPath());
66-
ResourceStorageEntry entry = Resources.get(Resources.toCanonicalForm(resourceName));
62+
String moduleNameResourcePath = url.getPath();
63+
int separatorPos = moduleNameResourcePath.indexOf(MODULENAME_SEPARATOR);
64+
String moduleName = moduleNameResourcePath.substring(0, separatorPos);
65+
String resourcePath = moduleNameResourcePath.substring(separatorPos + 1);
66+
String strippedResourcePath = resourcePath.startsWith("/") ? resourcePath.substring(1) : resourcePath;
67+
String canonicalForm = Resources.toCanonicalForm(strippedResourcePath);
68+
ResourceStorageEntry entry = Resources.get(moduleName.isEmpty() ? null : moduleName, canonicalForm);
6769
if (entry != null) {
6870
List<byte[]> bytes = entry.getData();
6971
if (index < bytes.size()) {

0 commit comments

Comments
 (0)