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    
020    import org.apache.maven.plugin.MojoExecutionException;
021    import org.apache.torque.mojo.morph.MorphRequest;
022    import org.apache.torque.mojo.morph.Morpher;
023    import org.apache.torque.mojo.morph.SchemaMorpher;
024    
025    /**
026     * Convert an Ant impex schema XML file into a maven-impex-plugin schema XML file
027     *
028     * @goal morphschema
029     * @phase generate-sources
030     */
031    public class MorphSchemaMojo extends AbstractMorphSingleMojo {
032    
033        /**
034         * The XML file describing the database schema (Maven style)
035         *
036         * @parameter expression="${newSchemaXMLFile}" default-value=
037         *            "${project.build.directory}/generated-impex/${project.artifactId}.xml"
038         * @required
039         */
040        private File newSchemaXMLFile;
041    
042        /**
043         * The XML file describing the database schema (Ant style)
044         *
045         * @parameter expression="${oldSchemaXMLFile}" default-value="${basedir}/src/main/impex/schema.xml"
046         * @required
047         */
048        private File oldSchemaXMLFile;
049    
050        @Override
051        protected void beforeExecution() {
052            setNewFile(newSchemaXMLFile);
053            setOldFile(oldSchemaXMLFile);
054        }
055    
056        @Override
057        protected void executeMojo() throws MojoExecutionException {
058            getLog().info("------------------------------------------------------------------------");
059            getLog().info("Converting schema XML file");
060            getLog().info("------------------------------------------------------------------------");
061            super.executeMojo();
062        }
063    
064        @Override
065        protected Morpher getMorpher(final MorphRequest request, final String artifactId) {
066            return new SchemaMorpher(request, artifactId);
067        }
068    
069        public File getNewSchemaXMLFile() {
070            return newSchemaXMLFile;
071        }
072    
073        public void setNewSchemaXMLFile(final File newSchemaXMLFile) {
074            this.newSchemaXMLFile = newSchemaXMLFile;
075        }
076    
077        public File getOldSchemaXMLFile() {
078            return oldSchemaXMLFile;
079        }
080    
081        public void setOldSchemaXMLFile(final File oldSchemaXMLFile) {
082            this.oldSchemaXMLFile = oldSchemaXMLFile;
083        }
084    }