package liquibase.integration.ant;

import liquibase.Liquibase;
import liquibase.database.Database;
import liquibase.diff.Diff;
import liquibase.diff.DiffResult;
import org.apache.tools.ant.BuildException;

import java.io.PrintStream;

public class GenerateChangeLogTask extends BaseLiquibaseTask {

	private String diffTypes;

	public String getDiffTypes() {
		return diffTypes;
	}

	public void setDiffTypes(String diffTypes) {
		this.diffTypes = diffTypes;
	}

	@Override
	public void execute() throws BuildException {
        super.execute();
        
		Liquibase liquibase = null;
		try {
			PrintStream writer = createPrintStream();
			if (writer == null) {
				throw new BuildException("generateChangeLog requires outputFile to be set");
			}

			liquibase = createLiquibase();

			Database database = liquibase.getDatabase();
			Diff diff = new Diff(database, getDefaultSchemaName());
			if (getDiffTypes() != null) {
				diff.setDiffTypes(getDiffTypes());
			}
//			diff.addStatusListener(new OutDiffStatusListener());
			DiffResult diffResult = diff.compare();

			if (getChangeLogFile() == null) {
				diffResult.printChangeLog(writer, database);
			} else {
				diffResult.printChangeLog(getChangeLogFile(), database);
			}

			writer.flush();
			writer.close();
		} catch (Exception e) {
			throw new BuildException(e);
		} finally {
			closeDatabase(liquibase);
		}
	}
}

@@ -332,16 +332,45 @@
 fTypes;%0D
+%0A    private String dataDir;%0D
 %0A%0D%0A%09publ
@@ -508,17 +508,176 @@
 %0D%0A%09%7D%0D%0A%0D%0A
-%09
+    public String getDataDir() %7B%0D%0A        return dataDir;%0D%0A    %7D%0D%0A%0D%0A    public void setDataDir(String dataDir) %7B%0D%0A        this.dataDir = dataDir;%0D%0A    %7D%0D%0A%0D%0A    
 @Overrid
@@ -1289,24 +1289,74 @@
 .compare();%0D
+%0A            diffResult.setDataDir(getDataDir());%0D
 %0A%0D%0A%09%09%09if (ge

support data dir in generateChangeLog ant task