@Beta public final class ClassPath extends java.lang.Object
ClassLoader
and finds all loadable classes and resources.
Warning: Current limitations:
URLClassLoader
instances or
the system class loader.
file:
URLs.
In the case of directory classloaders, symlinks are supported but cycles are not traversed. This guarantees discovery of each unique loadable resource. However, not all possible aliases for resources on cyclic paths will be listed.
Modifier and Type | Class and Description |
---|---|
static class |
ClassPath.ClassInfo
Represents a class that can be loaded through
ClassPath.ClassInfo.load() . |
(package private) static class |
ClassPath.DefaultScanner |
static class |
ClassPath.ResourceInfo
Represents a class path resource that can be either a class file or any other resource file
loadable from the class path.
|
(package private) static class |
ClassPath.Scanner
Abstract class that scans through the class path represented by a
ClassLoader and calls
ClassPath.Scanner.scanDirectory(java.lang.ClassLoader, java.io.File) and ClassPath.Scanner.scanJarFile(java.lang.ClassLoader, java.util.jar.JarFile) for directories and jar files on the class path
respectively. |
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
CLASS_FILE_NAME_EXTENSION |
private static Splitter |
CLASS_PATH_ATTRIBUTE_SEPARATOR
Separator for the Class-Path manifest attribute value in jar files.
|
private static Predicate<ClassPath.ClassInfo> |
IS_TOP_LEVEL |
private static java.util.logging.Logger |
logger |
private ImmutableSet<ClassPath.ResourceInfo> |
resources |
Modifier | Constructor and Description |
---|---|
private |
ClassPath(ImmutableSet<ClassPath.ResourceInfo> resources) |
Modifier and Type | Method and Description |
---|---|
static ClassPath |
from(java.lang.ClassLoader classloader)
Returns a
ClassPath representing all classes and resources loadable from classloader and its ancestor class loaders. |
ImmutableSet<ClassPath.ClassInfo> |
getAllClasses()
Returns all classes loadable from the current class path.
|
(package private) static java.lang.String |
getClassName(java.lang.String filename) |
ImmutableSet<ClassPath.ResourceInfo> |
getResources()
Returns all resources loadable from the current class path, including the class files of all
loadable classes but excluding the "META-INF/MANIFEST.MF" file.
|
ImmutableSet<ClassPath.ClassInfo> |
getTopLevelClasses()
Returns all top level classes loadable from the current class path.
|
ImmutableSet<ClassPath.ClassInfo> |
getTopLevelClasses(java.lang.String packageName)
Returns all top level classes whose package name is
packageName . |
ImmutableSet<ClassPath.ClassInfo> |
getTopLevelClassesRecursive(java.lang.String packageName)
Returns all top level classes whose package name is
packageName or starts with packageName followed by a '.'. |
(package private) static java.io.File |
toFile(java.net.URL url) |
private static final java.util.logging.Logger logger
private static final Predicate<ClassPath.ClassInfo> IS_TOP_LEVEL
private static final Splitter CLASS_PATH_ATTRIBUTE_SEPARATOR
private static final java.lang.String CLASS_FILE_NAME_EXTENSION
private final ImmutableSet<ClassPath.ResourceInfo> resources
private ClassPath(ImmutableSet<ClassPath.ResourceInfo> resources)
public static ClassPath from(java.lang.ClassLoader classloader) throws java.io.IOException
ClassPath
representing all classes and resources loadable from classloader
and its ancestor class loaders.
Warning: ClassPath
can find classes and resources only from:
URLClassLoader
instances' file:
URLs
URLClassLoader
(as in Java 9), ClassPath
searches the files from the java.class.path
system property.
java.io.IOException
- if the attempt to read class path resources (jar files or directories)
failed.public ImmutableSet<ClassPath.ResourceInfo> getResources()
public ImmutableSet<ClassPath.ClassInfo> getAllClasses()
public ImmutableSet<ClassPath.ClassInfo> getTopLevelClasses()
public ImmutableSet<ClassPath.ClassInfo> getTopLevelClasses(java.lang.String packageName)
packageName
.public ImmutableSet<ClassPath.ClassInfo> getTopLevelClassesRecursive(java.lang.String packageName)
packageName
or starts with packageName
followed by a '.'.static java.lang.String getClassName(java.lang.String filename)
static java.io.File toFile(java.net.URL url)