1 18 19 20 package org.apache.tools.ant.taskdefs.optional.ejb; 21 22 23 import java.io.BufferedReader ; 24 import java.io.File ; 25 import java.io.IOException ; 26 import java.io.InputStream ; 27 import java.io.InputStreamReader ; 28 import java.io.OutputStream ; 29 import java.util.Hashtable ; 30 import java.util.Iterator ; 31 import java.util.Vector ; 32 import org.apache.tools.ant.BuildException; 33 import org.apache.tools.ant.Project; 34 import org.apache.tools.ant.taskdefs.ExecTask; 35 import org.apache.tools.ant.taskdefs.Execute; 36 import org.apache.tools.ant.taskdefs.ExecuteStreamHandler; 37 import org.apache.tools.ant.taskdefs.Java; 38 import org.apache.tools.ant.types.Commandline; 39 import org.apache.tools.ant.types.Path; 40 41 42 77 public class BorlandDeploymentTool extends GenericDeploymentTool 78 implements ExecuteStreamHandler { 79 80 public static final String PUBLICID_BORLAND_EJB 81 = "-//Inprise Corporation//DTD Enterprise JavaBeans 1.1//EN"; 82 83 protected static final String DEFAULT_BAS45_EJB11_DTD_LOCATION 84 = "/com/inprise/j2ee/xml/dtds/ejb-jar.dtd"; 85 86 protected static final String DEFAULT_BAS_DTD_LOCATION 87 = "/com/inprise/j2ee/xml/dtds/ejb-inprise.dtd"; 88 89 protected static final String BAS_DD = "ejb-inprise.xml"; 90 protected static final String BES_DD = "ejb-borland.xml"; 91 92 93 94 protected static final String JAVA2IIOP = "java2iiop"; 95 96 97 protected static final String VERIFY = "com.inprise.ejb.util.Verify"; 98 99 100 private String jarSuffix = "-ejb.jar"; 101 102 103 private String borlandDTD; 104 105 106 private boolean java2iiopdebug = false; 107 108 109 private String java2iioparams = null; 110 111 112 private boolean generateclient = false; 113 114 115 static final int BES = 5; 116 117 static final int BAS = 4; 118 119 120 private int version = BAS; 121 122 123 127 private boolean verify = true; 128 private String verifyArgs = ""; 129 130 private Hashtable genfiles = new Hashtable (); 131 132 136 public void setDebug(boolean debug) { 137 this.java2iiopdebug = debug; 138 } 139 140 144 public void setVerify(boolean verify) { 145 this.verify = verify; 146 } 147 148 149 153 public void setSuffix(String inString) { 154 this.jarSuffix = inString; 155 } 156 157 158 162 public void setVerifyArgs(String args) { 163 this.verifyArgs = args; 164 } 165 166 171 public void setBASdtd(String inString) { 172 this.borlandDTD = inString; 173 } 174 175 176 181 public void setGenerateclient(boolean b) { 182 this.generateclient = b; 183 } 184 185 189 public void setVersion(int version) { 190 this.version = version; 191 } 192 193 198 public void setJava2iiopParams(String params) { 199 this.java2iioparams = params; 200 } 201 202 203 208 protected DescriptorHandler getBorlandDescriptorHandler(final File srcDir) { 209 DescriptorHandler handler = 210 new DescriptorHandler(getTask(), srcDir) { 211 protected void processElement() { 212 if (currentElement.equals("type-storage")) { 213 String fileNameWithMETA = currentText; 215 String fileName 217 = fileNameWithMETA.substring(META_DIR.length(), 218 fileNameWithMETA.length()); 219 File descriptorFile = new File (srcDir, fileName); 220 221 ejbFiles.put(fileNameWithMETA, descriptorFile); 222 } 223 } 224 }; 225 handler.registerDTD(PUBLICID_BORLAND_EJB, 226 borlandDTD == null ? DEFAULT_BAS_DTD_LOCATION : borlandDTD); 227 228 for (Iterator i = getConfig().dtdLocations.iterator(); i.hasNext();) { 229 EjbJar.DTDLocation dtdLocation = (EjbJar.DTDLocation) i.next(); 230 handler.registerDTD(dtdLocation.getPublicId(), dtdLocation.getLocation()); 231 } 232 return handler; 233 } 234 235 241 protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) { 242 243 if (!(version == BES || version == BAS)) { 245 throw new BuildException("version " + version + " is not supported"); 246 } 247 248 String dd = (version == BES ? BES_DD : BAS_DD); 249 250 log("vendor file : " + ddPrefix + dd, Project.MSG_DEBUG); 251 252 File borlandDD = new File (getConfig().descriptorDir, ddPrefix + dd); 253 if (borlandDD.exists()) { 254 log("Borland specific file found " + borlandDD, Project.MSG_VERBOSE); 255 ejbFiles.put(META_DIR + dd , borlandDD); 256 } else { 257 log("Unable to locate borland deployment descriptor. " 258 + "It was expected to be in " 259 + borlandDD.getPath(), Project.MSG_WARN); 260 return; 261 } 262 } 263 264 268 File getVendorOutputJarFile(String baseName) { 269 return new File (getDestDir(), baseName + jarSuffix); 270 } 271 272 276 private void verifyBorlandJar(File sourceJar) { 277 if (version == BAS) { 278 verifyBorlandJarV4(sourceJar); 279 return; 280 } 281 if (version == BES) { 282 verifyBorlandJarV5(sourceJar); 283 return; 284 } 285 log("verify jar skipped because the version is invalid [" 286 + version + "]", Project.MSG_WARN); 287 } 288 289 293 private void verifyBorlandJarV5(File sourceJar) { 294 log("verify BES " + sourceJar, Project.MSG_INFO); 295 try { 296 ExecTask execTask = null; 297 execTask = new ExecTask(getTask()); 298 execTask.setDir(new File (".")); 299 execTask.setExecutable("iastool"); 300 if (getCombinedClasspath() != null) { 302 execTask.createArg().setValue("-VBJclasspath"); 303 execTask.createArg().setValue(getCombinedClasspath().toString()); 304 } 305 306 if (java2iiopdebug) { 307 execTask.createArg().setValue("-debug"); 308 } 309 execTask.createArg().setValue("-verify"); 310 execTask.createArg().setValue("-src"); 311 execTask.createArg().setValue(sourceJar.getPath()); 313 log("Calling iastool", Project.MSG_VERBOSE); 314 execTask.execute(); 315 } catch (Exception e) { 316 String msg = "Exception while calling generateclient Details: " 318 + e.toString(); 319 throw new BuildException(msg, e); 320 } 321 } 322 323 327 private void verifyBorlandJarV4(File sourceJar) { 328 org.apache.tools.ant.taskdefs.Java javaTask = null; 329 log("verify BAS " + sourceJar, Project.MSG_INFO); 330 try { 331 String args = verifyArgs; 332 args += " " + sourceJar.getPath(); 333 334 javaTask = new Java(getTask()); 335 javaTask.setTaskName("verify"); 336 javaTask.setClassname(VERIFY); 337 Commandline.Argument arguments = javaTask.createArg(); 338 arguments.setLine(args); 339 Path classpath = getCombinedClasspath(); 340 if (classpath != null) { 341 javaTask.setClasspath(classpath); 342 javaTask.setFork(true); 343 } 344 345 log("Calling " + VERIFY + " for " + sourceJar.toString(), 346 Project.MSG_VERBOSE); 347 javaTask.execute(); 348 } catch (Exception e) { 349 String msg = "Exception while calling " + VERIFY + " Details: " 351 + e.toString(); 352 throw new BuildException(msg, e); 353 } 354 } 355 356 357 362 private void generateClient(File sourceJar) { 363 getTask().getProject().addTaskDefinition("internal_bas_generateclient", 364 org.apache.tools.ant.taskdefs.optional.ejb.BorlandGenerateClient.class); 365 366 org.apache.tools.ant.taskdefs.optional.ejb.BorlandGenerateClient gentask = null; 367 log("generate client for " + sourceJar, Project.MSG_INFO); 368 try { 369 Project project = getTask().getProject(); 370 gentask 371 = (BorlandGenerateClient) project.createTask("internal_bas_generateclient"); 372 gentask.setEjbjar(sourceJar); 373 gentask.setDebug(java2iiopdebug); 374 Path classpath = getCombinedClasspath(); 375 if (classpath != null) { 376 gentask.setClasspath(classpath); 377 } 378 gentask.setVersion(version); 379 gentask.setTaskName("generate client"); 380 gentask.execute(); 381 } catch (Exception e) { 382 String msg = "Exception while calling " + VERIFY + " Details: " 384 + e.toString(); 385 throw new BuildException(msg, e); 386 } 387 } 388 389 394 private void buildBorlandStubs(Iterator ithomes) { 395 Execute execTask = null; 396 397 execTask = new Execute(this); 398 Project project = getTask().getProject(); 399 execTask.setAntRun(project); 400 execTask.setWorkingDirectory(project.getBaseDir()); 401 402 Commandline commandline = new Commandline(); 403 commandline.setExecutable(JAVA2IIOP); 404 if (java2iiopdebug) { 406 commandline.createArgument().setValue("-VBJdebug"); 407 } 408 commandline.createArgument().setValue("-VBJclasspath"); 410 commandline.createArgument().setPath(getCombinedClasspath()); 411 commandline.createArgument().setValue("-list_files"); 413 commandline.createArgument().setValue("-no_tie"); 415 416 if (java2iioparams != null) { 417 log("additional " + java2iioparams + " to java2iiop ", 0); 418 commandline.createArgument().setValue(java2iioparams); 419 } 420 421 422 commandline.createArgument().setValue("-root_dir"); 424 commandline.createArgument().setValue(getConfig().srcDir.getAbsolutePath()); 425 commandline.createArgument().setValue("-compile"); 427 while (ithomes.hasNext()) { 429 commandline.createArgument().setValue(ithomes.next().toString()); 430 } 431 432 try { 433 log("Calling java2iiop", Project.MSG_VERBOSE); 434 log(commandline.describeCommand(), Project.MSG_DEBUG); 435 execTask.setCommandline(commandline.getCommandline()); 436 int result = execTask.execute(); 437 if (Execute.isFailure(result)) { 438 String msg = "Failed executing java2iiop (ret code is " 439 + result + ")"; 440 throw new BuildException(msg, getTask().getLocation()); 441 } 442 } catch (java.io.IOException e) { 443 log("java2iiop exception :" + e.getMessage(), Project.MSG_ERR); 444 throw new BuildException(e, getTask().getLocation()); 445 } 446 } 447 448 458 protected void writeJar(String baseName, File jarFile, Hashtable files, String publicId) 459 throws BuildException { 460 Vector homes = new Vector (); 462 Iterator it = files.keySet().iterator(); 463 while (it.hasNext()) { 464 String clazz = (String ) it.next(); 465 if (clazz.endsWith("Home.class")) { 466 String home = toClass(clazz); 468 homes.add(home); 469 log(" Home " + home, Project.MSG_VERBOSE); 470 } 471 } 472 473 buildBorlandStubs(homes.iterator()); 474 475 files.putAll(genfiles); 477 478 super.writeJar(baseName, jarFile, files, publicId); 479 480 if (verify) { 481 verifyBorlandJar(jarFile); 482 } 483 484 if (generateclient) { 485 generateClient(jarFile); 486 } 487 } 488 489 493 private String toClass(String filename) { 494 String classname = filename.substring(0, filename.lastIndexOf(".class")); 496 classname = classname.replace('\\', '.'); 497 return classname; 498 } 499 500 504 private String toClassFile(String filename) { 505 String classfile = filename.substring(0, filename.lastIndexOf(".java")); 507 classfile = classfile + ".class"; 508 return classfile; 509 } 510 511 513 514 public void start() throws IOException { } 515 516 public void stop() { } 517 518 public void setProcessInputStream(OutputStream param1) throws IOException { } 519 520 525 public void setProcessOutputStream(InputStream is) throws IOException { 526 try { 527 BufferedReader reader = new BufferedReader (new InputStreamReader (is)); 528 String javafile; 529 while ((javafile = reader.readLine()) != null) { 530 if (javafile.endsWith(".java")) { 531 String classfile = toClassFile(javafile); 532 String key = classfile.substring( 533 getConfig().srcDir.getAbsolutePath().length() + 1); 534 genfiles.put(key, new File (classfile)); 535 } 536 } 537 reader.close(); 538 } catch (Exception e) { 539 String msg = "Exception while parsing java2iiop output. Details: " + e.toString(); 540 throw new BuildException(msg, e); 541 } 542 } 543 544 549 public void setProcessErrorStream(InputStream is) throws IOException { 550 BufferedReader reader = new BufferedReader (new InputStreamReader (is)); 551 String s = reader.readLine(); 552 if (s != null) { 553 log("[java2iiop] " + s, Project.MSG_ERR); 554 } 555 } 556 } 557 558 | Popular Tags |