Package com.google.common.reflect
Class ClassPath
- java.lang.Object
-
- com.google.common.reflect.ClassPath
-
@Beta public final class ClassPath extends java.lang.Object
Scans the source of aClassLoader
and finds all loadable classes and resources.Warning: Currently only
URLClassLoader
and onlyfile://
urls are supported.- Since:
- 14.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ClassPath.ClassInfo
Represents a class that can be loaded throughClassPath.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 aClassLoader
and callsClassPath.Scanner.scanDirectory(java.lang.ClassLoader, java.io.File)
andClassPath.Scanner.scanJarFile(java.lang.ClassLoader, java.util.jar.JarFile)
for directories and jar files on the class path respectively.
-
Field Summary
Fields Modifier and Type Field 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
-
Constructor Summary
Constructors Modifier Constructor Description private
ClassPath(ImmutableSet<ClassPath.ResourceInfo> resources)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ClassPath
from(java.lang.ClassLoader classloader)
Returns aClassPath
representing all classes and resources loadable fromclassloader
and its parent 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 ispackageName
.ImmutableSet<ClassPath.ClassInfo>
getTopLevelClassesRecursive(java.lang.String packageName)
Returns all top level classes whose package name ispackageName
or starts withpackageName
followed by a '.'.
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
IS_TOP_LEVEL
private static final Predicate<ClassPath.ClassInfo> IS_TOP_LEVEL
-
CLASS_PATH_ATTRIBUTE_SEPARATOR
private static final Splitter CLASS_PATH_ATTRIBUTE_SEPARATOR
Separator for the Class-Path manifest attribute value in jar files.
-
CLASS_FILE_NAME_EXTENSION
private static final java.lang.String CLASS_FILE_NAME_EXTENSION
- See Also:
- Constant Field Values
-
resources
private final ImmutableSet<ClassPath.ResourceInfo> resources
-
-
Constructor Detail
-
ClassPath
private ClassPath(ImmutableSet<ClassPath.ResourceInfo> resources)
-
-
Method Detail
-
from
public static ClassPath from(java.lang.ClassLoader classloader) throws java.io.IOException
Returns aClassPath
representing all classes and resources loadable fromclassloader
and its parent class loaders.Warning: Currently only
URLClassLoader
and onlyfile://
urls are supported.- Throws:
java.io.IOException
- if the attempt to read class path resources (jar files or directories) failed.
-
getResources
public 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.
-
getAllClasses
public ImmutableSet<ClassPath.ClassInfo> getAllClasses()
Returns all classes loadable from the current class path.- Since:
- 16.0
-
getTopLevelClasses
public ImmutableSet<ClassPath.ClassInfo> getTopLevelClasses()
Returns all top level classes loadable from the current class path.
-
getTopLevelClasses
public ImmutableSet<ClassPath.ClassInfo> getTopLevelClasses(java.lang.String packageName)
Returns all top level classes whose package name ispackageName
.
-
getTopLevelClassesRecursive
public ImmutableSet<ClassPath.ClassInfo> getTopLevelClassesRecursive(java.lang.String packageName)
Returns all top level classes whose package name ispackageName
or starts withpackageName
followed by a '.'.
-
getClassName
static java.lang.String getClassName(java.lang.String filename)
-
-