[jOOQ/jOOQ#11637] FilePattern cannot load classpath resource from within jar file

This commit is contained in:
Lukas Eder 2022-01-06 17:17:19 +01:00
parent 1e6a5c6ee3
commit 32734700f3

View File

@ -41,7 +41,7 @@ import static java.util.Comparator.naturalOrder;
import static org.jooq.FilePattern.Sort.SEMANTIC;
import java.io.File;
import java.net.URISyntaxException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
@ -224,8 +224,14 @@ public final class FilePattern {
if (url != null) {
log.info("Reading from classpath: " + pattern);
load0(new File(url.toURI()), loader);
loaded = true;
// [#11637] Avoid working with File to support classpath resources
// inside of nested jar files.
try (InputStream is = FilePattern.class.getResourceAsStream(pattern)) {
// Cannot accept a Source based on an InputStream if using FilePattern::collect
loader.accept(Source.of(Source.of(is).readString()));
loaded = true;
}
}
else {
file = new File(pattern);
@ -253,11 +259,6 @@ public final class FilePattern {
}
}
}
// It is quite unlikely that a classpath URL doesn't produce a valid URI
catch (URISyntaxException e) {
throw new RuntimeException(e);
}
catch (java.io.IOException e) {
throw new IOException("Error while loading pattern", e);
}