Coverage Report - org.liquibase.maven.plugins.AbstractLiquibaseChangeLogMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractLiquibaseChangeLogMojo
5%
1/17
0%
0/4
2.2
 
 1  
 // Version: $Id: $
 2  
 // Copyright: Copyright(c) 2007 Trace Financial Limited
 3  
 package org.liquibase.maven.plugins;
 4  
 
 5  
 import liquibase.Liquibase;
 6  
 import liquibase.database.Database;
 7  
 import liquibase.exception.LiquibaseException;
 8  
 import liquibase.resource.CompositeResourceAccessor;
 9  
 import liquibase.resource.FileSystemResourceAccessor;
 10  
 import liquibase.resource.ResourceAccessor;
 11  
 
 12  
 import org.apache.maven.plugin.MojoExecutionException;
 13  
 import org.apache.maven.plugin.MojoFailureException;
 14  
 
 15  
 /**
 16  
  * A Liquibase MOJO that requires the user to provide a DatabaseChangeLogFile to be able to perform any actions on the
 17  
  * database.
 18  
  * 
 19  
  * @author Peter Murray
 20  
  */
 21  8
 public abstract class AbstractLiquibaseChangeLogMojo extends AbstractLiquibaseMojo {
 22  
 
 23  
     /**
 24  
      * Specifies the change log file to use for Liquibase.
 25  
      * 
 26  
      * @parameter expression="${liquibase.changeLogFile}"
 27  
      */
 28  
     protected String changeLogFile;
 29  
 
 30  
     /**
 31  
      * The Liquibase contexts to execute, which can be "," separated if multiple contexts are required. If no context is
 32  
      * specified then ALL contexts will be executed.
 33  
      * 
 34  
      * @parameter expression="${liquibase.contexts}" default-value=""
 35  
      */
 36  
     protected String contexts;
 37  
 
 38  
     @Override
 39  
     protected void checkRequiredParametersAreSpecified() throws MojoFailureException {
 40  0
         super.checkRequiredParametersAreSpecified();
 41  
 
 42  0
         if (changeLogFile == null) {
 43  0
             throw new MojoFailureException("The changeLogFile must be specified.");
 44  
         }
 45  0
     }
 46  
 
 47  
     /**
 48  
      * Performs the actual Liquibase task on the database using the fully configured {@link liquibase.Liquibase}.
 49  
      * 
 50  
      * @param liquibase
 51  
      *            The {@link liquibase.Liquibase} that has been fully configured to run the desired database task.
 52  
      */
 53  
     @Override
 54  
     protected void performLiquibaseTask(Liquibase liquibase) throws LiquibaseException {
 55  0
     }
 56  
 
 57  
     @Override
 58  
     protected void printSettings(String indent) {
 59  0
         super.printSettings(indent);
 60  0
         getLog().info(indent + "changeLogFile: " + changeLogFile);
 61  0
         getLog().info(indent + "context(s): " + contexts);
 62  0
     }
 63  
 
 64  
     @Override
 65  
     protected ResourceAccessor getFileOpener(ClassLoader cl) {
 66  0
         ResourceAccessor mFO = new MavenResourceAccessor(cl);
 67  0
         ResourceAccessor fsFO = new FileSystemResourceAccessor(project.getBasedir().getAbsolutePath());
 68  0
         return new CompositeResourceAccessor(mFO, fsFO);
 69  
     }
 70  
 
 71  
     @Override
 72  
     protected Liquibase createLiquibase(ResourceAccessor fo, Database db) throws MojoExecutionException {
 73  
         try {
 74  0
             String changeLog = changeLogFile == null ? "" : changeLogFile.trim();
 75  0
             return new Liquibase(changeLog, fo, db);
 76  0
         } catch (LiquibaseException ex) {
 77  0
             throw new MojoExecutionException("Error creating liquibase: " + ex.getMessage(), ex);
 78  
         }
 79  
     }
 80  
 }