1 28 29 30 package org.objectweb.ecm.taskdefs; 31 32 119 abstract public class IDLtoJavaTask 120 extends org.apache.tools.ant.Task 121 { 122 private java.io.File _idlfile; 124 private java.io.File _generateto; 125 private java.io.File _genfile; 126 private String _genfilename; 127 private java.util.ArrayList _idldeps; 128 private java.util.ArrayList _idldep; 129 private java.util.ArrayList _includedirs; 130 private java.util.ArrayList _includedir; 131 private String _prefix; 132 133 private String _archive; 134 private java.io.File _buildto; 135 private java.io.File _compileto; 136 private BuildJarTask _buildjar; 137 138 protected 140 IDLtoJavaTask() 141 { 142 _idlfile = null; 144 _generateto = null; 145 _genfile = null; 146 _genfilename = null; 147 _idldeps = new java.util.ArrayList (); 148 _idldep = new java.util.ArrayList (); 149 _includedirs = new java.util.ArrayList (); 150 _includedir = new java.util.ArrayList (); 151 _prefix = null; 152 153 _archive = null; 154 _buildto = null; 155 _compileto = null; 156 _buildjar = null; 157 } 158 159 163 private BuildJarTask 164 buildjar() 165 { 166 if (_buildjar==null) { 167 org.apache.tools.ant.Task task = getProject().createTask("buildjar"); 168 _buildjar = (BuildJarTask)task; 169 } 170 171 return _buildjar; 172 } 173 174 private void 176 validateAttributes() 177 throws org.apache.tools.ant.BuildException 178 { 179 String msg = ""; 180 if (_idlfile==null) { 181 msg = "idlfile attribute is missing"; 182 throw new org.apache.tools.ant.BuildException(msg); 183 } 184 185 if ((!_idlfile.exists()) || (!_idlfile.isFile())) { 186 msg = "Source OMG IDL file does not exists or is not a file"; 187 throw new org.apache.tools.ant.BuildException(msg); 188 } 189 190 if ((!_generateto.exists()) || (!_generateto.isDirectory())) { 191 msg = "Generation directory does not exist or is not a directory"; 192 throw new org.apache.tools.ant.BuildException(msg); 193 } 194 195 _genfile = new java.io.File (_generateto, _genfilename.replace('/', java.io.File.separatorChar)); 197 if (_genfile==null) { 198 msg = "[validateAttributes] genfile (null): "+_generateto.getPath()+"/"+_genfilename.replace('/', java.io.File.separatorChar); 199 log(msg); 200 } 201 202 if (_archive!=null) { 204 if (_compileto==null) { 205 msg = "compileto attribute must be set when archivename attribute is set"; 206 throw new org.apache.tools.ant.BuildException(msg); 207 } 208 209 if ((!_compileto.exists()) || (!_compileto.isDirectory())) { 210 msg = "class directory does not exist or is not a directory"; 211 throw new org.apache.tools.ant.BuildException(msg); 212 } 213 214 if (_buildto==null) { 215 msg = "buildto attribute must be set when archivename attribute is set"; 216 throw new org.apache.tools.ant.BuildException(msg); 217 } 218 219 if ((!_buildto.exists()) || (!_buildto.isDirectory())) { 220 msg = "archive directory does not exist or is not a directory"; 221 throw new org.apache.tools.ant.BuildException(msg); 222 } 223 } 224 } 225 226 private boolean 227 idlfileUpToDate() 228 { 229 boolean genfile_passed=false; 230 boolean idldeps_passed=false; 231 boolean idldep_passed=false; 232 233 if (_genfile!=null) { 235 if ((!_genfile.exists()) || (_genfile.lastModified()<_idlfile.lastModified())) { 236 return false; 237 } 238 else { 239 genfile_passed=true; 240 } 241 } 242 243 org.apache.tools.ant.types.FileSet[] sets = null; 245 sets = (org.apache.tools.ant.types.FileSet[])_idldeps.toArray(new org.apache.tools.ant.types.FileSet[0]); 246 247 if (sets.length>0) { 248 for (int i=0;i<sets.length;i++) { 249 org.apache.tools.ant.DirectoryScanner scanner = sets[i].getDirectoryScanner(super.project); 250 String [] filenames = scanner.getIncludedFiles(); 251 java.io.File file = null; 252 253 log("[idlfileUpToDate] base dir: "+scanner.getBasedir().getPath()); 254 for (int j=0;j<filenames.length;j++) { 255 log("[idlfileUpToDate] filename: "+filenames[j]); 256 file = new java.io.File (scanner.getBasedir(), filenames[j]); 257 if (_idlfile.lastModified()>file.lastModified()) { 258 return false; 259 } 260 } 261 } 262 263 idldeps_passed=true; 264 } 265 266 NestedElementWithFile[] idlfiles = (NestedElementWithFile[])_idldep.toArray(new NestedElementWithFile[0]); 268 if (idlfiles.length!=0) { 269 for (int i=0;i<idlfiles.length;i++) { 270 if (_idlfile.lastModified()>idlfiles[i].getFile().lastModified()) { 271 return false; 272 } 273 } 274 275 idldep_passed = true; 276 } 277 278 if (genfile_passed || idldeps_passed || idldep_passed) { 281 return true; 282 } 283 284 return false; 285 } 286 287 private boolean 288 jarUpToDate(java.io.File tmpdir) 289 { 290 if (_archive==null) { 292 return true; 293 } 294 295 if (tmpdir.listFiles().length==0) { 297 return true; 298 } 299 300 return false; 301 } 302 303 307 final public void 308 setIdlfile(java.io.File file) 309 { 310 _idlfile = file; 311 } 312 313 final public void 314 setGenerateto(java.io.File dir) 315 { 316 _generateto = dir; 317 } 318 319 final public void 320 setGenfile(String filename) 321 { 322 _genfilename = filename; 323 } 324 325 final public void 326 setIdldeps(String idldeps) 327 { 328 } 331 332 final public void 333 addIdldeps(org.apache.tools.ant.types.FileSet set) 334 { 335 _idldeps.add(set); 336 } 337 338 final public NestedElementWithFile 339 createIdldep() 340 { 341 NestedElementWithFile idldep = new NestedElementWithFile(); 342 _idldep.add(idldep); 343 return idldep; 344 } 345 346 final public void 347 addIncludedirs(org.apache.tools.ant.types.DirSet set) 348 { 349 _includedirs.add(set); 350 } 351 352 final public NestedElementWithFile 353 createIncludedir() 354 { 355 NestedElementWithFile dir = new NestedElementWithFile(); 356 _includedir.add(dir); 357 return dir; 358 } 359 360 final public void 361 setPrefix(String p) 362 { 363 _prefix = p; 364 } 365 366 final public void 367 setCompileto(java.io.File dir) 368 { 369 _compileto = dir; 370 } 371 372 final public void 373 setArchivename(String name) 374 { 375 _archive = name; 376 } 377 378 final public void 379 setBuildto(java.io.File dir) 380 { 381 _buildto = dir; 382 } 383 384 final public void 385 setClasspathRef(org.apache.tools.ant.types.Reference cp) 386 { 387 buildjar().setClasspathRef(cp); 388 } 389 390 final public void 391 setClasspathref(org.apache.tools.ant.types.Reference cp) 392 { 393 buildjar().setClasspathref(cp); 394 } 395 396 final public void 397 setBootclasspathRef(org.apache.tools.ant.types.Reference cp) 398 { 399 buildjar().setBootclasspathRef(cp); 400 } 401 402 final public void 403 setBootclasspathref(org.apache.tools.ant.types.Reference cp) 404 { 405 buildjar().setBootclasspathref(cp); 406 } 407 408 final public org.apache.tools.ant.types.Path 409 createClasspath() 410 { 411 return buildjar().createClasspath(); 412 } 413 414 final public org.apache.tools.ant.types.Path 415 createBootclasspath() 416 { 417 return buildjar().createBootclasspath(); 418 } 419 420 424 final public void 425 execute() 426 throws org.apache.tools.ant.BuildException 427 { 428 validateAttributes(); 430 431 java.io.File tmpdir = FileHelper.createTempDir(); 433 434 if (!idlfileUpToDate()) { 436 log("[execute] OMG IDL file is not uptodate: "+_idlfile.getName()); 437 438 java.util.ArrayList vdirs = new java.util.ArrayList (); 439 440 org.apache.tools.ant.types.DirSet[] sets = null; 442 sets = (org.apache.tools.ant.types.DirSet[])_includedirs.toArray(new org.apache.tools.ant.types.DirSet[0]); 443 444 for (int i=0;i<sets.length;i++) { 445 org.apache.tools.ant.DirectoryScanner scanner = sets[i].getDirectoryScanner(super.project); 446 String [] dirnames = scanner.getIncludedDirectories(); 447 448 for (int j=0;j<dirnames.length;j++) { 449 java.io.File dir = new java.io.File (scanner.getBasedir(), dirnames[j]); 450 if (!dir.exists()) { 451 String msg = "Included directory does not exists: "+dir.getPath(); 452 log(msg, org.apache.tools.ant.Project.MSG_WARN); 453 } 454 else if (!dir.isDirectory()) { 455 String msg = "Included directory is not a directory: "+dir.getPath(); 456 log(msg, org.apache.tools.ant.Project.MSG_WARN); 457 } 458 else { 459 vdirs.add(dir); 460 } 461 } 462 } 463 464 NestedElementWithFile[] dirs = (NestedElementWithFile[])_includedir.toArray(new NestedElementWithFile[0]); 467 for (int i=0;i<dirs.length;i++) { 468 java.io.File dir = dirs[i].getFile(); 469 if (!dir.exists()) { 470 String msg = "Included directory does not exists: "+dir.getPath(); 471 log(msg, org.apache.tools.ant.Project.MSG_WARN); 472 } 473 else if (!dir.isDirectory()) { 474 String msg = "Included directory is not a directory: "+dir.getPath(); 475 log(msg, org.apache.tools.ant.Project.MSG_WARN); 476 } 477 else { 478 vdirs.add(dir); 479 } 480 } 481 482 java.io.File [] idirs = (java.io.File [])vdirs.toArray(new java.io.File [0]); 483 compileIDL(_idlfile, tmpdir, idirs, _prefix); 484 } 485 486 if (!jarUpToDate(tmpdir)) { 488 log("[execute] jar is not uptodate"); 490 buildjar().setSrcdir(tmpdir); 491 buildjar().setCompileto(_compileto); 492 buildjar().setArchivename(_archive); 493 buildjar().setBuildto(_buildto); 494 buildjar().execute(); 495 } 496 497 FileHelper.moveFiles(tmpdir.listFiles(), _generateto); 499 500 FileHelper.deleteDir(tmpdir); 502 } 503 504 508 abstract protected void 509 compileIDL(java.io.File idlfile, java.io.File compileto, 510 java.io.File [] includedirs, String prefix); 511 } 512 | Popular Tags |