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.util.Properties;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.apache.maven.plugin.MojoExecutionException;
22 import org.apache.maven.plugin.descriptor.PluginDescriptor;
23 import org.apache.torque.util.JdbcConfigurer;
24 import org.kuali.core.db.torque.DumpTask;
25 import org.kuali.core.db.torque.PropertyHandlingException;
26 import org.kuali.core.db.torque.StringFilter;
27
28
29
30
31 public abstract class ExportMojo extends AntTaskMojo {
32
33
34
35
36
37
38 private Properties driverProperties;
39
40
41
42
43
44
45 private boolean antCompatibilityMode;
46
47
48
49
50
51
52
53
54 private String artifactId;
55
56
57
58
59
60
61
62
63
64 private boolean includeVersionInComment;
65
66
67
68
69
70
71
72
73 private String comment;
74
75
76
77
78
79
80 private String includes;
81
82
83
84
85
86
87 private String excludes;
88
89
90
91
92
93
94
95
96 private String targetDatabase;
97
98
99
100
101
102
103
104
105
106
107
108 private String schema;
109
110
111
112
113
114
115
116
117
118 private String driver;
119
120
121
122
123
124
125
126 private String url;
127
128
129
130
131
132
133
134
135
136
137 private String username;
138
139
140
141
142
143
144
145
146
147
148 private String password;
149
150
151
152
153 public String getDriver() {
154 return driver;
155 }
156
157
158
159
160
161
162
163 public void setDriver(final String driver) {
164 this.driver = driver;
165 }
166
167
168
169
170
171
172 public String getPassword() {
173 return password;
174 }
175
176
177
178
179
180
181
182 public void setPassword(final String password) {
183 this.password = password;
184 }
185
186
187
188
189
190
191 public String getUrl() {
192 return url;
193 }
194
195
196
197
198
199
200
201 public void setUrl(final String url) {
202 this.url = url;
203 }
204
205 public String getUsername() {
206 return username;
207 }
208
209 public void setUsername(final String username) {
210 this.username = username;
211 }
212
213 public String getSchema() {
214 return schema;
215 }
216
217 public void setSchema(final String schema) {
218 this.schema = schema;
219 }
220
221 public String getTargetDatabase() {
222 return targetDatabase;
223 }
224
225 public void setTargetDatabase(final String targetDatabase) {
226 this.targetDatabase = targetDatabase;
227 }
228
229 public String getIncludes() {
230 return includes;
231 }
232
233 public void setIncludes(final String includePatterns) {
234 this.includes = includePatterns;
235 }
236
237 public String getExcludes() {
238 return excludes;
239 }
240
241 public void setExcludes(final String excludePatterns) {
242 this.excludes = excludePatterns;
243 }
244
245 public String getComment() {
246 return comment;
247 }
248
249 public void setComment(final String comment) {
250 this.comment = comment;
251 }
252
253 protected String getUpdatedComment() {
254 PluginDescriptor descriptor = (PluginDescriptor) this.getPluginContext().get("pluginDescriptor");
255 if (descriptor == null) {
256
257 return " Auto-generated by the maven-impex-plugin " + getComment();
258 }
259 String name = descriptor.getName();
260 String version = descriptor.getVersion();
261 String comment = " Auto-generated by the " + name;
262 if (isIncludeVersionInComment()) {
263 comment += " v" + version + " ";
264 }
265 if (!StringUtils.isEmpty(getComment())) {
266 comment += getComment();
267 }
268 return comment;
269 }
270
271 @Override
272 protected void configureTask() throws MojoExecutionException {
273 setComment(getUpdatedComment());
274 try {
275 JdbcConfigurer configurer = new JdbcConfigurer();
276 configurer.updateConfiguration(this);
277 configurer.validateConfiguration(this);
278 } catch (PropertyHandlingException e) {
279 throw new MojoExecutionException("Error handling properties", e);
280 }
281 super.configureTask();
282 DumpTask task = (DumpTask) super.getAntTask();
283 task.setIncludePatterns(StringFilter.getListFromCSV(getIncludes()));
284 task.setExcludePatterns(StringFilter.getListFromCSV(getExcludes()));
285 task.setDriverProperties(driverProperties);
286 }
287
288 public String getArtifactId() {
289 return artifactId;
290 }
291
292 public void setArtifactId(final String artifactId) {
293 this.artifactId = artifactId;
294 }
295
296 public boolean isAntCompatibilityMode() {
297 return antCompatibilityMode;
298 }
299
300 public void setAntCompatibilityMode(final boolean antCompatibilityMode) {
301 this.antCompatibilityMode = antCompatibilityMode;
302 }
303
304
305
306
307 public boolean isIncludeVersionInComment() {
308 return includeVersionInComment;
309 }
310
311
312
313
314
315 public void setIncludeVersionInComment(final boolean includeVersionInComment) {
316 this.includeVersionInComment = includeVersionInComment;
317 }
318
319 public Properties getDriverProperties() {
320 return driverProperties;
321 }
322
323 public void setDriverProperties(Properties driverProperties) {
324 this.driverProperties = driverProperties;
325 }
326 }