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 Stringprotected final ClassLoaderprotected static final Stringprotected static final charprotected static final charprotected Stringprotected static final char -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(Consumer<Class<?>> listener) Registers a listener to which discovered classes will be passed for processing.protected static JarFilecreateJarFile(URL elementUrl) protected static booleanprotected voidprocessClass(String className) Retrieves aClasswith the specified name and passes it to the registered listeners.voidprocessClasses(String scanPackage) Inspired by https://github.com/ddopson/java-class-enumeratorprotected voidprocessDirectory(File dir, String packageName) Processes the specified directory, looking for classes in the specified package (and its descendants).protected voidprocessElements(Enumeration<URL> urls, String scanPath) protected voidprocessJarFile(JarFile jarFile) Processes the specifiedJarFile, looking for classes in the configured package.protected static StringsanitizePath(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:ClasspathScannerRegisters a listener to which discovered classes will be passed for processing.- Specified by:
addListenerin interfaceClasspathScanner- Parameters:
listener- Listener to invoke with discovered classes
-
processClasses
Inspired by https://github.com/ddopson/java-class-enumerator- Specified by:
processClassesin 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 aClasswith 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
-