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 @Override 038 protected void configureTask() throws MojoExecutionException { 039 KualiTorqueDataDumpTask task = new KualiTorqueDataDumpTask(); 040 task.setBuildDirectory(new File(getProject().getBuild().getDirectory())); 041 setAntTask(task); 042 super.configureTask(); 043 makeOutputDir(); 044 } 045 046 protected void makeOutputDir() throws MojoExecutionException { 047 if (getDataXMLDir().exists()) { 048 return; 049 } 050 try { 051 FileUtils.forceMkdir(getDataXMLDir()); 052 } catch (IOException e) { 053 throw new MojoExecutionException("Error creating output directory", e); 054 } 055 } 056 057 public File getDataXMLDir() { 058 return dataXMLDir; 059 } 060 061 public void setDataXMLDir(File outputDir) { 062 this.dataXMLDir = outputDir; 063 } 064 065 public String getDateFormat() { 066 return dateFormat; 067 } 068 069 public void setDateFormat(String dateFormat) { 070 this.dateFormat = dateFormat; 071 } 072 }