Coverage Report - org.liquibase.maven.plugins.LiquibaseMigrateSQL
 
Classes in this File Line Coverage Branch Coverage Complexity
LiquibaseMigrateSQL
0%
0/31
0%
0/8
2.333
 
 1  
 // Version: $Id: $
 2  
 // Copyright: Copyright(c) 2007 Trace Financial Limited
 3  
 package org.liquibase.maven.plugins;
 4  
 
 5  
 import java.io.*;
 6  
 import liquibase.resource.ResourceAccessor;
 7  
 import liquibase.Liquibase;
 8  
 import liquibase.database.Database;
 9  
 import liquibase.exception.LiquibaseException;
 10  
 import org.apache.maven.plugin.MojoExecutionException;
 11  
 import org.apache.maven.plugin.MojoFailureException;
 12  
 
 13  
 /**
 14  
  * Creates an SQL migration script using the provided DatabaseChangeLog(s) comparing what already exists in the database
 15  
  * to what is defined in the DataBaseChangeLog(s).
 16  
  * 
 17  
  * @author Peter Murray
 18  
  * @description Liquibase Migrate SQL Maven plugin
 19  
  * @goal migrateSQL
 20  
  * @deprecated Use {@link LiquibaseUpdateSQL} or Maven goal "updateSQL" instead.
 21  
  */
 22  0
 public class LiquibaseMigrateSQL extends AbstractLiquibaseUpdateMojo {
 23  
 
 24  
     /**
 25  
      * The file to output the Migration SQL script to, if it exists it will be overwritten.
 26  
      * 
 27  
      * @parameter expression="${liquibase.migrationSqlOutputFile}"
 28  
      *            default-value="${project.build.directory}/liquibase/migrate.sql"
 29  
      */
 30  
     protected File migrationSqlOutputFile;
 31  
 
 32  
     /** The writer fro writing the migration SQL. */
 33  
     private Writer outputWriter;
 34  
 
 35  
     @Override
 36  
     public void configureFieldsAndValues(ResourceAccessor fo) throws MojoExecutionException, MojoFailureException {
 37  0
         getLog().warn(
 38  
                 "This plugin goal is DEPRICATED and will bre removed in a future "
 39  
                         + "release, please use \"updateSQL\" instead of \"migrateSQL\".");
 40  0
         super.configureFieldsAndValues(fo);
 41  0
     }
 42  
 
 43  
     @Override
 44  
     protected boolean isPromptOnNonLocalDatabase() {
 45  
         // Always run on an non-local database as we are not actually modifying the database
 46  
         // when run on it.
 47  0
         return false;
 48  
     }
 49  
 
 50  
     @Override
 51  
     protected void doUpdate(Liquibase liquibase) throws LiquibaseException {
 52  0
         if (changesToApply > 0) {
 53  0
             liquibase.update(changesToApply, contexts, outputWriter);
 54  
         } else {
 55  0
             liquibase.update(contexts, outputWriter);
 56  
         }
 57  0
     }
 58  
 
 59  
     @Override
 60  
     protected Liquibase createLiquibase(ResourceAccessor fo, Database db) throws MojoExecutionException {
 61  0
         Liquibase liquibase = super.createLiquibase(fo, db);
 62  
 
 63  
         // Setup the output file writer
 64  
         try {
 65  0
             if (!migrationSqlOutputFile.exists()) {
 66  
                 // Ensure the parent directories exist
 67  0
                 migrationSqlOutputFile.getParentFile().mkdirs();
 68  
                 // Create the actual file
 69  0
                 if (!migrationSqlOutputFile.createNewFile()) {
 70  0
                     throw new MojoExecutionException("Cannot create the migration SQL file; "
 71  
                             + migrationSqlOutputFile.getAbsolutePath());
 72  
                 }
 73  
             }
 74  0
             outputWriter = new FileWriter(migrationSqlOutputFile);
 75  0
         } catch (IOException e) {
 76  0
             getLog().error(e);
 77  0
             throw new MojoExecutionException("Failed to create SQL output writer", e);
 78  0
         }
 79  0
         getLog().info("Output SQL Migration File: " + migrationSqlOutputFile.getAbsolutePath());
 80  0
         return liquibase;
 81  
     }
 82  
 
 83  
     @Override
 84  
     protected void printSettings(String indent) {
 85  0
         super.printSettings(indent);
 86  0
         getLog().info(indent + "migrationSQLOutputFile: " + migrationSqlOutputFile);
 87  0
     }
 88  
 
 89  
     @Override
 90  
     protected void cleanup(Database db) {
 91  0
         super.cleanup(db);
 92  0
         if (outputWriter != null) {
 93  
             try {
 94  0
                 outputWriter.close();
 95  0
             } catch (IOException e) {
 96  0
                 getLog().error(e);
 97  0
             }
 98  
         }
 99  0
     }
 100  
 }