View Javadoc

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  
20  import org.apache.maven.plugin.MojoExecutionException;
21  import org.apache.torque.mojo.morph.MorphRequest;
22  import org.apache.torque.mojo.morph.Morpher;
23  import org.apache.torque.mojo.morph.SchemaMorpher;
24  
25  /**
26   * Convert an Ant impex schema XML file into a maven-impex-plugin schema XML file
27   *
28   * @goal morphschema
29   * @phase generate-sources
30   */
31  public class MorphSchemaMojo extends AbstractMorphSingleMojo {
32  
33  	/**
34  	 * The XML file describing the database schema (Maven style)
35  	 *
36  	 * @parameter expression="${impex.antSchemaName}" default-value= "kfs"
37  	 * @required
38  	 */
39  	private String antSchemaName;
40  
41  	/**
42  	 * The XML file describing the database schema (Maven style)
43  	 *
44  	 * @parameter expression="${newSchemaXMLFile}" default-value= "${project.build.directory}/generated-impex/${project.artifactId}.xml"
45  	 * @required
46  	 */
47  	private File newSchemaXMLFile;
48  
49  	/**
50  	 * The XML file describing the database schema (Ant style)
51  	 *
52  	 * @parameter expression="${oldSchemaXMLFile}" default-value="${basedir}/src/main/impex/schema.xml"
53  	 * @required
54  	 */
55  	private File oldSchemaXMLFile;
56  
57  	@Override
58  	protected void beforeExecution() {
59  		setNewFile(newSchemaXMLFile);
60  		setOldFile(oldSchemaXMLFile);
61  	}
62  
63  	@Override
64  	protected void executeMojo() throws MojoExecutionException {
65  		getLog().info("------------------------------------------------------------------------");
66  		getLog().info("Converting schema XML file");
67  		getLog().info("------------------------------------------------------------------------");
68  		super.executeMojo();
69  	}
70  
71  	@Override
72  	protected Morpher getMorpher(final MorphRequest request, final String artifactId) {
73  		SchemaMorpher morpher = new SchemaMorpher(request, artifactId);
74  		morpher.setAntSchemaName(antSchemaName);
75  		morpher.setAntSchemaToken("name=\"" + antSchemaName + "\"");
76  		return morpher;
77  	}
78  
79  	public File getNewSchemaXMLFile() {
80  		return newSchemaXMLFile;
81  	}
82  
83  	public void setNewSchemaXMLFile(final File newSchemaXMLFile) {
84  		this.newSchemaXMLFile = newSchemaXMLFile;
85  	}
86  
87  	public File getOldSchemaXMLFile() {
88  		return oldSchemaXMLFile;
89  	}
90  
91  	public void setOldSchemaXMLFile(final File oldSchemaXMLFile) {
92  		this.oldSchemaXMLFile = oldSchemaXMLFile;
93  	}
94  
95  	public String getAntSchemaName() {
96  		return antSchemaName;
97  	}
98  
99  	public void setAntSchemaName(String antSchemaName) {
100 		this.antSchemaName = antSchemaName;
101 	}
102 }