liquibase.dbdoc.ChangeLogWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of liquibase-core Show documentation
Show all versions of liquibase-core Show documentation
Liquibase is a tool for managing and executing database changes.
package liquibase.dbdoc;
import liquibase.GlobalConfiguration;
import liquibase.resource.ResourceAccessor;
import liquibase.util.StreamUtil;
import java.io.*;
public class ChangeLogWriter {
protected File outputDir;
private ResourceAccessor resourceAccessor;
public ChangeLogWriter(ResourceAccessor resourceAccessor, File rootOutputDir) {
this.outputDir = new File(rootOutputDir, "changelogs");
this.resourceAccessor = resourceAccessor;
}
public void writeChangeLog(String changeLog, String physicalFilePath) throws IOException {
String changeLogOutFile = changeLog.replace(":", "_");
File xmlFile = new File(outputDir, changeLogOutFile.toLowerCase() + ".html");
xmlFile.getParentFile().mkdirs();
BufferedWriter changeLogStream = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(xmlFile,
false), GlobalConfiguration.OUTPUT_FILE_ENCODING.getCurrentValue()));
try (InputStream stylesheet = resourceAccessor.openStream(null, physicalFilePath)) {
if (stylesheet == null) {
throw new IOException("Can not find " + changeLog);
}
changeLogStream.write("\n");
changeLogStream.write(StreamUtil.readStreamAsString(stylesheet).replace("<", "<").replace(">", ">"));
changeLogStream.write("\n
");
} finally {
changeLogStream.close();
}
}
}