1 package liquibase.integration.ant;
2
3 import liquibase.Liquibase;
4 import liquibase.util.ui.UIFactory;
5 import org.apache.tools.ant.BuildException;
6
7
8
9
10 public class DatabaseUpdateTestingRollbackTask extends BaseLiquibaseTask {
11 private boolean dropFirst = false;
12
13 public boolean isDropFirst() {
14 return dropFirst;
15 }
16
17 public void setDropFirst(boolean dropFirst) {
18 this.dropFirst = dropFirst;
19 }
20
21 @Override
22 public void execute() throws BuildException {
23 if (!shouldRun()) {
24 return;
25 }
26
27 super.execute();
28
29 Liquibase liquibase = null;
30 try {
31 liquibase = createLiquibase();
32
33 if (isPromptOnNonLocalDatabase() && !liquibase.isSafeToRunMigration()
34 && UIFactory.getInstance().getFacade().promptForNonLocalDatabase(liquibase.getDatabase())) {
35 throw new BuildException("Chose not to run against non-production database");
36 }
37
38 if (isDropFirst()) {
39 liquibase.dropAll();
40 }
41
42 liquibase.updateTestingRollback(getContexts());
43
44 } catch (Exception e) {
45 throw new BuildException(e);
46 } finally {
47 closeDatabase(liquibase);
48 }
49 }
50 }