Package liquibase.resource
Class ClassLoaderResourceAccessor
- java.lang.Object
-
- liquibase.AbstractExtensibleObject
-
- liquibase.resource.AbstractResourceAccessor
-
- liquibase.resource.ClassLoaderResourceAccessor
-
- All Implemented Interfaces:
AutoCloseable
,Cloneable
,ExtensibleObject
,ResourceAccessor
- Direct Known Subclasses:
MavenResourceAccessor
,OSGiResourceAccessor
public class ClassLoaderResourceAccessor extends AbstractResourceAccessor
An implementation ofDirectoryResourceAccessor
that builds up the file roots based on the passedClassLoader
. If you are using a ClassLoader that isn't based on local files, you will need to use a differentResourceAccessor
implementation.- See Also:
for OSGi-based classloaders
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface liquibase.resource.ResourceAccessor
ResourceAccessor.NotFoundResource, ResourceAccessor.SearchOptions
-
-
Field Summary
Fields Modifier and Type Field Description protected SortedSet<String>
description
-
Constructor Summary
Constructors Constructor Description ClassLoaderResourceAccessor()
ClassLoaderResourceAccessor(ClassLoader classLoader)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
protected void
configureAdditionalResourceAccessors(ClassLoader classLoader)
The classloader search logic insearch(String, boolean)
does not handle jar files well.List<String>
describeLocations()
Returns a description of the places this classloader will look for paths.List<Resource>
getAll(String path)
Returns allResource
s at the given path.protected void
init()
Performs the configuration of this resourceAccessor.List<Resource>
search(String path, boolean recursive)
Returns the path to all resources contained in the given path.List<Resource>
search(String path, ResourceAccessor.SearchOptions searchOptions)
Returns the path to all resources contained in the given path that match the searchOptions criteria.-
Methods inherited from class liquibase.AbstractExtensibleObject
clone, describe, equals, get, get, get, getAttributes, getFieldValue, getObjectMetaData, getValuePath, has, hashCode, set, toString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface liquibase.resource.ResourceAccessor
get, getExisting, list, openStream, openStreams
-
-
-
-
Constructor Detail
-
ClassLoaderResourceAccessor
public ClassLoaderResourceAccessor()
-
ClassLoaderResourceAccessor
public ClassLoaderResourceAccessor(ClassLoader classLoader)
-
-
Method Detail
-
describeLocations
public List<String> describeLocations()
Description copied from interface:ResourceAccessor
Returns a description of the places this classloader will look for paths. Used in error messages and other troubleshooting cases.
-
init
protected void init()
Performs the configuration of this resourceAccessor. Not done in the constructor for performance reasons, but can be called at the beginning of every public method.
-
configureAdditionalResourceAccessors
protected void configureAdditionalResourceAccessors(ClassLoader classLoader)
The classloader search logic insearch(String, boolean)
does not handle jar files well. This method is called by that method to configure an internalResourceAccessor
with paths to search.
-
search
public List<Resource> search(String path, ResourceAccessor.SearchOptions searchOptions) throws IOException
Description copied from interface:ResourceAccessor
Returns the path to all resources contained in the given path that match the searchOptions criteria. Multiple resources may be returned with the same path, but only if they are actually unique files. Order is important to pay attention to, they should be returned in a user-expected manner based on this resource accessor.
Should return an empty list if:- Path does not exist or maxDepth less or equals than zero
- Path is null
- Path is not a "directory"
- Path exists but cannot be read from
- Parameters:
path
- The path to lookup resources in.searchOptions
- A set of criteria for how resources should be found/filtered- Returns:
- empty set if nothing was found
- Throws:
IOException
- if there is an error searching the system.
-
search
public List<Resource> search(String path, boolean recursive) throws IOException
Description copied from interface:ResourceAccessor
Returns the path to all resources contained in the given path. Multiple resources may be returned with the same path, but only if they are actually unique files. Order is important to pay attention to, they should be returned in a user-expected manner based on this resource accessor.
Should return an empty list if:- Path does not exist
- Path is null
- Path is not a "directory"
- Path exists but cannot be read from
- Parameters:
path
- The path to lookup resources in.recursive
- Set to true and will return paths to contents in subdirectories as well.- Returns:
- empty set if nothing was found
- Throws:
IOException
- if there is an error searching the system.
-
getAll
public List<Resource> getAll(String path) throws IOException
Description copied from interface:ResourceAccessor
Returns allResource
s at the given path. For many resource accessors (such as a file system), only one resource can exist at a given spot, but some accessors (such asCompositeResourceAccessor
orClassLoaderResourceAccessor
) can have multiple resources for a single path.If the resourceAccessor returns multiple values, the returned List should be considered sorted for that resource accessor. For example,
ClassLoaderResourceAccessor
returns them in order based on the configured classloader. Order is important to pay attention to, because users may setGlobalConfiguration.DUPLICATE_FILE_MODE
to pick the "best" file which is defined as "the first file from this function".- Returns:
- null if no resources match the path
- Throws:
IOException
- if there is an unexpected error determining what is at the path
-
-