Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
Liquibase's XMLChangeLogSAXParser now gets the Resource instead of an…
Browse files Browse the repository at this point in the history
… InputStream, LiquibaseMigrate adapted to these changes.
  • Loading branch information
softqwewasdfortnox committed Nov 10, 2022
1 parent f7a7fe5 commit a6fc35c
Showing 1 changed file with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
import liquibase.ext.TimeoutLockService;
import liquibase.lockservice.LockServiceFactory;
import liquibase.resource.ClassLoaderResourceAccessor;
import liquibase.resource.InputStreamList;
import liquibase.resource.Resource;
import liquibase.resource.URIResource;
import se.fortnox.reactivewizard.db.DbDriver;

import javax.inject.Inject;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
Expand Down Expand Up @@ -56,9 +56,7 @@ public LiquibaseMigrate(LiquibaseConfig liquibaseConfig) throws LiquibaseExcepti
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
String file = url.toExternalForm();
int jarFileSep = file.lastIndexOf('!');
String loggedFileName = file.substring(jarFileSep + 1);
Liquibase liquibase = new Liquibase(loggedFileName, new UrlAwareClassLoaderResourceAccessor(file), conn);
Liquibase liquibase = new Liquibase(file, new UrlAwareClassLoaderResourceAccessor(file), conn);
liquibase.getDatabase().setDefaultSchemaName(liquibaseConfig.getSchema());

liquibaseList.add(liquibase);
Expand Down Expand Up @@ -152,34 +150,30 @@ void exit() {
System.exit(0);
}

class UrlAwareClassLoaderResourceAccessor extends ClassLoaderResourceAccessor {
static class UrlAwareClassLoaderResourceAccessor extends ClassLoaderResourceAccessor {
private final String realFileName;

public UrlAwareClassLoaderResourceAccessor(String realFileName) {
this.realFileName = realFileName;
}

@Override
public InputStreamList openStreams(String relativeTo, String path) throws IOException {
public Resource get(String path) throws IOException {
if (realFileName.endsWith(path)) {
path = realFileName;
}

if (path.startsWith("file:") || path.startsWith("jar:file:")) {
URL url = new URL(path);
InputStream resourceAsStream = url.openStream();
InputStreamList inputStreamList = new InputStreamList();
URI uri;
try {
uri = url.toURI();
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
inputStreamList.add(uri, resourceAsStream);

return inputStreamList;
return new URIResource(path, uri);
}
return super.openStreams(relativeTo, path);
return super.get(path);
}
}
}

0 comments on commit a6fc35c

Please sign in to comment.