Coverage Report - liquibase.integration.ant.DatabaseUpdateTask
 
Classes in this File Line Coverage Branch Coverage Complexity
DatabaseUpdateTask
7%
2/27
0%
0/14
5
 
 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  
 import java.io.Writer;
 8  
 
 9  
 /**
 10  
  * Ant task for migrating a database forward.
 11  
  */
 12  1
 public class DatabaseUpdateTask extends BaseLiquibaseTask {
 13  1
     private boolean dropFirst = false;
 14  
 
 15  
     public boolean isDropFirst() {
 16  0
         return dropFirst;
 17  
     }
 18  
 
 19  
     public void setDropFirst(boolean dropFirst) {
 20  0
         this.dropFirst = dropFirst;
 21  0
     }
 22  
 
 23  
     @Override
 24  
     public void execute() throws BuildException {
 25  0
         if (!shouldRun()) {
 26  0
             return;
 27  
         }
 28  
 
 29  0
         super.execute();
 30  
 
 31  0
         Liquibase liquibase = null;
 32  
         try {
 33  0
             liquibase = createLiquibase();
 34  
 
 35  0
             if (isPromptOnNonLocalDatabase() && !liquibase.isSafeToRunMigration()
 36  
                     && UIFactory.getInstance().getFacade().promptForNonLocalDatabase(liquibase.getDatabase())) {
 37  0
                 throw new BuildException("Chose not to run against non-production database");
 38  
             }
 39  
 
 40  0
             Writer writer = createOutputWriter();
 41  0
             if (writer == null) {
 42  0
                 if (isDropFirst()) {
 43  0
                     liquibase.dropAll();
 44  
                 }
 45  
 
 46  0
                 liquibase.update(getContexts());
 47  
             } else {
 48  0
                 if (isDropFirst()) {
 49  0
                     throw new BuildException("Cannot dropFirst when outputting update SQL");
 50  
                 }
 51  0
                 liquibase.update(getContexts(), writer);
 52  0
                 writer.flush();
 53  0
                 writer.close();
 54  
             }
 55  
 
 56  0
         } catch (Exception e) {
 57  0
             throw new BuildException(e);
 58  
         } finally {
 59  0
             closeDatabase(liquibase);
 60  0
         }
 61  0
     }
 62  
 }