001    /**
002     * Copyright 2004-2013 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="${impex.antSchemaName}" default-value= "kfs"
037             * @required
038             */
039            private String antSchemaName;
040    
041            /**
042             * The XML file describing the database schema (Maven style)
043             *
044             * @parameter expression="${newSchemaXMLFile}" default-value= "${project.build.directory}/generated-impex/${project.artifactId}.xml"
045             * @required
046             */
047            private File newSchemaXMLFile;
048    
049            /**
050             * The XML file describing the database schema (Ant style)
051             *
052             * @parameter expression="${oldSchemaXMLFile}" default-value="${basedir}/src/main/impex/schema.xml"
053             * @required
054             */
055            private File oldSchemaXMLFile;
056    
057            @Override
058            protected void beforeExecution() {
059                    setNewFile(newSchemaXMLFile);
060                    setOldFile(oldSchemaXMLFile);
061            }
062    
063            @Override
064            protected void executeMojo() throws MojoExecutionException {
065                    getLog().info("------------------------------------------------------------------------");
066                    getLog().info("Converting schema XML file");
067                    getLog().info("------------------------------------------------------------------------");
068                    super.executeMojo();
069            }
070    
071            @Override
072            protected Morpher getMorpher(final MorphRequest request, final String artifactId) {
073                    SchemaMorpher morpher = new SchemaMorpher(request, artifactId);
074                    morpher.setAntSchemaName(antSchemaName);
075                    morpher.setAntSchemaToken("name=\"" + antSchemaName + "\"");
076                    return morpher;
077            }
078    
079            public File getNewSchemaXMLFile() {
080                    return newSchemaXMLFile;
081            }
082    
083            public void setNewSchemaXMLFile(final File newSchemaXMLFile) {
084                    this.newSchemaXMLFile = newSchemaXMLFile;
085            }
086    
087            public File getOldSchemaXMLFile() {
088                    return oldSchemaXMLFile;
089            }
090    
091            public void setOldSchemaXMLFile(final File oldSchemaXMLFile) {
092                    this.oldSchemaXMLFile = oldSchemaXMLFile;
093            }
094    
095            public String getAntSchemaName() {
096                    return antSchemaName;
097            }
098    
099            public void setAntSchemaName(String antSchemaName) {
100                    this.antSchemaName = antSchemaName;
101            }
102    }