1 /**
2 * Copyright 2004-2012 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.apache.torque.mojo;
17
18 import java.io.File;
19 import java.io.IOException;
20
21 import org.apache.commons.io.FileUtils;
22 import org.apache.maven.plugin.MojoExecutionException;
23 import org.kuali.core.db.torque.KualiTorqueDataDumpTask;
24
25 /**
26 * Reads the content of tables from a database and exports the data in a database agnostic format to XML files.
27 *
28 * @goal exportdata
29 * @phase generate-sources
30 */
31 public class ExportDataMojo extends ExportMojo {
32
33 /**
34 * The format to use for dates/timestamps
35 *
36 * @parameter expression="${dateFormat}" default-value="yyyyMMddHHmmss z"
37 * @required
38 */
39 private String dateFormat;
40
41 /**
42 * The directory where data XML files will be written
43 *
44 * @parameter expression="${dataXMLDir}" default-value="${basedir}/src/main/impex"
45 * @required
46 */
47 private File dataXMLDir;
48
49 /**
50 * Configure the Ant task
51 */
52 @Override
53 protected void configureTask() throws MojoExecutionException {
54 KualiTorqueDataDumpTask task = new KualiTorqueDataDumpTask();
55 task.setBuildDirectory(new File(getProject().getBuild().getDirectory()));
56 setAntTask(task);
57 super.configureTask();
58 makeOutputDir();
59 }
60
61 protected void makeOutputDir() throws MojoExecutionException {
62 if (getDataXMLDir().exists()) {
63 return;
64 }
65 try {
66 FileUtils.forceMkdir(getDataXMLDir());
67 } catch (IOException e) {
68 throw new MojoExecutionException("Error creating output directory", e);
69 }
70 }
71
72 public File getDataXMLDir() {
73 return dataXMLDir;
74 }
75
76 public void setDataXMLDir(File outputDir) {
77 this.dataXMLDir = outputDir;
78 }
79
80 public String getDateFormat() {
81 return dateFormat;
82 }
83
84 public void setDateFormat(String dateFormat) {
85 this.dateFormat = dateFormat;
86 }
87 }