All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.peterphi.std.guice.liquibase.hibernate.RetryAbsoluteAsRelativeResourceAccessor Maven / Gradle / Ivy

There is a newer version: 9.2.0
Show newest version
package com.peterphi.std.guice.liquibase.hibernate;

import liquibase.resource.ResourceAccessor;

import java.io.IOException;
import java.io.InputStream;
import java.util.Set;

/**
 * A filtering {@link ResourceAccessor} implementation that retries unsuccessful absolute resource accesses as relative to /
* This allows a path like /liquibase/changelog.xml to work within a unit test where it would otherwise need to be * written as liquibase/changelog.xml */ class RetryAbsoluteAsRelativeResourceAccessor implements ResourceAccessor { private final ResourceAccessor inner; public RetryAbsoluteAsRelativeResourceAccessor(final ResourceAccessor inner) { this.inner = inner; } /** * Intercepts getResourcesAsStream, the method used to retrieve resources for the master changeset * * @param path * * @return * * @throws IOException */ @Override public Set getResourcesAsStream(final String path) throws IOException { // First, try the path as specified final Set streams = inner.getResourcesAsStream(path); // If no results were found and the path was absolute, retry without the leading slash if ((streams == null || streams.isEmpty()) && !path.isEmpty() && path.charAt(0) == '/') { // Strip the leading slash away and re-try the path // This lets us final String newPath = path.substring(1); return inner.getResourcesAsStream(newPath); } else { return streams; } } @Override public Set list(final String relativeTo, final String path, final boolean includeFiles, final boolean includeDirectories, final boolean recursive) throws IOException { // Does not appear to be used return inner.list(relativeTo, path, includeFiles, includeDirectories, recursive); } @Override public ClassLoader toClassLoader() { // Does not appear to be used return inner.toClassLoader(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy