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.util.List;
20
21 import org.apache.commons.configuration.PropertiesConfiguration;
22 import org.apache.maven.plugin.MojoExecutionException;
23 import org.apache.torque.util.ChangeDetector;
24 import org.apache.torque.util.SimpleScanner;
25 import org.kuali.core.db.torque.KualiTorqueDataSQLTask;
26
27
28
29
30
31
32
33
34 public class DataSqlMojo extends DataModelTaskMojo {
35
36
37
38
39
40
41 @SuppressWarnings("unused")
42 private String dummy;
43
44
45
46
47
48
49 @SuppressWarnings("unused")
50 private String dummy2;
51
52
53
54
55
56
57 @SuppressWarnings("unused")
58 private String dummy3;
59
60
61
62
63
64
65
66 private boolean runOnlyOnChange;
67
68
69
70
71
72
73
74 private File schemaXMLFile;
75
76
77
78
79
80
81
82 private File dataXMLDir;
83
84
85
86
87
88
89
90 private String dataXMLIncludes;
91
92
93
94
95
96
97 private String dataXMLExcludes;
98
99
100
101
102
103
104
105 private File dataDTD;
106
107 @Override
108 public void executeMojo() throws MojoExecutionException {
109
110 updateConfiguration();
111 validateConfiguration();
112 generateContextProperties();
113 configureTask();
114 addTargetDatabaseToOutputDir();
115 addTargetDatabaseToReportFile();
116 ChangeDetector schema = new ChangeDetector(getCanonicalReportFile(), getSchemaFiles());
117 ChangeDetector data = new ChangeDetector(getCanonicalReportFile(), getDataFiles());
118 if (!schema.isChanged() && !data.isChanged() && isRunOnlyOnChange()) {
119 getLog().info("------------------------------------------------------------------------");
120 getLog().info("Data and schema are unchanged. Skipping generation.");
121 getLog().info("------------------------------------------------------------------------");
122 return;
123 }
124 getLog().info("------------------------------------------------------------------------");
125 getLog().info("Generating SQL for " + getTargetDatabase() + " from data XML files");
126 getLog().info("------------------------------------------------------------------------");
127 getAntTask().execute();
128 }
129
130 protected List<File> getDataFiles() {
131 return new SimpleScanner(getDataXMLDir(), getDataXMLIncludes(), getDataXMLExcludes()).getFiles();
132 }
133
134
135
136
137
138
139 @Override
140 protected PropertiesConfiguration getMojoContextProperties() {
141 PropertiesConfiguration configuration = new PropertiesConfiguration();
142 configuration.addProperty(TARGET_DATABASE_CONTEXT_PROPERTY, super.getTargetDatabase());
143 return configuration;
144 }
145
146
147
148
149 @Override
150 protected void configureTask() throws MojoExecutionException {
151 KualiTorqueDataSQLTask task = new KualiTorqueDataSQLTask();
152 setAntTask(task);
153 super.configureTask();
154 task.setDataDTD(getDataDTD());
155 task.addFileset(getAntFileSet(getDataXMLDir(), getDataXMLIncludes(), getDataXMLExcludes()));
156 task.setXmlFile(getSchemaXMLFile().getAbsolutePath());
157 task.setTargetDatabase(getTargetDatabase());
158 }
159
160
161
162
163
164
165 @Override
166 protected String getControlTemplate() {
167 return "sql/load/Control.vm";
168 }
169
170 public String getDataXMLIncludes() {
171 return dataXMLIncludes;
172 }
173
174 public void setDataXMLIncludes(String dataXMLIncludes) {
175 this.dataXMLIncludes = dataXMLIncludes;
176 }
177
178 public String getDataXMLExcludes() {
179 return dataXMLExcludes;
180 }
181
182 public void setDataXMLExcludes(String dataXMLExcludes) {
183 this.dataXMLExcludes = dataXMLExcludes;
184 }
185
186 public File getDataXMLDir() {
187 return dataXMLDir;
188 }
189
190 public void setDataXMLDir(File dataXMLDir) {
191 this.dataXMLDir = dataXMLDir;
192 }
193
194 public File getSchemaXMLFile() {
195 return schemaXMLFile;
196 }
197
198 public void setSchemaXMLFile(File schemaXMLFile) {
199 this.schemaXMLFile = schemaXMLFile;
200 }
201
202 public boolean isRunOnlyOnChange() {
203 return runOnlyOnChange;
204 }
205
206 public void setRunOnlyOnChange(boolean runOnlyOnDataChange) {
207 this.runOnlyOnChange = runOnlyOnDataChange;
208 }
209
210 public File getDataDTD() {
211 return dataDTD;
212 }
213
214 public void setDataDTD(File dataDTD) {
215 this.dataDTD = dataDTD;
216 }
217
218 }