Top Description Fields Constructors Methods
liquibase.resource

public Class ClassLoaderResourceAccessor

extends AbstractResourceAccessor
Class Inheritance
Known Direct Subclasses
liquibase.resource.OSGiResourceAccessor
Imports
liquibase.Scope, java.io.FileNotFoundException, .IOException, java.net.*, java.nio.file.Paths, java.util.*, java.util.regex.Pattern

An implementation of DirectoryResourceAccessor 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.
See Also
{@link OSGiResourceAccessor} for OSGi-based classloaders

Field Summary

Modifier and TypeField and Description
private CompositeResourceAccessor
private final ClassLoader
protected SortedSet<String>

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources.

protected void
configureAdditionalResourceAccessors(ClassLoader classLoader)

The classloader search logic in search(String, boolean) does not handle jar files well.

public List<String>
describeLocations()

Implements liquibase.resource.ResourceAccessor.describeLocations.

Returns a description of the places this classloader will look for paths.

public List<Resource>
getAll(String path)

Implements liquibase.resource.ResourceAccessor.getAll.

Returns all Resources at the given path.

protected synchronized void
init()

Performs the configuration of this resourceAccessor.

public List<Resource>
search(String
The path to lookup resources in.
path
,
ResourceAccessor.SearchOptions
A set of criteria for how resources should be found/filtered
searchOptions
)

Overrides default liquibase.resource.ResourceAccessor.search.

Returns the path to all resources contained in the given path that match the searchOptions criteria.

public List<Resource>
search(String
The path to lookup resources in.
path
,
boolean
Set to true and will return paths to contents in subdirectories as well.
recursive
)

Implements liquibase.resource.ResourceAccessor.search.

Returns the path to all resources contained in the given path.

Field Detail

additionalResourceAccessorsback to summary
private CompositeResourceAccessor additionalResourceAccessors
classLoaderback to summary
private final ClassLoader classLoader
descriptionback to summary
protected SortedSet<String> description

Constructor Detail

ClassLoaderResourceAccessorback to summary
public ClassLoaderResourceAccessor()
ClassLoaderResourceAccessorback to summary
public ClassLoaderResourceAccessor(ClassLoader classLoader)

Method Detail

closeback to summary
public void close() throws Exception

Implements java.lang.AutoCloseable.close.

Doc from java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

Annotations
@Override
Exceptions
Exception:
if this resource cannot be closed
configureAdditionalResourceAccessorsback to summary
protected void configureAdditionalResourceAccessors(ClassLoader classLoader)

The classloader search logic in search(String, boolean) does not handle jar files well. This method is called by that method to configure an internal ResourceAccessor with paths to search.

describeLocationsback to summary
public List<String> describeLocations()

Implements liquibase.resource.ResourceAccessor.describeLocations.

Doc from liquibase.resource.ResourceAccessor.describeLocations.

Returns a description of the places this classloader will look for paths. Used in error messages and other troubleshooting cases.

Annotations
@Override
getAllback to summary
public List<Resource> getAll(String path) throws IOException

Implements liquibase.resource.ResourceAccessor.getAll.

Doc from liquibase.resource.ResourceAccessor.getAll.

Returns all Resources 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 as CompositeResourceAccessor or ClassLoaderResourceAccessor) 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 set GlobalConfiguration#DUPLICATE_FILE_MODE to pick the "best" file which is defined as "the first file from this function".

Returns:List<Resource>

null if no resources match the path

Annotations
@Override
Exceptions
IOException:
if there is an unexpected error determining what is at the path
initback to summary
protected synchronized 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.

searchback to summary
public List<Resource> search(String path, ResourceAccessor.SearchOptions searchOptions) throws IOException

Overrides default liquibase.resource.ResourceAccessor.search.

Doc from liquibase.resource.ResourceAccessor.search.

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
Should throw an exception if:
  • Path is null
  • Path is not a "directory"
  • Path exists but cannot be read from
Parameters
path:String

The path to lookup resources in.

searchOptions:ResourceAccessor.SearchOptions

A set of criteria for how resources should be found/filtered

Returns:List<Resource>

empty set if nothing was found

Annotations
@Override
Exceptions
IOException:
if there is an error searching the system.
searchback to summary
public List<Resource> search(String path, boolean recursive) throws IOException

Implements liquibase.resource.ResourceAccessor.search.

Doc from liquibase.resource.ResourceAccessor.search.

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
Should throw an exception if:
  • Path is null
  • Path is not a "directory"
  • Path exists but cannot be read from
Parameters
path:String

The path to lookup resources in.

recursive:boolean

Set to true and will return paths to contents in subdirectories as well.

Returns:List<Resource>

empty set if nothing was found

Annotations
@Override
Exceptions
IOException:
if there is an error searching the system.