Clover Coverage Report - Impex Parent 1.0.21-SNAPSHOT (Aggregated)
Coverage timestamp: Tue Feb 8 2011 11:33:53 EST
../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
37   209   18   2.47
4   97   0.49   15
15     1.2  
1    
 
  DataDtdMojo       Line # 18 37 0% 18 56 0% 0.0
 
No Tests
 
1    package org.apache.torque.mojo;
2   
3    import java.io.File;
4    import java.io.IOException;
5   
6    import org.apache.commons.configuration.PropertiesConfiguration;
7    import org.apache.commons.io.FileUtils;
8    import org.apache.maven.plugin.MojoExecutionException;
9    import org.apache.torque.task.TorqueDataModelTask;
10    import org.kuali.core.db.torque.Utils;
11   
12    /**
13    * Generates a DTD for the database tables from a schema XML file
14    *
15    * @goal datadtd
16    * @phase generate-sources
17    */
 
18    public class DataDtdMojo extends DataModelTaskMojo {
19    /** The context property for the name of the project. */
20    public static final String PROJECT_CONTEXT_PROPERTY = "project";
21   
22    /**
23    * @parameter expression="${antCompatibilityMode}" antCompatibilityMode="false"
24    */
25    boolean antCompatibilityMode;
26   
27    /**
28    * Only used if antCompatibilityMode is set to true. If so, the dtd that gets generated will be copied to
29    *
30    * @parameter expression="${copyToFile}" default-value="${basedir}/src/main/impex/data.dtd"
31    */
32    String copyToFile;
33   
34    /**
35    * Included here as a simple property to facilitate generating DTD's for other artifacts
36    *
37    * @parameter expression="${artifactId}" default-value="${project.artifactId}"
38    */
39    String artifactId;
40   
41    /**
42    * The directory in which the DTD will be generated
43    *
44    * @parameter property="outputDir" expression="${outputDir}"
45    * default-value="${project.build.directory}/generated-impex"
46    */
47    @SuppressWarnings("unused")
48    private String dummy1;
49   
50    /**
51    * The location where the report file will be generated, relative to outputDir.
52    *
53    * @parameter property="reportFile" expression="${reportFile}"
54    * default-value="../reports/report.${project.artifactId}.datadtd.generation"
55    */
56    @SuppressWarnings("unused")
57    private String dummy2;
58   
59    /**
60    * The location where the context property file for velocity will be generated.
61    *
62    * @parameter property="contextPropertiesPath" expression="${contextPropertiesPath}"
63    * default-value="${project.build.directory}/reports/context.datadtd.properties"
64    */
65    @SuppressWarnings("unused")
66    private String dummy3;
67   
68    /**
69    * The name of the project
70    *
71    * @parameter expression="${projectName}" default-value="impex"
72    */
73    private String projectName;
74   
75    /**
76    * The name of the schema.xml file to process
77    *
78    * @parameter expression="${schemaXMLFile}"
79    * default-value="${project.build.directory}/generated-impex/${project.artifactId}.xml"
80    * @required
81    */
82    private String schemaXMLFile;
83   
84    /**
85    * Returns the context properties for the Texen task.
86    *
87    * @return The PropertiesConfiguration containing all context properties, not null.
88    */
 
89  0 toggle @Override
90    protected PropertiesConfiguration getMojoContextProperties() {
91  0 PropertiesConfiguration configuration = new PropertiesConfiguration();
92  0 configuration.addProperty(PROJECT_CONTEXT_PROPERTY, getProjectName());
93  0 configuration.addProperty("version", getProject().getVersion());
94  0 return configuration;
95    }
96   
 
97  0 toggle protected void showConfig() {
98  0 getLog().info("Schema XML File: " + schemaXMLFile);
99  0 getLog().info("Ant Compatibility Mode: " + antCompatibilityMode);
100  0 getLog().info("Output Directory: " + getOutputDir());
101    }
102   
103    /**
104    * Configures the Texen task wrapped by this mojo
105    */
 
106  0 toggle @Override
107    protected void configureTask() throws MojoExecutionException {
108  0 TorqueDataModelTask task = new TorqueDataModelTask();
109  0 setAntTask(task);
110  0 super.configureTask();
111  0 boolean exists = new Utils().isFileOrResource(getSchemaXMLFile());
112  0 if (!exists) {
113  0 throw new MojoExecutionException("Unable to locate: " + getSchemaXMLFile());
114    }
115  0 task.setXmlFile(getSchemaXMLFile());
116   
117    }
118   
119    /**
120    * Returns the path to the control template.
121    *
122    * @return "data/Control.vm"
123    */
 
124  0 toggle @Override
125    protected String getControlTemplate() {
126  0 return "data/Control.vm";
127    }
128   
129    /**
130    * Returns the name of the project
131    *
132    * @return the name of the project.
133    */
 
134  0 toggle public String getProjectName() {
135  0 return projectName;
136    }
137   
138    /**
139    * Sets the name of the project
140    *
141    * @param project
142    * the name of the project.
143    */
 
144  0 toggle public void setProjectName(final String projectName) {
145  0 this.projectName = projectName;
146    }
147   
148    /**
149    * Returns the name of the xml file to process.
150    *
151    * @return the name of the xml file to process.
152    */
 
153  0 toggle public String getSchemaXMLFile() {
154  0 return schemaXMLFile;
155    }
156   
157    /**
158    * Sets the name of the xml file to process.
159    *
160    * @param project
161    * the name of the xml file to process.
162    */
 
163  0 toggle public void setSchemaXMLFile(final String xmlFile) {
164  0 this.schemaXMLFile = xmlFile;
165    }
166   
 
167  0 toggle @Override
168    public void executeMojo() throws MojoExecutionException {
169  0 getLog().info("------------------------------------------------------------------------");
170  0 getLog().info("Generating database DTD");
171  0 getLog().info("------------------------------------------------------------------------");
172  0 showConfig();
173  0 super.executeMojo();
174  0 if (antCompatibilityMode) {
175  0 File srcFile = new File(getOutputDir() + FS + getArtifactId() + ".dtd");
176  0 File dstFile = new File(copyToFile);
177  0 getLog().info("Creating " + dstFile.getAbsolutePath() + " for Ant compatibility mode");
178  0 try {
179  0 FileUtils.copyFile(srcFile, dstFile);
180    } catch (IOException e) {
181  0 throw new MojoExecutionException("Error copying file", e);
182    }
183    }
184    }
185   
 
186  0 toggle public boolean isAntCompatibilityMode() {
187  0 return antCompatibilityMode;
188    }
189   
 
190  0 toggle public void setAntCompatibilityMode(final boolean antCompatibilityMode) {
191  0 this.antCompatibilityMode = antCompatibilityMode;
192    }
193   
 
194  0 toggle public String getCopyToFile() {
195  0 return copyToFile;
196    }
197   
 
198  0 toggle public void setCopyToFile(final String copyToFile) {
199  0 this.copyToFile = copyToFile;
200    }
201   
 
202  0 toggle public String getArtifactId() {
203  0 return artifactId;
204    }
205   
 
206  0 toggle public void setArtifactId(final String artifactId) {
207  0 this.artifactId = artifactId;
208    }
209    }