public class ClassLoaderResourceAccessor extends AbstractResourceAccessor implements AutoCloseable
FileSystemResourceAccessor that builds up the file roots based on the passed ClassLoader.
If you are using a ClassLoader that isn't based on local files, you will need to use a different ResourceAccessor implementation.for OSGi-based classloaders| Modifier and Type | Field and Description |
|---|---|
protected SortedSet<String> |
description |
protected List<FileSystem> |
rootPaths |
| Constructor and Description |
|---|
ClassLoaderResourceAccessor() |
ClassLoaderResourceAccessor(ClassLoader classLoader) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
SortedSet<String> |
describeLocations()
Returns a description of the places this classloader will look for paths.
|
protected String |
getFinalPath(String relativeTo,
String streamPath)
Generates a final path to
streamPath relative to relatoveTo. |
protected void |
init()
Performs the configuration of this resourceAccessor.
|
protected boolean |
isDirectory(String path)
Used by
listFromClassLoader(String, boolean, boolean, boolean) to determine if a path is a directory or not. |
SortedSet<String> |
list(String relativeTo,
String path,
boolean recursive,
boolean includeFiles,
boolean includeDirectories)
Returns the path to all resources contained in the given path.
|
protected SortedSet<String> |
listFromClassLoader(String path,
boolean recursive,
boolean includeFiles,
boolean includeDirectories)
Called by
list(String, String, boolean, boolean, boolean) to find files in classLoader. |
protected SortedSet<String> |
listFromRootPaths(String path,
boolean recursive,
boolean includeFiles,
boolean includeDirectories)
Called by
list(String, String, boolean, boolean, boolean) to find files in rootPaths. |
protected void |
loadRootPaths(ClassLoader classLoader)
The classloader search logic in
list(String, String, boolean, boolean, boolean) does not handle jar files well. |
InputStreamList |
openStreams(String relativeTo,
String streamPath)
Return the streams for each resource mapped by the given path.
|
openStreamclone, describe, equals, get, get, get, getAttributes, getFieldValue, getObjectMetaData, getValuePath, has, hashCode, set, toStringprotected List<FileSystem> rootPaths
public ClassLoaderResourceAccessor()
public ClassLoaderResourceAccessor(ClassLoader classLoader)
protected void init()
protected void loadRootPaths(ClassLoader classLoader)
list(String, String, boolean, boolean, boolean) does not handle jar files well.
This method is called by that method to populate rootPaths with additional paths to search.public InputStreamList openStreams(String relativeTo, String streamPath) throws IOException
ResourceAccessorInputStreamList since multiple resources can map to the same path, such as "META-INF/MAINFEST.MF".
Remember to close streams when finished with them.openStreams in interface ResourceAccessorrelativeTo - Location that streamPath should be found relative to. If null, streamPath is an absolute pathIOException - if there is an error reading an existing path.protected String getFinalPath(String relativeTo, String streamPath)
streamPath relative to relatoveTo.
If the last part of relativeTo contains a dot character (`.`)
this part is considered to be a file name, if it does not, it is
considered to be a directory.
i.e.changelog/some.sql -> some.sql is considered to be a file changelog/some_sql -> some_sql is considered to be a directory
relativeTo - starting point of the path resolution (may be null)streamPath - a path to a resource relative to relativeTo must not be nullpublic SortedSet<String> list(String relativeTo, String path, boolean recursive, boolean includeFiles, boolean includeDirectories) throws IOException
ResourceAccessorResourceAccessor.openStreams(String, String) and return the contents.
Returned paths should normally be root-relative and therefore not be an absolute path, unless there is a good reason to be absolute.list in interface ResourceAccessorrelativeTo - Location that streamPath should be found relative to. If null, path is an absolute pathpath - The path to lookup resources in.recursive - Set to true and will return paths to contents in sub directories as well.includeFiles - Set to true and will return paths to files.includeDirectories - Set to true and will return paths to directories.IOException - if there is an error reading an existing root.protected SortedSet<String> listFromRootPaths(String path, boolean recursive, boolean includeFiles, boolean includeDirectories)
list(String, String, boolean, boolean, boolean) to find files in rootPaths.protected SortedSet<String> listFromClassLoader(String path, boolean recursive, boolean includeFiles, boolean includeDirectories)
list(String, String, boolean, boolean, boolean) to find files in classLoader.protected boolean isDirectory(String path)
listFromClassLoader(String, boolean, boolean, boolean) to determine if a path is a directory or not.public SortedSet<String> describeLocations()
ResourceAccessordescribeLocations in interface ResourceAccessorpublic void close()
throws Exception
close in interface AutoCloseableExceptionCopyright © 2022 Liquibase.org. All rights reserved.