01: package liquibase.dbdoc;
02:
03: import liquibase.ChangeSet;
04: import liquibase.change.Change;
05: import liquibase.database.Database;
06: import liquibase.exception.MigrationFailedException;
07: import liquibase.Liquibase;
08:
09: import java.io.File;
10: import java.io.FileWriter;
11: import java.io.IOException;
12: import java.util.List;
13:
14: public class PendingSQLWriter extends HTMLWriter {
15:
16: public PendingSQLWriter(File rootOutputDir, Database database) {
17: super (new File(rootOutputDir, "pending"), database);
18: }
19:
20: protected String createTitle(Object object) {
21: return "Pending SQL";
22: }
23:
24: protected void writeBody(FileWriter fileWriter, Object object,
25: List<Change> ranChanges, List<Change> changesToRun,
26: Liquibase liquibase) throws IOException {
27: if (changesToRun.size() == 0) {
28: fileWriter.append("<b>NONE</b>");
29: }
30:
31: fileWriter.append("<code><pre>");
32:
33: ChangeSet lastRunChangeSet = null;
34:
35: for (Change change : changesToRun) {
36: ChangeSet this ChangeSet = change.getChangeSet();
37: if (this ChangeSet.equals(lastRunChangeSet)) {
38: continue;
39: }
40: lastRunChangeSet = this ChangeSet;
41: String anchor = this ChangeSet.toString(false).replaceAll(
42: "\\W", "_");
43: fileWriter.append("<a name='").append(anchor).append("'/>");
44: try {
45: this ChangeSet.execute(liquibase.getDatabase());
46: } catch (MigrationFailedException e) {
47: fileWriter.append("EXECUTION ERROR: ").append(
48: change.getChangeName()).append(": ").append(
49: e.getMessage()).append("\n\n");
50: }
51: }
52: fileWriter.append("</pre></code>");
53: }
54:
55: protected void writeCustomHTML(FileWriter fileWriter,
56: Object object, List<Change> changes, Database database)
57: throws IOException {
58: }
59: }
|