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