Package cz.cvut.kbss.jopa.loaders
Class DefaultClasspathScanner
java.lang.Object
cz.cvut.kbss.jopa.loaders.DefaultClasspathScanner
- All Implemented Interfaces:
ClasspathScanner
Processes classes available to the current classloader.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final String
protected final ClassLoader
protected static final String
protected static final char
protected static final char
protected String
protected static final char
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(Consumer<Class<?>> listener) Registers a listener to which discovered classes will be passed for processing.protected static JarFile
createJarFile
(URL elementUrl) protected static boolean
protected void
processClass
(String className) Retrieves aClass
with the specified name and passes it to the registered listeners.void
processClasses
(String scanPackage) Inspired by https://github.com/ddopson/java-class-enumeratorprotected void
processDirectory
(File dir, String packageName) Processes the specified directory, looking for classes in the specified package (and its descendants).protected void
processElements
(Enumeration<URL> urls, String scanPath) protected void
processJarFile
(JarFile jarFile) Processes the specifiedJarFile
, looking for classes in the configured package.protected static String
sanitizePath
(URL url) Handles possible non-ascii character encoding in the specified URL.
-
Field Details
-
JAVA_CLASSPATH_SEPARATOR
protected static final char JAVA_CLASSPATH_SEPARATOR- See Also:
-
WINDOWS_FILE_SEPARATOR
protected static final char WINDOWS_FILE_SEPARATOR- See Also:
-
JAVA_PACKAGE_SEPARATOR
protected static final char JAVA_PACKAGE_SEPARATOR- See Also:
-
JAR_FILE_SUFFIX
- See Also:
-
CLASS_FILE_SUFFIX
- See Also:
-
listeners
-
classLoader
-
pathPattern
-
visited
-
-
Constructor Details
-
DefaultClasspathScanner
public DefaultClasspathScanner()
-
-
Method Details
-
addListener
Description copied from interface:ClasspathScanner
Registers a listener to which discovered classes will be passed for processing.- Specified by:
addListener
in interfaceClasspathScanner
- Parameters:
listener
- Listener to invoke with discovered classes
-
processClasses
Inspired by https://github.com/ddopson/java-class-enumerator- Specified by:
processClasses
in interfaceClasspathScanner
- Parameters:
scanPackage
- Package to scan
-
processElements
- Throws:
IOException
-
sanitizePath
Handles possible non-ascii character encoding in the specified URL.- Parameters:
url
- Resource URL (presumably leading to a local file)- Returns:
- Decoded argument
-
isJar
-
createJarFile
- Throws:
IOException
-
processJarFile
Processes the specifiedJarFile
, looking for classes in the configured package.- Parameters:
jarFile
- JAR file to scan
-
processClass
Retrieves aClass
with the specified name and passes it to the registered listeners.- Parameters:
className
- Fully-qualified class name
-
processDirectory
Processes the specified directory, looking for classes in the specified package (and its descendants).- Parameters:
dir
- DirectorypackageName
- Package name- Throws:
IOException
-