handle review comments

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
Ludovic Orban 2022-07-26 15:29:29 +02:00
parent 9f0463b545
commit a84a86d820
2 changed files with 31 additions and 14 deletions

View File

@ -22,6 +22,7 @@ import java.net.URLClassLoader;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
@ -719,23 +720,31 @@ public class MetaInfConfiguration extends AbstractConfiguration
public Collection<URL> getTlds(URI uri) throws IOException
{
HashSet<URL> tlds = new HashSet<>();
URI jarUri = uriJarPrefix(uri, "!/");
try (Resource.Mount mount = Resource.mount(jarUri);
try (Resource.Mount mount = Resource.mount(uriJarPrefix(uri, "!/"));
Stream<Path> stream = Files.walk(mount.root().getPath()))
{
Iterator<String> it = stream
.map(Path::toString)
.filter(filename -> filename.startsWith("META-INF") && filename.endsWith(".tld"))
Iterator<Path> it = stream
.filter(MetaInfConfiguration::isTldFile)
.iterator();
String prefix = jarUri.toString();
while (it.hasNext())
{
tlds.add(new URL(prefix + it.next()));
Path entry = it.next();
tlds.add(entry.toUri().toURL());
}
}
return tlds;
}
private static boolean isTldFile(Path path)
{
if (path.getNameCount() < 2)
return false;
if (!path.getName(0).toString().equalsIgnoreCase("META-INF"))
return false;
String filename = path.getFileName().toString();
return filename.toLowerCase(Locale.ENGLISH).endsWith(".tld");
}
protected List<Resource> findClassDirs(WebAppContext context)
throws Exception
{

View File

@ -713,23 +713,31 @@ public class MetaInfConfiguration extends AbstractConfiguration
public Collection<URL> getTlds(URI uri) throws IOException
{
HashSet<URL> tlds = new HashSet<>();
URI jarUri = uriJarPrefix(uri, "!/");
try (Resource.Mount mount = Resource.mount(jarUri);
try (Resource.Mount mount = Resource.mount(uriJarPrefix(uri, "!/"));
Stream<Path> stream = Files.walk(mount.root().getPath()))
{
Iterator<String> it = stream
.map(Path::toString)
.filter(filename -> filename.startsWith("META-INF") && filename.endsWith(".tld"))
Iterator<Path> it = stream
.filter(MetaInfConfiguration::isTldFile)
.iterator();
String prefix = jarUri.toString();
while (it.hasNext())
{
tlds.add(new URL(prefix + it.next()));
Path entry = it.next();
tlds.add(entry.toUri().toURL());
}
}
return tlds;
}
private static boolean isTldFile(Path path)
{
if (path.getNameCount() < 2)
return false;
if (!path.getName(0).toString().equalsIgnoreCase("META-INF"))
return false;
String filename = path.getFileName().toString();
return filename.toLowerCase(Locale.ENGLISH).endsWith(".tld");
}
protected List<Resource> findClassDirs(WebAppContext context)
throws Exception
{