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