01: package liquibase.ant;
02:
03: import liquibase.database.Database;
04: import liquibase.diff.Diff;
05: import liquibase.diff.DiffResult;
06: import liquibase.Liquibase;
07: import org.apache.tools.ant.BuildException;
08:
09: import java.io.PrintStream;
10:
11: public class GenerateChangeLogTask extends BaseLiquibaseTask {
12:
13: public void execute() throws BuildException {
14: Liquibase liquibase = null;
15: try {
16: PrintStream writer = createPrintStream();
17: if (writer == null) {
18: throw new BuildException(
19: "generateChangeLog requires outputFile to be set");
20: }
21:
22: liquibase = createLiquibase();
23:
24: Database database = liquibase.getDatabase();
25: Diff diff = new Diff(database, getDefaultSchemaName());
26: // diff.addStatusListener(new OutDiffStatusListener());
27: DiffResult diffResult = diff.compare();
28:
29: diffResult.printChangeLog(writer, database);
30:
31: writer.flush();
32: writer.close();
33: } catch (Exception e) {
34: throw new BuildException(e);
35: } finally {
36: closeDatabase(liquibase);
37: }
38: }
39: }
|