| 1 |
|
package org.apache.torque.task; |
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
import java.io.File; |
| 23 |
|
import java.util.ArrayList; |
| 24 |
|
import java.util.Date; |
| 25 |
|
import java.util.Hashtable; |
| 26 |
|
import java.util.Iterator; |
| 27 |
|
import java.util.List; |
| 28 |
|
import java.util.Map; |
| 29 |
|
|
| 30 |
|
import org.apache.commons.lang.StringUtils; |
| 31 |
|
import org.apache.tools.ant.BuildException; |
| 32 |
|
import org.apache.tools.ant.DirectoryScanner; |
| 33 |
|
import org.apache.tools.ant.types.FileSet; |
| 34 |
|
import org.apache.torque.engine.EngineException; |
| 35 |
|
import org.apache.torque.engine.database.model.Database; |
| 36 |
|
import org.apache.velocity.VelocityContext; |
| 37 |
|
import org.apache.velocity.context.Context; |
| 38 |
|
import org.apache.texen.ant.TexenTask; |
| 39 |
|
import org.kuali.core.db.torque.DatabaseParser; |
| 40 |
|
import org.kuali.core.db.torque.KualiXmlToAppData; |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
@author |
| 48 |
|
@author |
| 49 |
|
|
|
|
|
| 0% |
Uncovered Elements: 120 (120) |
Complexity: 33 |
Complexity Density: 0.42 |
|
| 50 |
|
public class TorqueDataModelTask extends TexenTask { |
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
protected String xmlFile; |
| 55 |
|
|
| 56 |
|
|
| 57 |
|
protected List<FileSet> filesets = new ArrayList<FileSet>(); |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
protected List<Database> dataModels = new ArrayList<Database>(); |
| 61 |
|
|
| 62 |
|
|
| 63 |
|
protected Context context; |
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
protected Hashtable<String, String> dataModelDbMap; |
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
protected Hashtable<String, String> databaseNames; |
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
protected String sqldbmap; |
| 85 |
|
|
| 86 |
|
|
| 87 |
|
private String targetDatabase; |
| 88 |
|
|
| 89 |
|
|
| 90 |
|
private String targetPackage; |
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
|
@param |
| 96 |
|
|
| 97 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 98 |
0
|
public void setSqlDbMap(String sqldbmap) {... |
| 99 |
|
|
| 100 |
0
|
this.sqldbmap = getProject().resolveFile(sqldbmap).toString(); |
| 101 |
|
} |
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
|
|
| 106 |
|
@return |
| 107 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 108 |
0
|
public String getSqlDbMap() {... |
| 109 |
0
|
return sqldbmap; |
| 110 |
|
} |
| 111 |
|
|
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| 115 |
|
@return |
| 116 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 117 |
0
|
public List<Database> getDataModels() {... |
| 118 |
0
|
return dataModels; |
| 119 |
|
} |
| 120 |
|
|
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
| 124 |
|
@return |
| 125 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 126 |
0
|
public Hashtable<String, String> getDataModelDbMap() {... |
| 127 |
0
|
return dataModelDbMap; |
| 128 |
|
} |
| 129 |
|
|
| 130 |
|
|
| 131 |
|
|
| 132 |
|
|
| 133 |
|
@return |
| 134 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 135 |
0
|
public String getXmlFile() {... |
| 136 |
0
|
return xmlFile; |
| 137 |
|
} |
| 138 |
|
|
| 139 |
|
|
| 140 |
|
|
| 141 |
|
|
| 142 |
|
@param |
| 143 |
|
|
| 144 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 145 |
0
|
public void setXmlFile(String xmlFile) {... |
| 146 |
0
|
this.xmlFile = xmlFile; |
| 147 |
|
} |
| 148 |
|
|
| 149 |
|
|
| 150 |
|
|
| 151 |
|
|
| 152 |
|
@param |
| 153 |
|
|
| 154 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 155 |
0
|
public void addFileset(FileSet set) {... |
| 156 |
0
|
filesets.add(set); |
| 157 |
|
} |
| 158 |
|
|
| 159 |
|
|
| 160 |
|
|
| 161 |
|
|
| 162 |
|
@return |
| 163 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 164 |
0
|
public String getTargetDatabase() {... |
| 165 |
0
|
return targetDatabase; |
| 166 |
|
} |
| 167 |
|
|
| 168 |
|
|
| 169 |
|
|
| 170 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 171 |
0
|
public void setTargetDatabase(String targetDatabase) {... |
| 172 |
0
|
this.targetDatabase = targetDatabase; |
| 173 |
|
} |
| 174 |
|
|
| 175 |
|
|
| 176 |
|
|
| 177 |
|
|
| 178 |
|
@return |
| 179 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 180 |
0
|
public String getTargetPackage() {... |
| 181 |
0
|
return targetPackage; |
| 182 |
|
} |
| 183 |
|
|
| 184 |
|
|
| 185 |
|
|
| 186 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 187 |
0
|
public void setTargetPackage(String targetPackage) {... |
| 188 |
0
|
this.targetPackage = targetPackage; |
| 189 |
|
} |
| 190 |
|
|
| 191 |
|
|
| 192 |
|
|
| 193 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 194 |
0
|
protected DatabaseParser getDatabaseParser() {... |
| 195 |
0
|
return new KualiXmlToAppData(getTargetDatabase(), getTargetPackage()); |
| 196 |
|
} |
| 197 |
|
|
| 198 |
|
|
| 199 |
|
|
| 200 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 201 |
0
|
protected Database getDataModel(File file) throws EngineException {... |
| 202 |
|
|
| 203 |
0
|
DatabaseParser databaseParser = getDatabaseParser(); |
| 204 |
|
|
| 205 |
|
|
| 206 |
0
|
Database database = databaseParser.parseResource(file.toString()); |
| 207 |
|
|
| 208 |
|
|
| 209 |
0
|
database.setFileName(grokName(file.toString())); |
| 210 |
|
|
| 211 |
|
|
| 212 |
0
|
return database; |
| 213 |
|
} |
| 214 |
|
|
| 215 |
|
|
| 216 |
|
|
| 217 |
|
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
| 218 |
0
|
protected List<File> getDataModelFiles() {... |
| 219 |
|
|
| 220 |
0
|
List<File> dataModelFiles = new ArrayList<File>(); |
| 221 |
|
|
| 222 |
|
|
| 223 |
0
|
for (int i = 0; i < getFilesets().size(); i++) { |
| 224 |
|
|
| 225 |
0
|
FileSet fs = getFilesets().get(i); |
| 226 |
|
|
| 227 |
|
|
| 228 |
0
|
DirectoryScanner ds = fs.getDirectoryScanner(getProject()); |
| 229 |
|
|
| 230 |
|
|
| 231 |
0
|
File srcDir = fs.getDir(getProject()); |
| 232 |
|
|
| 233 |
|
|
| 234 |
0
|
String[] dataModelFilesArray = ds.getIncludedFiles(); |
| 235 |
|
|
| 236 |
|
|
| 237 |
0
|
for (int j = 0; j < dataModelFilesArray.length; j++) { |
| 238 |
0
|
File file = new File(srcDir, dataModelFilesArray[j]); |
| 239 |
0
|
dataModelFiles.add(file); |
| 240 |
|
} |
| 241 |
|
} |
| 242 |
|
|
| 243 |
|
|
| 244 |
0
|
return dataModelFiles; |
| 245 |
|
} |
| 246 |
|
|
| 247 |
|
|
| 248 |
|
|
| 249 |
|
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
| 250 |
0
|
protected List<Database> getPopulatedDataModels() throws EngineException {... |
| 251 |
|
|
| 252 |
0
|
List<Database> databases = new ArrayList<Database>(); |
| 253 |
|
|
| 254 |
|
|
| 255 |
0
|
if (getXmlFile() != null) { |
| 256 |
|
|
| 257 |
0
|
Database database = getDataModel(new File(getXmlFile())); |
| 258 |
|
|
| 259 |
0
|
databases.add(database); |
| 260 |
|
|
| 261 |
0
|
return databases; |
| 262 |
|
} |
| 263 |
|
|
| 264 |
|
|
| 265 |
0
|
List<File> dataModelFiles = getDataModelFiles(); |
| 266 |
|
|
| 267 |
0
|
for (File dataModelFile : dataModelFiles) { |
| 268 |
|
|
| 269 |
0
|
Database database = getDataModel(dataModelFile); |
| 270 |
|
|
| 271 |
0
|
databases.add(database); |
| 272 |
|
} |
| 273 |
|
|
| 274 |
0
|
return databases; |
| 275 |
|
} |
| 276 |
|
|
| 277 |
|
|
| 278 |
|
|
| 279 |
|
|
| 280 |
|
@return |
| 281 |
|
@throws |
| 282 |
|
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 5 |
Complexity Density: 0.28 |
|
| 283 |
0
|
public Context initControlContext() throws Exception {... |
| 284 |
0
|
if (xmlFile == null && filesets.isEmpty()) { |
| 285 |
0
|
throw new BuildException("You must specify an XML schema or fileset of XML schemas!"); |
| 286 |
|
} |
| 287 |
|
|
| 288 |
0
|
try { |
| 289 |
0
|
dataModels = getPopulatedDataModels(); |
| 290 |
|
} catch (EngineException ee) { |
| 291 |
0
|
throw new BuildException(ee); |
| 292 |
|
} |
| 293 |
|
|
| 294 |
0
|
Iterator<Database> i = dataModels.iterator(); |
| 295 |
0
|
databaseNames = new Hashtable<String, String>(); |
| 296 |
0
|
dataModelDbMap = new Hashtable<String, String>(); |
| 297 |
|
|
| 298 |
|
|
| 299 |
|
|
| 300 |
0
|
while (i.hasNext()) { |
| 301 |
0
|
Database database = i.next(); |
| 302 |
0
|
databaseNames.put(database.getName(), database.getName()); |
| 303 |
0
|
dataModelDbMap.put(database.getFileName(), database.getName()); |
| 304 |
|
} |
| 305 |
|
|
| 306 |
0
|
context = new VelocityContext(); |
| 307 |
|
|
| 308 |
|
|
| 309 |
|
|
| 310 |
0
|
context.put("dataModels", dataModels); |
| 311 |
0
|
context.put("databaseNames", databaseNames); |
| 312 |
0
|
context.put("targetDatabase", targetDatabase); |
| 313 |
0
|
context.put("targetPackage", targetPackage); |
| 314 |
|
|
| 315 |
0
|
return context; |
| 316 |
|
} |
| 317 |
|
|
| 318 |
|
|
| 319 |
|
|
| 320 |
|
|
| 321 |
|
@see |
| 322 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 323 |
0
|
protected void populateInitialContext(Context context) throws Exception {... |
| 324 |
0
|
super.populateInitialContext(context); |
| 325 |
0
|
context.put("now", new Date()); |
| 326 |
|
} |
| 327 |
|
|
| 328 |
|
|
| 329 |
|
|
| 330 |
|
|
| 331 |
|
@param |
| 332 |
|
|
| 333 |
|
@return |
| 334 |
|
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
| 335 |
0
|
private String grokName(String xmlFile) {... |
| 336 |
|
|
| 337 |
|
|
| 338 |
|
|
| 339 |
|
|
| 340 |
0
|
String name = "data-model"; |
| 341 |
0
|
int i = xmlFile.lastIndexOf(System.getProperty("file.separator")); |
| 342 |
0
|
if (i != -1) { |
| 343 |
|
|
| 344 |
0
|
i++; |
| 345 |
|
|
| 346 |
0
|
int j = xmlFile.lastIndexOf('.'); |
| 347 |
0
|
if (i < j) { |
| 348 |
0
|
name = xmlFile.substring(i, j); |
| 349 |
|
} else { |
| 350 |
|
|
| 351 |
0
|
name = xmlFile.substring(i); |
| 352 |
|
} |
| 353 |
|
} |
| 354 |
0
|
return name; |
| 355 |
|
} |
| 356 |
|
|
| 357 |
|
|
| 358 |
|
|
| 359 |
|
|
| 360 |
|
|
| 361 |
|
|
| 362 |
|
|
| 363 |
|
|
| 364 |
|
|
| 365 |
|
@param |
| 366 |
|
|
| 367 |
|
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
| 368 |
0
|
public void setContextProperties(String file) {... |
| 369 |
0
|
super.setContextProperties(file); |
| 370 |
|
|
| 371 |
|
|
| 372 |
0
|
Hashtable<?, ?> env = super.getProject().getProperties(); |
| 373 |
0
|
for (Iterator<?> i = env.entrySet().iterator(); i.hasNext();) { |
| 374 |
0
|
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) i.next(); |
| 375 |
0
|
String key = (String) entry.getKey(); |
| 376 |
0
|
if (key.startsWith("torque.")) { |
| 377 |
0
|
String newKey = key.substring("torque.".length()); |
| 378 |
0
|
int j = newKey.indexOf("."); |
| 379 |
0
|
while (j != -1) { |
| 380 |
0
|
newKey = newKey.substring(0, j) + StringUtils.capitalize(newKey.substring(j + 1)); |
| 381 |
0
|
j = newKey.indexOf("."); |
| 382 |
|
} |
| 383 |
|
|
| 384 |
0
|
contextProperties.setProperty(newKey, entry.getValue()); |
| 385 |
|
} |
| 386 |
|
} |
| 387 |
|
} |
| 388 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 389 |
0
|
public List<FileSet> getFilesets() {... |
| 390 |
0
|
return filesets; |
| 391 |
|
} |
| 392 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 393 |
0
|
public void setFilesets(List<FileSet> filesets) {... |
| 394 |
0
|
this.filesets = filesets; |
| 395 |
|
} |
| 396 |
|
} |