In 2018, there was a post on stackoverflow regarding this question, which can be found here: Run liquibase with changelog xml as stream input
I’ve tested this solution with version 4.16.0 and it still works. However, when migrating to version 4.18.0 this no longer works. AbstractResourceAccessor
has new methods such as search
. I noticed that in the release notes extending the ResourceAccessor is a breaking change. Looking in github, i don’t see any ResourceAccessors for stream inputs yet: liquibase/liquibase-core/src/main/java/liquibase/resource at master · liquibase/liquibase · GitHub.
How do i fix the extended class, to accept streams as input with version 4.18.0? It says that the file cannot be found on the search path. Here is my class:
public class StreamResourceAccessor extends AbstractResourceAccessor {
private String xml;
public StreamResourceAccessor(String xml) {
super();
this.xml = xml;
}
@Override
public InputStreamList openStreams(String relativeTo, String streamPath) {
InputStreamList list = new InputStreamList();
InputStream xmlBytesStream = new ByteArrayInputStream(this.xml.getBytes());
list.add(URI.create(streamPath), xmlBytesStream);
return list;
}
@Override
public SortedSet<String> list(String relativeTo, String path, boolean recursive, boolean includeFiles,
boolean includeDirectories) throws IOException {
return new TreeSet<>();
}
@Override
public List<Resource> search(String path, boolean recursive) throws IOException {
// TODO Auto-generated method stub
return null;
}
@Override
public List<Resource> getAll(String path) throws IOException {
// TODO Auto-generated method stub
return null;
}
@Override
public List<String> describeLocations() {
// TODO Auto-generated method stub
return null;
}
@Override
public void close() throws Exception {
// TODO Auto-generated method stub
}
}