Fix PropertiesLauncher classpath detection without 'loader.path' set
Update `PropertiesLauncher` to restore classpath detection logic applied when no `loader.path` property is set. Fixes gh-37992
This commit is contained in:
@@ -38,11 +38,7 @@ public class JarLauncher extends ExecutableArchiveLauncher {
|
||||
|
||||
@Override
|
||||
protected boolean isIncludedOnClassPath(Archive.Entry entry) {
|
||||
String name = entry.name();
|
||||
if (entry.isDirectory()) {
|
||||
return name.equals("BOOT-INF/classes/");
|
||||
}
|
||||
return name.startsWith("BOOT-INF/lib/");
|
||||
return isLibraryFileOrClassesDirectory(entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,6 +46,14 @@ public class JarLauncher extends ExecutableArchiveLauncher {
|
||||
return "BOOT-INF/";
|
||||
}
|
||||
|
||||
static boolean isLibraryFileOrClassesDirectory(Archive.Entry entry) {
|
||||
String name = entry.name();
|
||||
if (entry.isDirectory()) {
|
||||
return name.equals("BOOT-INF/classes/");
|
||||
}
|
||||
return name.startsWith("BOOT-INF/lib/");
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new JarLauncher().launch(args);
|
||||
}
|
||||
|
||||
@@ -140,7 +140,11 @@ public class PropertiesLauncher extends Launcher {
|
||||
private final Properties properties = new Properties();
|
||||
|
||||
public PropertiesLauncher() throws Exception {
|
||||
this.archive = Archive.create(Launcher.class);
|
||||
this(Archive.create(Launcher.class));
|
||||
}
|
||||
|
||||
PropertiesLauncher(Archive archive) throws Exception {
|
||||
this.archive = archive;
|
||||
this.homeDirectory = getHomeDirectory();
|
||||
initializeProperties();
|
||||
this.paths = getPaths();
|
||||
@@ -464,6 +468,8 @@ public class PropertiesLauncher extends Launcher {
|
||||
path = cleanupPath(handleUrl(path));
|
||||
urls.addAll(getClassPathUrlsForPath(path));
|
||||
}
|
||||
urls.addAll(getClassPathUrlsForRoot());
|
||||
debug.log("Using class path URLs %s", urls);
|
||||
return urls;
|
||||
}
|
||||
|
||||
@@ -531,6 +537,11 @@ public class PropertiesLauncher extends Launcher {
|
||||
}
|
||||
}
|
||||
|
||||
private Set<URL> getClassPathUrlsForRoot() throws IOException {
|
||||
debug.log("Adding classpath entries from root archive %s", this.archive);
|
||||
return this.archive.getClassPathUrls(JarLauncher::isLibraryFileOrClassesDirectory);
|
||||
}
|
||||
|
||||
private Predicate<Entry> includeByPrefix(String prefix) {
|
||||
return (entry) -> (entry.isDirectory() && entry.name().equals(prefix))
|
||||
|| (isArchive(entry) && entry.name().startsWith(prefix));
|
||||
|
||||
@@ -37,11 +37,7 @@ public class WarLauncher extends ExecutableArchiveLauncher {
|
||||
|
||||
@Override
|
||||
public boolean isIncludedOnClassPath(Archive.Entry entry) {
|
||||
String name = entry.name();
|
||||
if (entry.isDirectory()) {
|
||||
return name.equals("WEB-INF/classes/");
|
||||
}
|
||||
return name.startsWith("WEB-INF/lib/") || name.startsWith("WEB-INF/lib-provided/");
|
||||
return isLibraryFileOrClassesDirectory(entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,6 +45,14 @@ public class WarLauncher extends ExecutableArchiveLauncher {
|
||||
return "WEB-INF/";
|
||||
}
|
||||
|
||||
static boolean isLibraryFileOrClassesDirectory(Archive.Entry entry) {
|
||||
String name = entry.name();
|
||||
if (entry.isDirectory()) {
|
||||
return name.equals("WEB-INF/classes/");
|
||||
}
|
||||
return name.startsWith("WEB-INF/lib/") || name.startsWith("WEB-INF/lib-provided/");
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new WarLauncher().launch(args);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user