Coverage Report - org.liquibase.maven.plugins.LiquibaseChangeLogSyncSQLMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
LiquibaseChangeLogSyncSQLMojo
0%
0/26
0%
0/6
2.4
 
 1  
 package org.liquibase.maven.plugins;
 2  
 
 3  
 import java.io.File;
 4  
 import java.io.FileWriter;
 5  
 import java.io.IOException;
 6  
 import java.io.Writer;
 7  
 
 8  
 import org.apache.maven.plugin.MojoExecutionException;
 9  
 
 10  
 import liquibase.Liquibase;
 11  
 import liquibase.database.Database;
 12  
 import liquibase.exception.LiquibaseException;
 13  
 import liquibase.resource.ResourceAccessor;
 14  
 
 15  
 /**
 16  
  * Generates SQL that marks all unapplied changes as applied.
 17  
  * 
 18  
  * @author JAmes Atwill
 19  
  * @goal changelogSyncSQL
 20  
  */
 21  0
 public class LiquibaseChangeLogSyncSQLMojo extends AbstractLiquibaseChangeLogMojo {
 22  
 
 23  
     /**
 24  
      * The file to output the Migration SQL script to, if it exists it will be overwritten.
 25  
      * 
 26  
      * @parameter expression="${liquibase.migrationSqlOutputFile}" default-value=
 27  
      *            "${project.build.directory}/liquibase/migrate.sql"
 28  
      */
 29  
     protected File migrationSqlOutputFile;
 30  
 
 31  
     /** The writer for writing the migration SQL. */
 32  
     private Writer outputWriter;
 33  
 
 34  
     @Override
 35  
     protected void performLiquibaseTask(Liquibase liquibase) throws LiquibaseException {
 36  0
         liquibase.changeLogSync(contexts, outputWriter);
 37  0
     }
 38  
 
 39  
     @Override
 40  
     protected void printSettings(String indent) {
 41  0
         super.printSettings(indent);
 42  0
         getLog().info(indent + "migrationSQLOutputFile: " + migrationSqlOutputFile);
 43  
 
 44  0
     }
 45  
 
 46  
     @Override
 47  
     protected boolean isPromptOnNonLocalDatabase() {
 48  
         // Always run on an non-local database as we are not actually modifying
 49  
         // the database
 50  
         // when run on it.
 51  0
         return false;
 52  
     }
 53  
 
 54  
     @Override
 55  
     protected Liquibase createLiquibase(ResourceAccessor fo, Database db) throws MojoExecutionException {
 56  0
         Liquibase liquibase = super.createLiquibase(fo, db);
 57  
 
 58  
         // Setup the output file writer
 59  
         try {
 60  0
             if (!migrationSqlOutputFile.exists()) {
 61  
                 // Ensure the parent directories exist
 62  0
                 migrationSqlOutputFile.getParentFile().mkdirs();
 63  
                 // Create the actual file
 64  0
                 if (!migrationSqlOutputFile.createNewFile()) {
 65  0
                     throw new MojoExecutionException("Cannot create the migration SQL file; "
 66  
                             + migrationSqlOutputFile.getAbsolutePath());
 67  
                 }
 68  
             }
 69  0
             outputWriter = new FileWriter(migrationSqlOutputFile);
 70  0
         } catch (IOException e) {
 71  0
             getLog().error(e);
 72  0
             throw new MojoExecutionException("Failed to create SQL output writer", e);
 73  0
         }
 74  0
         getLog().info("Output SQL Migration File: " + migrationSqlOutputFile.getAbsolutePath());
 75  0
         return liquibase;
 76  
     }
 77  
 
 78  
     @Override
 79  
     protected void cleanup(Database db) {
 80  0
         super.cleanup(db);
 81  0
         if (outputWriter != null) {
 82  
             try {
 83  0
                 outputWriter.close();
 84  0
             } catch (IOException e) {
 85  0
                 getLog().error(e);
 86  0
             }
 87  
         }
 88  0
     }
 89  
 
 90  
 }