1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.torque.mojo;
17
18 import java.io.File;
19 import java.io.IOException;
20
21 import org.apache.commons.configuration.PropertiesConfiguration;
22 import org.apache.commons.io.FileUtils;
23 import org.apache.maven.plugin.MojoExecutionException;
24 import org.apache.torque.task.TorqueDataModelTask;
25 import org.kuali.core.db.torque.Utils;
26
27
28
29
30
31
32
33 public class DataDtdMojo extends DataModelTaskMojo {
34
35 public static final String PROJECT_CONTEXT_PROPERTY = "project";
36
37
38
39
40 boolean antCompatibilityMode;
41
42
43
44
45
46
47 String copyToFile;
48
49
50
51
52
53
54 String artifactId;
55
56
57
58
59
60
61
62 @SuppressWarnings("unused")
63 private String dummy1;
64
65
66
67
68
69
70
71 @SuppressWarnings("unused")
72 private String dummy2;
73
74
75
76
77
78
79
80 @SuppressWarnings("unused")
81 private String dummy3;
82
83
84
85
86
87
88 private String projectName;
89
90
91
92
93
94
95
96
97 private String schemaXMLFile;
98
99
100
101
102
103
104 @Override
105 protected PropertiesConfiguration getMojoContextProperties() {
106 PropertiesConfiguration configuration = new PropertiesConfiguration();
107 configuration.addProperty(PROJECT_CONTEXT_PROPERTY, getProjectName());
108 configuration.addProperty("version", getProject().getVersion());
109 return configuration;
110 }
111
112 protected void showConfig() {
113 getLog().info("Schema XML File: " + schemaXMLFile);
114 getLog().info("Ant Compatibility Mode: " + antCompatibilityMode);
115 getLog().info("Output Directory: " + getOutputDir());
116 }
117
118
119
120
121 @Override
122 protected void configureTask() throws MojoExecutionException {
123 TorqueDataModelTask task = new TorqueDataModelTask();
124 setAntTask(task);
125 super.configureTask();
126 boolean exists = new Utils().isFileOrResource(getSchemaXMLFile());
127 if (!exists) {
128 throw new MojoExecutionException("Unable to locate: " + getSchemaXMLFile());
129 }
130 task.setXmlFile(getSchemaXMLFile());
131
132 }
133
134
135
136
137
138
139 @Override
140 protected String getControlTemplate() {
141 return "data/Control.vm";
142 }
143
144
145
146
147
148
149 public String getProjectName() {
150 return projectName;
151 }
152
153
154
155
156
157
158
159 public void setProjectName(final String projectName) {
160 this.projectName = projectName;
161 }
162
163
164
165
166
167
168 public String getSchemaXMLFile() {
169 return schemaXMLFile;
170 }
171
172
173
174
175
176
177
178 public void setSchemaXMLFile(final String xmlFile) {
179 this.schemaXMLFile = xmlFile;
180 }
181
182 @Override
183 public void executeMojo() throws MojoExecutionException {
184 getLog().info("------------------------------------------------------------------------");
185 getLog().info("Generating database DTD");
186 getLog().info("------------------------------------------------------------------------");
187 showConfig();
188 super.executeMojo();
189 if (antCompatibilityMode) {
190 File srcFile = new File(getOutputDir() + FS + getArtifactId() + ".dtd");
191 File dstFile = new File(copyToFile);
192 getLog().info("Creating " + dstFile.getAbsolutePath() + " for Ant compatibility mode");
193 try {
194 FileUtils.copyFile(srcFile, dstFile);
195 } catch (IOException e) {
196 throw new MojoExecutionException("Error copying file", e);
197 }
198 }
199 }
200
201 public boolean isAntCompatibilityMode() {
202 return antCompatibilityMode;
203 }
204
205 public void setAntCompatibilityMode(final boolean antCompatibilityMode) {
206 this.antCompatibilityMode = antCompatibilityMode;
207 }
208
209 public String getCopyToFile() {
210 return copyToFile;
211 }
212
213 public void setCopyToFile(final String copyToFile) {
214 this.copyToFile = copyToFile;
215 }
216
217 public String getArtifactId() {
218 return artifactId;
219 }
220
221 public void setArtifactId(final String artifactId) {
222 this.artifactId = artifactId;
223 }
224 }