001    /**
002     * Copyright 2004-2012 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.apache.torque.mojo;
017    
018    import java.io.File;
019    import java.io.IOException;
020    
021    import org.apache.commons.io.FileUtils;
022    import org.apache.maven.plugin.MojoExecutionException;
023    import org.kuali.core.db.torque.KualiTorqueDataDumpTask;
024    
025    /**
026     * Reads the content of tables from a database and exports the data in a database agnostic format to XML files.
027     * 
028     * @goal exportdata
029     * @phase generate-sources
030     */
031    public class ExportDataMojo extends ExportMojo {
032    
033        /**
034         * The format to use for dates/timestamps
035         * 
036         * @parameter expression="${dateFormat}" default-value="yyyyMMddHHmmss z"
037         * @required
038         */
039        private String dateFormat;
040    
041        /**
042         * The directory where data XML files will be written
043         * 
044         * @parameter expression="${dataXMLDir}" default-value="${basedir}/src/main/impex"
045         * @required
046         */
047        private File dataXMLDir;
048    
049        /**
050         * Configure the Ant task
051         */
052        @Override
053        protected void configureTask() throws MojoExecutionException {
054            KualiTorqueDataDumpTask task = new KualiTorqueDataDumpTask();
055            task.setBuildDirectory(new File(getProject().getBuild().getDirectory()));
056            setAntTask(task);
057            super.configureTask();
058            makeOutputDir();
059        }
060    
061        protected void makeOutputDir() throws MojoExecutionException {
062            if (getDataXMLDir().exists()) {
063                return;
064            }
065            try {
066                FileUtils.forceMkdir(getDataXMLDir());
067            } catch (IOException e) {
068                throw new MojoExecutionException("Error creating output directory", e);
069            }
070        }
071    
072        public File getDataXMLDir() {
073            return dataXMLDir;
074        }
075    
076        public void setDataXMLDir(File outputDir) {
077            this.dataXMLDir = outputDir;
078        }
079    
080        public String getDateFormat() {
081            return dateFormat;
082        }
083    
084        public void setDateFormat(String dateFormat) {
085            this.dateFormat = dateFormat;
086        }
087    }