1 23 24 77 78 package org.apache.tools.ant.taskdefs.optional.sun.appserv; 79 80 import org.apache.tools.ant.Project; 81 import org.apache.tools.ant.BuildException; 82 83 import java.io.File ; 84 85 100 public class DeployTask extends ComponentAdmin { 101 private static final String DEPLOY_COMMAND = "deploy"; 102 private static final String DEPLOY_DIR_COMMAND = "deploydir"; 103 LocalStringsManager lsm = new LocalStringsManager(); 104 105 protected Server getNewServer() { 106 return new DeployServer(server); 107 } 108 109 protected Component getNewComponent() { 110 return new DeployComponent(component); 111 } 112 113 121 public void setUpload(boolean upload) { 122 ((DeployServer)server).setUpload(upload); } 124 125 132 public void setVirtualServers(String virtualServers) { 133 ((DeployServer)server).setVirtualServers(virtualServers); 134 } 135 136 143 public void setForce(boolean force) { 144 ((DeployComponent)component).setForce(force); } 146 147 153 public void setEnabled(boolean enabled) { 154 ((DeployComponent)component).setEnabled(enabled); } 156 157 162 public void setRetrieveStubs(File stubsDir) { 163 ((DeployComponent)component).setRetrieveStubs(stubsDir); } 165 166 172 public void setContextroot(String contextroot) { 173 ((DeployComponent)component).setContextroot(contextroot); } 175 176 182 public void setDeploymentplan(File deploymentplan) { 183 ((DeployComponent)component).setDeploymentplan(deploymentplan); } 185 186 191 public void setDbvendorname(String dbvendorname) { 192 ((DeployComponent)component).setDbvendorname(dbvendorname); } 194 195 200 public void setCreatetables(boolean createtables) { 201 ((DeployComponent)component).setCreatetables(createtables); } 203 204 210 public void setDropandcreatetables(boolean dropandcreatetables) { 211 ((DeployComponent)component).setDropandcreatetables(dropandcreatetables); } 213 214 220 public void setUniquetablenames(boolean uniquetablenames) { 221 ((DeployComponent)component).setUniquetablenames(uniquetablenames); } 223 224 231 public void setAvailabilityenabled(boolean availabilityenabled) { 232 ((DeployComponent)component).setAvailabilityenabled(availabilityenabled); } 234 235 241 public void setGeneratermistubs(boolean generatermistubs) { 242 ((DeployComponent)component).setGeneratermistubs(generatermistubs); } 244 245 246 253 public void setPrecompileJsp(boolean precompile) { 254 ((DeployComponent)component).setPrecompileJsp(precompile); } 256 257 264 public void setVerify(boolean verify) { 265 ((DeployComponent)component).setVerify(verify); 266 } 267 268 273 public Server createServer() { 274 log("createServer using DeployServer object", Project.MSG_DEBUG); 275 Server aNestedServer = new DeployServer(server); 276 servers.add(aNestedServer); 277 return aNestedServer; 278 } 279 280 protected void checkComponentConfig(Server aServer, Component comp) 281 throws BuildException { 282 log("Checking component and server config in DeployTask", Project.MSG_DEBUG); 283 284 DeployServer deployServer = (DeployServer) aServer; 285 DeployComponent deployComp = (DeployComponent) comp; 286 287 File theFile = comp.getFile(); 289 if (theFile == null) { 290 throw new BuildException(lsm.getString("ComponentFileMustBeSpecified", 291 new Object [] {getTaskName()}), getLocation()); 292 } 293 294 300 super.checkComponentConfig(aServer, comp); 301 302 if (theFile.isDirectory() && deployServer.getUpload()) { 304 String hostname = aServer.getHost(); 305 if (hostname == null) { 306 hostname = "localhost"; 307 } 308 throw new BuildException(lsm.getString("UploadMayNotBeSetToTrue", 309 new Object [] {theFile.getAbsolutePath()}), 310 getLocation()); 311 } 312 313 File theDir = deployComp.getRetrieveStubs(); 315 if (theDir != null) { 316 if (!theDir.exists()) { 317 throw new BuildException(lsm.getString( 318 "RetrieveStubsDirectoryDoesNotExist", 319 new Object [] {theDir}), getLocation()); 320 } 321 if (!theDir.isDirectory()) { 322 throw new BuildException(lsm.getString( 323 "RetrievesStbusDoesNotReferToADirectory", 324 new Object [] {theDir}), getLocation()); 325 } 326 } 327 } 328 329 protected String getCommandString(Server aServer, Component comp) 330 throws BuildException { 331 DeployServer deployServer = (DeployServer) aServer; 332 DeployComponent deployComp = (DeployComponent) comp; 333 334 CheckForMutuallyExclusiveAttribute(deployComp); 335 336 StringBuffer cmdString; 337 boolean isFile = comp.getFile().isFile(); 338 339 cmdString = new StringBuffer (isFile ? DEPLOY_COMMAND : DEPLOY_DIR_COMMAND); 340 cmdString.append(aServer.getCommandParameters(true)); 341 if (comp.getType() != null) { 342 log(lsm.getString("DeprecatedTypeAttribute"), Project.MSG_WARN); 343 } 344 cmdString.append(" --force=").append(deployComp.isForce()); 345 cmdString.append(" --enabled=").append(deployComp.isEnabled()); 346 cmdString.append(" --name ").append(comp.getName()); 347 cmdString.append(" --verify=").append(deployComp.isVerify()); 348 cmdString.append(" --precompilejsp=").append(deployComp.isPrecompileJsp()); 349 if (isFile) { 350 cmdString.append(" --upload=").append(deployServer.getUpload()); 351 } 352 if (deployServer.getVirtualServers() != null) { 353 cmdString.append(" --virtualservers "); 354 cmdString.append(deployServer.getVirtualServers()); 355 } 356 357 if (deployComp.getRetrieveStubs() != null) { 358 cmdString.append(" --retrieve "); 359 cmdString.append("\""+deployComp.getRetrieveStubs()+"\""); 360 } 361 if (deployComp.getDeploymentplan() != null) { 362 cmdString.append(" --deploymentplan "); 363 cmdString.append("\""+deployComp.getDeploymentplan()+"\""); 364 } 365 366 if (deployComp.contextRootIsSet()) { 367 cmdString.append(" --contextroot ").append(deployComp.getContextroot()); 368 } 369 if (deployComp.getDbvendorname() != null) { 370 cmdString.append(" --dbvendorname ").append(deployComp.getDbvendorname()); 371 } 372 if (deployComp.createtablesIsSet) { 373 cmdString.append(" --createtables=").append(deployComp.getCreatetables()); 374 deployComp.createtablesIsSet = false; } 376 if (deployComp.dropandcreatetablesIsSet) { 377 cmdString.append(" --dropandcreatetables=").append(deployComp.getDropandcreatetables()); 378 deployComp.dropandcreatetablesIsSet = false; } 380 if (deployComp.uniquetablenamesIsSet) { 381 cmdString.append(" --uniquetablenames=").append(deployComp.getUniquetablenames()); 382 deployComp.uniquetablenamesIsSet = false; } 384 if (deployComp.availabilityenabledIsSet) { 385 cmdString.append(" --availabilityenabled=").append(deployComp.getAvailabilityenabled()); 386 deployComp.availabilityenabledIsSet = false; } 388 if (deployComp.generatermistubsIsSet) { 389 cmdString.append(" --generatermistubs=").append(deployComp.getGeneratermistubs()); 390 deployComp.generatermistubsIsSet = false; } 392 393 String lTarget = deployComp.getTarget(); 395 if ((lTarget != null) && (lTarget.length() > 0)) { 396 cmdString.append(" --target ").append(lTarget); 397 } 398 399 cmdString.append(" ").append("\""+comp.getFile().getPath()+"\""); 400 401 return cmdString.toString(); 402 } 403 404 405 410 private void CheckForMutuallyExclusiveAttribute(DeployComponent deployComp) 411 throws BuildException 412 { 413 if (deployComp.createtablesIsSet && 414 deployComp.dropandcreatetablesIsSet ) { 415 final String msg = lsm.getString("MutuallyExclusivelyAttribute", 416 new Object [] {"createtables", 417 "dropandcreatetables"}); 418 throw new BuildException(msg, getLocation()); 419 } 420 } 421 422 423 431 public class DeployServer extends Server { 432 private boolean upload; private String virtualServers = null; 435 441 private boolean uploadIsSet = false; 442 443 private static final boolean DEFAULT_UPLOAD = true; 444 445 449 public DeployServer() { 450 this(null); 451 } 452 453 459 public DeployServer(Server theParent) { 460 super(theParent); 461 } 462 463 471 public void setUpload(boolean upload) { 472 this.upload = upload; 473 uploadIsSet = true; } 475 476 483 protected boolean getUpload() { 484 DeployServer theParent = (DeployServer) getParent(); 485 if (!uploadIsSet) { 486 return (theParent == null) ? DEFAULT_UPLOAD : theParent.getUpload(); 487 } 488 return upload; 489 } 490 491 498 public void setVirtualServers(String virtualServers) { 499 this.virtualServers = virtualServers; 500 } 501 502 509 public String getVirtualServers() { 510 return virtualServers; 511 } 512 } 513 514 515 521 public class DeployComponent extends Component { 522 private boolean force; private boolean precompile; private File stubsDir; private String contextroot; private boolean verify; private boolean enabled; private File deploymentplan; private boolean availabilityenabled; private boolean generatermistubs; private String dbvendorname; private boolean createtables; private boolean dropandcreatetables; private boolean uniquetablenames; 548 554 private boolean forceIsSet = false; 555 private boolean enabledIsSet = false; 556 private boolean precompileIsSet = false; 557 private boolean verifyIsSet = false; 558 public boolean createtablesIsSet = false; 559 public boolean dropandcreatetablesIsSet = false; 560 public boolean uniquetablenamesIsSet = false; 561 public boolean availabilityenabledIsSet = false; 562 public boolean generatermistubsIsSet = false; 563 564 565 568 private static final boolean DEFAULT_FORCE = true; 569 private static final boolean DEFAULT_PRECOMPILE = false; 570 private static final boolean DEFAULT_VERIFY = false; 571 private static final boolean DEFAULT_ENABLED = true; 572 573 579 public DeployComponent(Component theParent) { 580 super(theParent); 581 } 582 583 590 public void setForce(boolean force) { 591 this.force = force; 592 forceIsSet = true; } 594 595 602 protected boolean isForce() { 603 if (!forceIsSet) { 604 return (parent == null) ? DEFAULT_FORCE : ((DeployComponent)parent).isForce(); 605 } 606 return force; 607 } 608 609 614 public void setEnabled(boolean enabled) { 615 this.enabled = enabled; 616 enabledIsSet = true; } 618 619 622 protected boolean isEnabled() { 623 if (!enabledIsSet) { 624 return (parent == null) ? DEFAULT_ENABLED : ((DeployComponent)parent).isEnabled(); 625 } 626 return enabled; 627 } 628 629 637 public void setAvailabilityenabled(boolean availabilityenabled) { 638 this.availabilityenabled = availabilityenabled; 639 availabilityenabledIsSet = true; } 641 642 648 protected boolean getAvailabilityenabled() { 649 return availabilityenabled; 650 } 651 652 653 659 public void setGeneratermistubs(boolean generatermistubs) { 660 this.generatermistubs = generatermistubs; 661 generatermistubsIsSet = true; } 663 664 668 protected boolean getGeneratermistubs() { 669 return generatermistubs; 670 } 671 672 677 public void setRetrieveStubs(File stubsDir) { 678 this.stubsDir = stubsDir; 679 } 680 681 688 protected File getRetrieveStubs() { 689 if (stubsDir == null) { 690 return (parent == null) ? null : ((DeployComponent)parent).getRetrieveStubs(); 691 } 692 return stubsDir; 693 } 694 695 701 public void setContextroot(String contextroot) { 702 this.contextroot = contextroot; 703 } 704 705 710 protected String getContextroot() { 711 return (contextroot != null) ? contextroot : getName(); 712 } 713 714 719 protected boolean contextRootIsSet() { 720 return (contextroot != null); 721 } 722 723 724 731 public void setDeploymentplan(File deploymentplan) { 732 this.deploymentplan = deploymentplan; 733 } 734 735 742 protected File getDeploymentplan() { 743 if (deploymentplan == null) { 744 return (parent == null) ? null : ((DeployComponent)parent).getDeploymentplan(); 745 } 746 return deploymentplan; 747 } 748 749 754 public void setDbvendorname(String dbvendorname) { 755 this.dbvendorname = dbvendorname; 756 } 757 758 763 protected String getDbvendorname() { 764 return (dbvendorname != null) ? dbvendorname : null; 765 } 766 767 772 public void setCreatetables(boolean createtables) { 773 this.createtables = createtables; 774 createtablesIsSet = true; } 776 777 782 protected boolean getCreatetables() { 783 return createtables; 784 } 785 786 794 public void setDropandcreatetables(boolean dropandcreatetables) { 795 this.dropandcreatetables = dropandcreatetables; 796 dropandcreatetablesIsSet = true; } 799 800 803 protected boolean getDropandcreatetables() { 804 return dropandcreatetables; 805 } 806 807 813 public void setUniquetablenames(boolean uniquetablenames) { 814 this.uniquetablenames = uniquetablenames; 815 uniquetablenamesIsSet = true; } 818 819 822 protected boolean getUniquetablenames() { 823 return uniquetablenames; 824 } 825 826 827 828 834 public void setPrecompileJsp(boolean precompile) { 835 this.precompile = precompile; 836 precompileIsSet = true; } 838 839 845 protected boolean isPrecompileJsp() { 846 if (!precompileIsSet) { 847 return (parent == null) ? DEFAULT_PRECOMPILE : ((DeployComponent)parent).isPrecompileJsp(); 848 } 849 return precompile; 850 } 851 852 859 public void setVerify(boolean verify) { 860 this.verify = verify; 861 verifyIsSet = true; } 863 864 870 protected boolean isVerify() { 871 if (!verifyIsSet) { 872 return (parent == null) ? DEFAULT_VERIFY : ((DeployComponent)parent).isVerify(); 873 } 874 return verify; 875 } 876 } 877 } 878 | Popular Tags |