Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions independent-projects/bootstrap/runner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
<type>pom</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,13 @@ private static class JarResourceURLProvider implements JarFileReference.JarFileC
private static final JarResourceURLProvider INSTANCE = new JarResourceURLProvider();

@Override
public URL apply(JarFile jarFile, Path path, String res) {
JarEntry entry = jarFile.getJarEntry(res);
public URL apply(JarFile jarFile, Path path, String resource) {
JarEntry entry = jarFile.getJarEntry(resource);
if (entry == null) {
return null;
}
try {
String realName = JarEntries.getRealName(entry);
// Avoid ending the URL with / to avoid breaking compatibility
if (realName.endsWith("/")) {
realName = realName.substring(0, realName.length() - 1);
}
final URL resUrl = getUrl(path, realName);
final URL resUrl = getUrl(path, getRealName(entry, resource));
// wrap it up into a "jar" protocol URL
//horrible hack to deal with '?' characters in the URL
//seems to be the only way, the URI constructor just does not let you handle them in a sane way
Expand All @@ -124,6 +119,25 @@ public URL apply(JarFile jarFile, Path path, String res) {
}
}

private static String getRealName(JarEntry entry, String resource) {
String realName = JarEntries.getRealName(entry);
// Make sure directories are returned with a / when the resource was requested with a /
if (resource.endsWith("/") && entry.isDirectory()) {
if (realName.endsWith("/")) {
return realName;
} else {
return realName + "/";
}
}

// this shouldn't be necessary but the previous implementation was doing it forcibly so keeping it for safety
if (realName.endsWith("/")) {
return realName.substring(0, realName.length() - 1);
}

return realName;
}

private static URL getUrl(Path jarPath, String realName) throws MalformedURLException, URISyntaxException {
final URI jarUri = jarPath.toUri();
// first create a URI which includes both the jar file path and the relative resource name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.bootstrap.runner;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.file.Path;
Expand Down Expand Up @@ -98,6 +99,27 @@ public void testConcurrentJarCloseAndReload() throws Exception {
assertTrue(exceptionsInThreads.isEmpty(), "Exceptions in threads: " + exceptionsInThreads);
}

@Test
public void testUrlWithTrailingSlash() {
ClassLoadingResource[] classLoadingResources = new ClassLoadingResource[] {
createProjectJarResource("simple-project-1.0.jar") };

Map<String, ClassLoadingResource[]> resourceDirectoryMap = Map.of(
"org", classLoadingResources,
"org/simple", classLoadingResources);

RunnerClassLoader runnerClassLoader = new RunnerClassLoader(ClassLoader.getSystemClassLoader(), resourceDirectoryMap,
Collections.emptySet(), Collections.emptySet(),
Collections.emptyList(), Collections.emptyMap());

assertThat(runnerClassLoader.findResource("org").toString()).endsWith("/org");
assertThat(runnerClassLoader.findResource("org/").toString()).endsWith("/org/");
assertThat(runnerClassLoader.findResource("org/simple").toString()).endsWith("/org/simple");
assertThat(runnerClassLoader.findResource("org/simple/").toString()).endsWith("/org/simple/");
assertThat(runnerClassLoader.findResource("org/simple/SimplePojo1.class").toString())
.endsWith("/org/simple/SimplePojo1.class");
}

private static JarResource createProjectJarResource(String jarName) {
ManifestInfo manifestInfo = new ManifestInfo(jarName.substring(jarName.lastIndexOf('-')), "1.0", "Apache", null, null,
null);
Expand Down
Loading