Jetty 12 - Improve FileID and use where appropriate (#8589)

* Use FileID where appropriate
* Adding FileID.matchesExtension
* Fixing demo modules start test
This commit is contained in:
Joakim Erdfelt 2022-09-20 09:35:50 -05:00 committed by GitHub
parent b9d980b5a9
commit 95bf791b71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 129 additions and 142 deletions

View File

@ -443,7 +443,7 @@ public class ContextProvider extends ScanningAppProvider
{
try (Stream<Path> paths = Files.list(libDir))
{
paths.filter(p -> p.getFileName().toString().toLowerCase().endsWith(".jar"))
paths.filter(FileID::isJavaArchive)
.map(Path::toUri)
.forEach(uri ->
{

View File

@ -68,6 +68,7 @@
<include>org/eclipse/jetty/util/JavaVersion*</include>
<include>org/eclipse/jetty/util/ManifestUtils*</include>
<include>org/eclipse/jetty/util/TopologicalSort*</include>
<include>org/eclipse/jetty/util/FileID*</include>
</includes>
</filter>
</filters>

View File

@ -26,6 +26,8 @@ import java.util.Locale;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.eclipse.jetty.util.FileID;
public class FS
{
public static String separator()
@ -180,9 +182,7 @@ public class FS
public static void extract(Path archive, Path destination) throws IOException
{
String filename = archive.getFileName().toString().toLowerCase(Locale.US);
if (filename.endsWith(".jar") || filename.endsWith(".zip"))
if (FileID.isLibArchive(archive))
{
extractZip(archive, destination);
}

View File

@ -30,13 +30,13 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.jetty.start.Props.Prop;
import org.eclipse.jetty.start.config.CommandLineConfigSource;
import org.eclipse.jetty.start.config.ConfigSource;
import org.eclipse.jetty.util.FileID;
import static org.eclipse.jetty.start.UsageException.ERR_BAD_STOP_PROPS;
import static org.eclipse.jetty.start.UsageException.ERR_INVOKE_MAIN;
@ -170,13 +170,9 @@ public class Main
return "(dir)";
}
if (Files.isRegularFile(element))
if (Files.isRegularFile(element) && FileID.isJavaArchive(element))
{
String name = element.toString().toLowerCase(Locale.ENGLISH);
if (name.endsWith(".jar"))
{
return JarVersion.getVersion(element);
}
return JarVersion.getVersion(element);
}
return "";

View File

@ -127,6 +127,54 @@ public class FileID
return filename.substring(lastDot).toLowerCase(Locale.ENGLISH);
}
/**
* Test if Path matches any of the indicated extensions.
*
* @param path the Path to test
* @param extensions the list of extensions (all lowercase, with preceding {@code .} dot)
* @return true if Path is a file, and has an extension, and it matches any of the indicated extensions
*/
public static boolean isExtension(Path path, String... extensions)
{
return matchesExtension(getExtension(path), extensions);
}
/**
* Test if URI matches any of the indicated extensions.
*
* @param uri the URI to test
* @param extensions the list of extensions (all lowercase, with preceding {@code .} dot)
* @return true if URI has an extension, and it matches any of the indicated extensions
*/
public static boolean isExtension(URI uri, String... extensions)
{
return matchesExtension(getExtension(uri), extensions);
}
/**
* Test if filename matches any of the indicated extensions.
*
* @param filename the filename to test
* @param extensions the list of extensions (all lowercase, with preceding {@code .} dot)
* @return true if filename has an extension, and it matches any of the indicated extensions
*/
public static boolean isExtension(String filename, String... extensions)
{
return matchesExtension(getExtension(filename), extensions);
}
private static boolean matchesExtension(String ext, String... extensions)
{
if (ext == null)
return false;
for (String extension : extensions)
{
if (ext.equals(extension))
return true;
}
return false;
}
/**
* Does the provided path have a directory segment with the given name.
*
@ -159,10 +207,7 @@ public class FileID
*/
public static boolean isArchive(Path path)
{
String ext = getExtension(path);
if (ext == null)
return false;
return (ext.equals(".jar") || ext.equals(".war") || ext.equals(".zip"));
return isExtension(path, ".jar", ".war", ".zip");
}
/**
@ -174,10 +219,7 @@ public class FileID
*/
public static boolean isArchive(String filename)
{
String ext = getExtension(filename);
if (ext == null)
return false;
return (ext.equals(".jar") || ext.equals(".war") || ext.equals(".zip"));
return isExtension(filename, ".jar", ".war", ".zip");
}
/**
@ -189,10 +231,7 @@ public class FileID
*/
public static boolean isArchive(URI uri)
{
String ext = getExtension(uri);
if (ext == null)
return false;
return (ext.equals(".jar") || ext.equals(".war") || ext.equals(".zip"));
return isExtension(uri, ".jar", ".war", ".zip");
}
/**
@ -204,10 +243,7 @@ public class FileID
*/
public static boolean isLibArchive(Path path)
{
String ext = getExtension(path);
if (ext == null)
return false;
return (ext.equals(".jar") || ext.equals(".zip"));
return isExtension(path, ".jar", ".zip");
}
/**
@ -219,10 +255,7 @@ public class FileID
*/
public static boolean isLibArchive(String filename)
{
String ext = getExtension(filename);
if (ext == null)
return false;
return (ext.equals(".jar") || ext.equals(".zip"));
return isExtension(filename, ".jar", ".zip");
}
/**
@ -234,10 +267,7 @@ public class FileID
*/
public static boolean isLibArchive(URI uri)
{
String ext = getExtension(uri);
if (ext == null)
return false;
return (ext.equals(".jar") || ext.equals(".zip"));
return isExtension(uri, ".jar", ".zip");
}
/**
@ -323,7 +353,7 @@ public class FileID
*/
public static boolean isJavaArchive(URI uri)
{
return ".jar".equals(getExtension(uri));
return isExtension(uri, ".jar");
}
/**
@ -334,7 +364,7 @@ public class FileID
*/
public static boolean isJavaArchive(Path path)
{
return ".jar".equals(getExtension(path));
return isExtension(path, ".jar");
}
/**
@ -345,7 +375,7 @@ public class FileID
*/
public static boolean isJavaArchive(String filename)
{
return ".jar".equals(getExtension(filename));
return isExtension(filename, ".jar");
}
/**
@ -418,7 +448,7 @@ public class FileID
return false;
if (!hasNamedPathSegment(path, "META-INF"))
return false;
return ".tld".equals(getExtension(path));
return isExtension(path, ".tld");
}
/**
@ -429,7 +459,7 @@ public class FileID
*/
public static boolean isWebArchive(Path path)
{
return ".war".equals(getExtension(path));
return isExtension(path, ".war");
}
/**
@ -440,7 +470,7 @@ public class FileID
*/
public static boolean isWebArchive(URI uri)
{
return ".war".equals(getExtension(uri));
return isExtension(uri, ".war");
}
/**
@ -451,7 +481,7 @@ public class FileID
*/
public static boolean isWebArchive(String filename)
{
return ".war".equals(getExtension(filename));
return isExtension(filename, ".war");
}
/**
@ -462,7 +492,7 @@ public class FileID
*/
public static boolean isXml(Path path)
{
return ".xml".equals(getExtension(path));
return isExtension(path, ".xml");
}
/**
@ -473,28 +503,6 @@ public class FileID
*/
public static boolean isXml(String filename)
{
return ".xml".equals(getExtension(filename));
}
/**
* Is the Path a file that ends in ZIP?
*
* @param path the path to test
* @return true if a .zip, false otherwise
*/
public static boolean isZip(Path path)
{
return ".zip".equals(getExtension(path));
}
/**
* Is the Path a file that ends in ZIP?
*
* @param filename the filename to test
* @return true if a .zip, false otherwise
*/
public static boolean isZip(String filename)
{
return ".zip".equals(getExtension(filename));
return isExtension(filename, ".xml");
}
}

View File

@ -300,6 +300,8 @@ public class FileIDTest
"file:/home/user/.m2/repository/com/company/1.0/company-1.0.jar",
"jar:file:/home/user/.m2/repository/com/company/1.0/company-1.0.jar!/",
"jar:file:/home/user/.m2/repository/com/company/1.0/company-1.0.jar",
"jar:file:///home/user/plugins/PLUGIN.JAR",
"jar:file:///home/user/plugins/Fragment.Jar",
"file:/home/user/install/jetty-home-12.0.0.zip",
"file:/opt/websites/webapps/company.war",
"jar:file:/home/user/.m2/repository/jakarta/servlet/jakarta.servlet-api/6.0.0/jakarta.servlet-api-6.0.0.jar!/META-INF/resources"

View File

@ -16,11 +16,11 @@ package org.eclipse.jetty.ee10.maven.plugin;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.eclipse.jetty.ee10.webapp.Configuration;
import org.eclipse.jetty.ee10.webapp.MetaInfConfiguration;
import org.eclipse.jetty.ee10.webapp.WebAppContext;
import org.eclipse.jetty.util.FileID;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceFactory;
import org.slf4j.Logger;
@ -63,7 +63,7 @@ public class MavenMetaInfConfiguration extends MetaInfConfiguration
{
files.forEach(file ->
{
if (file.getName().toLowerCase(Locale.ENGLISH).endsWith(".jar") || file.isDirectory())
if (FileID.isJavaArchive(file.getName()) || file.isDirectory())
{
try
{

View File

@ -36,6 +36,7 @@ import org.eclipse.jetty.ee10.webapp.Configuration;
import org.eclipse.jetty.ee10.webapp.Configurations;
import org.eclipse.jetty.ee10.webapp.MetaInfConfiguration;
import org.eclipse.jetty.ee10.webapp.WebAppContext;
import org.eclipse.jetty.util.FileID;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.resource.Resource;
@ -297,7 +298,7 @@ public class MavenWebAppContext extends WebAppContext
{
// Return all jar files from class path
String fileName = file.getName();
if (fileName.endsWith(".jar"))
if (FileID.isJavaArchive(fileName))
_webInfJarMap.put(fileName, file);
}

View File

@ -224,7 +224,7 @@ public class ContainerTldBundleDiscoverer implements TldBundleDiscoverer
{
for (File f : jasperLocation.listFiles())
{
if (f.getName().endsWith(".jar") && f.isFile())
if (FileID.isJavaArchive(f.getName()) && f.isFile())
{
urls.add(f.toURI().toURL());
}
@ -232,7 +232,7 @@ public class ContainerTldBundleDiscoverer implements TldBundleDiscoverer
{
for (File f2 : jasperLocation.listFiles())
{
if (f2.getName().endsWith(".jar") && f2.isFile())
if (FileID.isJavaArchive(f2.getName()) && f2.isFile())
{
urls.add(f2.toURI().toURL());
}

View File

@ -143,7 +143,7 @@ public class JSTLBundleDiscoverer implements TldBundleDiscoverer
// try to find the jar files inside this folder
for (File f : tldBundleLocation.listFiles())
{
if (f.getName().endsWith(".jar") && f.isFile())
if (FileID.isJavaArchive(f.getName()) && f.isFile())
{
urls.add(f.toURI().toURL());
}
@ -151,7 +151,7 @@ public class JSTLBundleDiscoverer implements TldBundleDiscoverer
{
for (File f2 : tldBundleLocation.listFiles())
{
if (f2.getName().endsWith(".jar") && f2.isFile())
if (FileID.isJavaArchive(f2.getName()) && f2.isFile())
{
urls.add(f2.toURI().toURL());
}

View File

@ -266,7 +266,7 @@ public class WarBundleManifestGenerator
while (en.hasMoreElements())
{
JarEntry e = en.nextElement();
if (e.getName().startsWith("WEB-INF/lib/") && e.getName().endsWith(".jar"))
if (e.getName().startsWith("WEB-INF/lib/") && FileID.isJavaArchive(e.getName()))
{
res.add(e.getName());
}

View File

@ -91,7 +91,7 @@ public class AnnotationConfiguration extends org.eclipse.jetty.ee10.annotations.
Resource resource = super.getJarFor(service);
// TODO This is not correct, but implemented like this to be bug for bug compatible
// with previous implementation that could only handle actual jars and not bundles.
if (resource != null && !resource.toString().endsWith(".jar"))
if (resource != null && !FileID.isJavaArchive(resource.getFileName()))
return null;
return resource;
}

View File

@ -151,7 +151,7 @@ public class AnnotationParser extends org.eclipse.jetty.ee10.annotations.Annotat
{
hasDotPath = true;
}
else if (!token.endsWith(".jar") && !token.endsWith("/"))
else if (!FileID.isJavaArchive(token) && !token.endsWith("/"))
{
paths.add(token + "/");
}

View File

@ -282,7 +282,7 @@ public class OSGiMetaInfConfiguration extends MetaInfConfiguration
{
for (File f : file.listFiles())
{
if (f.getName().endsWith(".jar") && f.isFile())
if (FileID.isJavaArchive(f.getName()) && f.isFile())
{
resources.add(Resource.newResource(f));
}
@ -290,7 +290,7 @@ public class OSGiMetaInfConfiguration extends MetaInfConfiguration
{
for (File f2 : file.listFiles())
{
if (f2.getName().endsWith(".jar") && f2.isFile())
if (FileID.isJavaArchive(f2.getName()) && f2.isFile())
{
resources.add(Resource.newResource(f));
}

View File

@ -313,10 +313,10 @@ public class DefaultJettyAtJettyHomeHelper
URL u = f.toURI().toURL();
u = BundleFileLocatorHelperFactory.getFactory().getHelper().getLocalURL(u);
Resource res = Resource.newResource(u);
String s = res.toString();
URI ruri = res.toURI();
//check if it is an unarchived bundle
if (s.endsWith(".jar") && s.startsWith("file:"))
// check if it is an unarchived bundle
if ("file".equalsIgnoreCase(ruri.getScheme()) && FileID.isJavaArchive(ruri))
res = JarResource.newJarResource(res);
//if looking for a directory

View File

@ -105,7 +105,7 @@ public class LibExtClassLoaderHelper
{
for (File f : libExt.listFiles())
{
if (f.getName().endsWith(".jar"))
if (FileID.isJavaArchive(f.getName()))
{
// cheap to tolerate folders so let's do it.
URL url = f.toURI().toURL();
@ -152,7 +152,7 @@ public class LibExtClassLoaderHelper
{
for (File f : libExt.listFiles())
{
if (f.getName().endsWith(".jar"))
if (FileID.isJavaArchive(f.getName()))
{
// cheap to tolerate folders so let's do it.
URL url = f.toURI().toURL();

View File

@ -285,7 +285,7 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
ArrayList<File> urls = new ArrayList<>();
for (File f : jasperLocation.listFiles())
{
if (f.getName().endsWith(".jar") && f.isFile())
if (FileID.isJavaArchive(f.getName()) && f.isFile())
{
urls.add(f);
}
@ -293,7 +293,7 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
{
for (File f2 : jasperLocation.listFiles())
{
if (f2.getName().endsWith(".jar") && f2.isFile())
if (FileID.isJavaArchive(f2.getName()) && f2.isFile())
{
urls.add(f2);
}

View File

@ -31,13 +31,13 @@ import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Stream;
import org.eclipse.jetty.util.ClassVisibilityChecker;
import org.eclipse.jetty.util.FileID;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.TypeUtil;
@ -78,7 +78,7 @@ public class WebAppClassLoader extends URLClassLoader implements ClassVisibility
private final Context _context;
private final ClassLoader _parent;
private final Set<String> _extensions = new HashSet<String>();
private final Set<String> _extensions = new HashSet<>();
private String _name = String.valueOf(hashCode());
private final List<ClassFileTransformer> _transformers = new CopyOnWriteArrayList<>();
private final ResourceFactory.Closeable _resourceFactory = ResourceFactory.closeable();
@ -282,16 +282,13 @@ public class WebAppClassLoader extends URLClassLoader implements ClassVisibility
/**
* @param file Checks if this file type can be added to the classpath.
* TODO: move to FileID in later PR
*/
private boolean isFileSupported(String file)
{
int dot = file.lastIndexOf('.');
return dot != -1 && _extensions.contains(file.substring(dot).toLowerCase(Locale.ENGLISH));
String ext = FileID.getExtension(file);
return ext != null && _extensions.contains(ext);
}
// TODO: move to FileID in later PR
private boolean isFileSupported(Path path)
{
return isFileSupported(path.getFileName().toString());

View File

@ -16,11 +16,11 @@ package org.eclipse.jetty.ee9.maven.plugin;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.eclipse.jetty.ee9.webapp.Configuration;
import org.eclipse.jetty.ee9.webapp.MetaInfConfiguration;
import org.eclipse.jetty.ee9.webapp.WebAppContext;
import org.eclipse.jetty.util.FileID;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceFactory;
import org.slf4j.Logger;
@ -63,7 +63,7 @@ public class MavenMetaInfConfiguration extends MetaInfConfiguration
{
files.forEach(file ->
{
if (file.getName().toLowerCase(Locale.ENGLISH).endsWith(".jar") || file.isDirectory())
if (FileID.isJavaArchive(file.getName()) || file.isDirectory())
{
try
{

View File

@ -37,6 +37,7 @@ import org.eclipse.jetty.ee9.webapp.Configuration;
import org.eclipse.jetty.ee9.webapp.Configurations;
import org.eclipse.jetty.ee9.webapp.MetaInfConfiguration;
import org.eclipse.jetty.ee9.webapp.WebAppContext;
import org.eclipse.jetty.util.FileID;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.resource.Resource;
@ -299,7 +300,7 @@ public class MavenWebAppContext extends WebAppContext
{
// Return all jar files from class path
String fileName = file.getName();
if (fileName.endsWith(".jar"))
if (FileID.isJavaArchive(fileName))
_webInfJarMap.put(fileName, file);
}

View File

@ -224,7 +224,7 @@ public class ContainerTldBundleDiscoverer implements TldBundleDiscoverer
{
for (File f : jasperLocation.listFiles())
{
if (f.getName().endsWith(".jar") && f.isFile())
if (FileID.isJavaArchive(f.getName()) && f.isFile())
{
urls.add(f.toURI().toURL());
}
@ -232,7 +232,7 @@ public class ContainerTldBundleDiscoverer implements TldBundleDiscoverer
{
for (File f2 : jasperLocation.listFiles())
{
if (f2.getName().endsWith(".jar") && f2.isFile())
if (FileID.isJavaArchive(f2.getName()) && f2.isFile())
{
urls.add(f2.toURI().toURL());
}

View File

@ -143,7 +143,7 @@ public class JSTLBundleDiscoverer implements TldBundleDiscoverer
// try to find the jar files inside this folder
for (File f : tldBundleLocation.listFiles())
{
if (f.getName().endsWith(".jar") && f.isFile())
if (FileID.isJavaArchive(f.getName()) && f.isFile())
{
urls.add(f.toURI().toURL());
}
@ -151,7 +151,7 @@ public class JSTLBundleDiscoverer implements TldBundleDiscoverer
{
for (File f2 : tldBundleLocation.listFiles())
{
if (f2.getName().endsWith(".jar") && f2.isFile())
if (FileID.isJavaArchive(f2.getName()) && f2.isFile())
{
urls.add(f2.toURI().toURL());
}

View File

@ -266,7 +266,7 @@ public class WarBundleManifestGenerator
while (en.hasMoreElements())
{
JarEntry e = en.nextElement();
if (e.getName().startsWith("WEB-INF/lib/") && e.getName().endsWith(".jar"))
if (e.getName().startsWith("WEB-INF/lib/") && FileID.isJavaArchive(e.getName()))
{
res.add(e.getName());
}

View File

@ -91,7 +91,7 @@ public class AnnotationConfiguration extends org.eclipse.jetty.ee9.annotations.A
Resource resource = super.getJarFor(service);
// TODO This is not correct, but implemented like this to be bug for bug compatible
// with previous implementation that could only handle actual jars and not bundles.
if (resource != null && !resource.toString().endsWith(".jar"))
if (resource != null && !FileID.isJavaArchive(resource.getURI()))
return null;
return resource;
}

View File

@ -151,7 +151,7 @@ public class AnnotationParser extends org.eclipse.jetty.ee9.annotations.Annotati
{
hasDotPath = true;
}
else if (!token.endsWith(".jar") && !token.endsWith("/"))
else if (!FileID.isJavaArchive(token) && !token.endsWith("/"))
{
paths.add(token + "/");
}

View File

@ -281,7 +281,7 @@ public class OSGiMetaInfConfiguration extends MetaInfConfiguration
{
for (File f : file.listFiles())
{
if (f.getName().endsWith(".jar") && f.isFile())
if (FileID.isJavaArchive(f.getName()) && f.isFile())
{
resources.add(Resource.newResource(f));
}
@ -289,7 +289,7 @@ public class OSGiMetaInfConfiguration extends MetaInfConfiguration
{
for (File f2 : file.listFiles())
{
if (f2.getName().endsWith(".jar") && f2.isFile())
if (FileID.isJavaArchive(f2.getName()) && f2.isFile())
{
resources.add(Resource.newResource(f));
}

View File

@ -313,10 +313,10 @@ public class DefaultJettyAtJettyHomeHelper
URL u = f.toURI().toURL();
u = BundleFileLocatorHelperFactory.getFactory().getHelper().getLocalURL(u);
Resource res = Resource.newResource(u);
String s = res.toString();
URI ruri = res.getURI();
//check if it is an unarchived bundle
if (s.endsWith(".jar") && s.startsWith("file:"))
if ("file".equalsIgnoreCase(ruri.getScheme()) && FileID.isJavaArchive(ruri))
res = JarResource.newJarResource(res);
//if looking for a directory

View File

@ -105,7 +105,7 @@ public class LibExtClassLoaderHelper
{
for (File f : libExt.listFiles())
{
if (f.getName().endsWith(".jar"))
if (FileID.isJavaArchive(f.getName()))
{
// cheap to tolerate folders so let's do it.
URL url = f.toURI().toURL();
@ -152,7 +152,7 @@ public class LibExtClassLoaderHelper
{
for (File f : libExt.listFiles())
{
if (f.getName().endsWith(".jar"))
if (FileID.isJavaArchive(f.getName()))
{
// cheap to tolerate folders so let's do it.
URL url = f.toURI().toURL();

View File

@ -285,7 +285,7 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
ArrayList<File> urls = new ArrayList<>();
for (File f : jasperLocation.listFiles())
{
if (f.getName().endsWith(".jar") && f.isFile())
if (FileID.isJavaArchive(f.getName()) && f.isFile())
{
urls.add(f);
}
@ -293,7 +293,7 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
{
for (File f2 : jasperLocation.listFiles())
{
if (f2.getName().endsWith(".jar") && f2.isFile())
if (FileID.isJavaArchive(f2.getName()) && f2.isFile())
{
urls.add(f2);
}

View File

@ -112,29 +112,12 @@ public class Runner
if (lib == null || !lib.exists())
throw new IllegalStateException("No such lib: " + lib);
String[] list = lib.list();
if (list == null)
return;
for (String path : list)
for (Resource item: lib.list())
{
if (".".equals(path) || "..".equals(path))
continue;
try (Resource item = lib.addPath(path))
{
if (item.isDirectory())
addJars(item);
else
{
String lowerCasePath = path.toLowerCase(Locale.ENGLISH);
if (lowerCasePath.endsWith(".jar") ||
lowerCasePath.endsWith(".zip"))
{
_classpath.add(item.getURI());
}
}
}
if (item.isDirectory())
addJars(item);
else if (FileID.isLibArchive(item.getFileName()))
_classpath.add(item.getURI());
}
}

View File

@ -31,13 +31,13 @@ import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Stream;
import org.eclipse.jetty.util.ClassVisibilityChecker;
import org.eclipse.jetty.util.FileID;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.TypeUtil;
@ -78,7 +78,7 @@ public class WebAppClassLoader extends URLClassLoader implements ClassVisibility
private final Context _context;
private final ClassLoader _parent;
private final Set<String> _extensions = new HashSet<String>();
private final Set<String> _extensions = new HashSet<>();
private String _name = String.valueOf(hashCode());
private final List<ClassFileTransformer> _transformers = new CopyOnWriteArrayList<>();
private final ResourceFactory.Closeable _resourceFactory = ResourceFactory.closeable();
@ -282,16 +282,13 @@ public class WebAppClassLoader extends URLClassLoader implements ClassVisibility
/**
* @param file Checks if this file type can be added to the classpath.
* TODO: move to FileID in later PR
*/
private boolean isFileSupported(String file)
{
int dot = file.lastIndexOf('.');
return dot != -1 && _extensions.contains(file.substring(dot).toLowerCase(Locale.ENGLISH));
String ext = FileID.getExtension(file);
return ext != null && _extensions.contains(ext);
}
// TODO: move to FileID in later PR
private boolean isFileSupported(Path path)
{
return isFileSupported(path.getFileName().toString());

View File

@ -45,6 +45,7 @@ import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.eclipse.jetty.util.FileID;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.resource.FileSystemPool;
@ -539,7 +540,7 @@ public class WebAppContextTest
{
expectedUris = s
.filter(Files::isRegularFile)
.filter((path) -> path.getFileName().toString().endsWith(".jar"))
.filter(FileID::isLibArchive)
.sorted(Comparator.naturalOrder())
.map(Path::toUri)
.map(URIUtil::toJarFileUri)

View File

@ -70,12 +70,12 @@ public class DemoModulesTests extends AbstractJettyHomeTest
try (JettyHomeTester.Run runConfig = distribution.start(argsConfig))
{
assertTrue(runConfig.awaitFor(START_TIMEOUT, TimeUnit.SECONDS));
assertEquals(0, runConfig.getExitValue());
assertEquals(0, runConfig.getExitValue(), "Exit value");
try (JettyHomeTester.Run runListConfig = distribution.start("--list-config"))
{
assertTrue(runListConfig.awaitFor(START_TIMEOUT, TimeUnit.SECONDS));
assertEquals(0, runListConfig.getExitValue());
assertEquals(0, runListConfig.getExitValue(), "Exit value");
// Example of what we expect
// jetty.webapp.addServerClasses = org.eclipse.jetty.logging.,${jetty.home.uri}/lib/logging/,org.slf4j.,${jetty.base.uri}/lib/bouncycastle/
String addServerKey = " jetty.webapp.addServerClasses = ";