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