com.celum.dbtool.mojo.PatchMojo Maven / Gradle / Ivy
package com.celum.dbtool.mojo;
import com.celum.dbtool.Db;
import com.celum.dbtool.configuration.DbConfiguration;
import com.celum.dbtool.resource.DbStepResource;
import com.celum.dbtool.resource.DirResource;
import com.celum.dbtool.resource.PackageResource;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import java.io.File;
/**
* @author Zdenko Vrabel ([email protected])
*
* @goal patch
*/
public class PatchMojo extends AbstractDbMojo
{
/**
* @parameter default-value="${basedir}/src/main/sql/patch"
*/
protected File stepsDir;
/**
* @parameter
*/
protected String stepsPackage;
/**
* @parameter default-value="PATCH"
*/
protected String patchTable;
@Override
public void execute() throws MojoExecutionException, MojoFailureException
{
try {
registerVersionFactoryFromSettings();
DbConfiguration config =
DbConfiguration.createSelfInitConfigurationForTable(patchTable)
.setDataSource(getDataSource())
.setVariables(getParameters())
.setEventListener(this);
if (stepsPackage == null || stepsPackage.isEmpty()) {
config.setStepsSourceForDirectory(stepsDir);
} else {
config.setStepsSource(new PackageResource(stepsPackage, getClassLoaderWithCompiledClasses()));
}
config.build().patch();
} catch (Exception e) {
getLog().error(e);
}
}
}