001 package org.apache.torque.mojo;
002
003 import java.io.File;
004 import java.io.IOException;
005
006 import org.apache.commons.io.FileUtils;
007 import org.apache.maven.plugin.MojoExecutionException;
008 import org.kuali.core.db.torque.KualiTorqueDataDumpTask;
009
010 /**
011 * Reads the content of tables from a database and exports the data in a database agnostic format to XML files.
012 *
013 * @goal exportdata
014 * @phase generate-sources
015 */
016 public class ExportDataMojo extends ExportMojo {
017
018 /**
019 * The format to use for dates/timestamps
020 *
021 * @parameter expression="${dateFormat}" default-value="yyyyMMddHHmmss z"
022 * @required
023 */
024 private String dateFormat;
025
026 /**
027 * The directory where data XML files will be written
028 *
029 * @parameter expression="${dataXMLDir}" default-value="${basedir}/src/main/impex"
030 * @required
031 */
032 private File dataXMLDir;
033
034 /**
035 * Configure the Ant task
036 */
037 protected void configureTask() throws MojoExecutionException {
038 KualiTorqueDataDumpTask task = new KualiTorqueDataDumpTask();
039 setAntTask(task);
040 super.configureTask();
041 makeOutputDir();
042 }
043
044 protected void makeOutputDir() throws MojoExecutionException {
045 if (getDataXMLDir().exists()) {
046 return;
047 }
048 try {
049 FileUtils.forceMkdir(getDataXMLDir());
050 } catch (IOException e) {
051 throw new MojoExecutionException("Error creating output directory", e);
052 }
053 }
054
055 public File getDataXMLDir() {
056 return dataXMLDir;
057 }
058
059 public void setDataXMLDir(File outputDir) {
060 this.dataXMLDir = outputDir;
061 }
062
063 public String getDateFormat() {
064 return dateFormat;
065 }
066
067 public void setDateFormat(String dateFormat) {
068 this.dateFormat = dateFormat;
069 }
070 }