Don't add bad URIs, and log if they don't point to anything

This commit is contained in:
Joakim Erdfelt 2022-10-17 15:22:00 -05:00
parent b1c00223aa
commit bb887c9c81
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
1 changed files with 26 additions and 10 deletions

View File

@ -148,6 +148,12 @@ public class MetaInfConfiguration extends AbstractConfiguration
Consumer<URI> addContainerResource = (uri) ->
{
Resource resource = _resourceFactory.newResource(uri);
if (resource == null || !resource.exists())
{
if (LOG.isDebugEnabled())
LOG.debug("Classpath URI doesn't exist: " + uri);
}
else
context.getMetaData().addContainerResource(resource);
};
@ -379,6 +385,10 @@ public class MetaInfConfiguration extends AbstractConfiguration
*/
public void scanForResources(WebAppContext context, Resource target, ConcurrentHashMap<Resource, Resource> cache)
{
// Resource target does not exist
if (target == null || !target.exists())
return;
Resource resourcesDir = null;
if (cache != null && cache.containsKey(target))
{
@ -691,13 +701,20 @@ public class MetaInfConfiguration extends AbstractConfiguration
if (webInf == null || !webInf.exists() || !webInf.isDirectory())
return List.of();
Resource webInfLib = webInf.resolve("/lib");
Resource webInfLib = webInf.resolve("lib");
if (webInfLib != null && webInfLib.exists() && webInfLib.isDirectory())
{
return webInfLib.list().stream()
.filter((lib) -> FileID.isLibArchive(lib.getFileName()))
.sorted(ResourceCollators.byName(true))
.collect(Collectors.toList());
}
else
{
return List.of();
}
}
/**
* Get jars from WebAppContext.getExtraClasspath as resources
@ -733,14 +750,13 @@ public class MetaInfConfiguration extends AbstractConfiguration
return null;
Resource webInf = context.getWebInf();
// Find WEB-INF/classes
if (webInf != null && webInf.isDirectory())
{
// Look for classes directory
Resource classes = webInf.resolve("classes/");
if (classes.exists())
return classes;
Resource webInfClassesDir = webInf.resolve("classes/");
if (webInfClassesDir != null && webInfClassesDir.exists() && webInfClassesDir.isDirectory())
return webInfClassesDir;
}
return null;
}