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 @SuppressWarnings("unused")
62 private String dummy1;
63
64
65
66
67
68
69 @SuppressWarnings("unused")
70 private String dummy2;
71
72
73
74
75
76
77 @SuppressWarnings("unused")
78 private String dummy3;
79
80
81
82
83
84
85 private String projectName;
86
87
88
89
90
91
92
93 private String schemaXMLFile;
94
95
96
97
98
99
100 @Override
101 protected PropertiesConfiguration getMojoContextProperties() {
102 PropertiesConfiguration configuration = new PropertiesConfiguration();
103 configuration.addProperty(PROJECT_CONTEXT_PROPERTY, getProjectName());
104 configuration.addProperty("version", getProject().getVersion());
105 return configuration;
106 }
107
108 protected void showConfig() {
109 getLog().info("Schema XML File: " + schemaXMLFile);
110 getLog().info("Ant Compatibility Mode: " + antCompatibilityMode);
111 getLog().info("Output Directory: " + getOutputDir());
112 }
113
114
115
116
117 @Override
118 protected void configureTask() throws MojoExecutionException {
119 TorqueDataModelTask task = new TorqueDataModelTask();
120 setAntTask(task);
121 super.configureTask();
122 boolean exists = new Utils().isFileOrResource(getSchemaXMLFile());
123 if (!exists) {
124 throw new MojoExecutionException("Unable to locate: " + getSchemaXMLFile());
125 }
126 task.setXmlFile(getSchemaXMLFile());
127
128 }
129
130
131
132
133
134
135 @Override
136 protected String getControlTemplate() {
137 return "data/Control.vm";
138 }
139
140
141
142
143
144
145 public String getProjectName() {
146 return projectName;
147 }
148
149
150
151
152
153
154
155 public void setProjectName(final String projectName) {
156 this.projectName = projectName;
157 }
158
159
160
161
162
163
164 public String getSchemaXMLFile() {
165 return schemaXMLFile;
166 }
167
168
169
170
171
172
173
174 public void setSchemaXMLFile(final String xmlFile) {
175 this.schemaXMLFile = xmlFile;
176 }
177
178 @Override
179 public void executeMojo() throws MojoExecutionException {
180 getLog().info("------------------------------------------------------------------------");
181 getLog().info("Generating database DTD");
182 getLog().info("------------------------------------------------------------------------");
183 showConfig();
184 super.executeMojo();
185 if (antCompatibilityMode) {
186 File srcFile = new File(getOutputDir() + FS + getArtifactId() + ".dtd");
187 File dstFile = new File(copyToFile);
188 getLog().info("Creating " + dstFile.getAbsolutePath() + " for Ant compatibility mode");
189 try {
190 FileUtils.copyFile(srcFile, dstFile);
191 } catch (IOException e) {
192 throw new MojoExecutionException("Error copying file", e);
193 }
194 }
195 }
196
197 public boolean isAntCompatibilityMode() {
198 return antCompatibilityMode;
199 }
200
201 public void setAntCompatibilityMode(final boolean antCompatibilityMode) {
202 this.antCompatibilityMode = antCompatibilityMode;
203 }
204
205 public String getCopyToFile() {
206 return copyToFile;
207 }
208
209 public void setCopyToFile(final String copyToFile) {
210 this.copyToFile = copyToFile;
211 }
212
213 public String getArtifactId() {
214 return artifactId;
215 }
216
217 public void setArtifactId(final String artifactId) {
218 this.artifactId = artifactId;
219 }
220 }