Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 452   Methods: 20
NCLOC: 186   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
WLRun.java 0% 0% 0% 0%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
 5   
  * reserved.
 6   
  *
 7   
  * Redistribution and use in source and binary forms, with or without
 8   
  * modification, are permitted provided that the following conditions
 9   
  * are met:
 10   
  *
 11   
  * 1. Redistributions of source code must retain the above copyright
 12   
  *    notice, this list of conditions and the following disclaimer.
 13   
  *
 14   
  * 2. Redistributions in binary form must reproduce the above copyright
 15   
  *    notice, this list of conditions and the following disclaimer in
 16   
  *    the documentation and/or other materials provided with the
 17   
  *    distribution.
 18   
  *
 19   
  * 3. The end-user documentation included with the redistribution, if
 20   
  *    any, must include the following acknowlegement:
 21   
  *       "This product includes software developed by the
 22   
  *        Apache Software Foundation (http://www.apache.org/)."
 23   
  *    Alternately, this acknowlegement may appear in the software itself,
 24   
  *    if and wherever such third-party acknowlegements normally appear.
 25   
  *
 26   
  * 4. The names "Ant" and "Apache Software
 27   
  *    Foundation" must not be used to endorse or promote products derived
 28   
  *    from this software without prior written permission. For written
 29   
  *    permission, please contact apache@apache.org.
 30   
  *
 31   
  * 5. Products derived from this software may not be called "Apache"
 32   
  *    nor may "Apache" appear in their names without prior written
 33   
  *    permission of the Apache Group.
 34   
  *
 35   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 36   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 37   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 38   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 39   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 40   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 41   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 42   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 44   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 45   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46   
  * SUCH DAMAGE.
 47   
  * ====================================================================
 48   
  *
 49   
  * This software consists of voluntary contributions made by many
 50   
  * individuals on behalf of the Apache Software Foundation.  For more
 51   
  * information on the Apache Software Foundation, please see
 52   
  * <http://www.apache.org/>.
 53   
  */
 54   
 package org.apache.tools.ant.taskdefs.optional.ejb;
 55   
 
 56   
 
 57   
 import java.io.File;
 58   
 import org.apache.tools.ant.BuildException;
 59   
 import org.apache.tools.ant.Task;
 60   
 import org.apache.tools.ant.taskdefs.Java;
 61   
 import org.apache.tools.ant.types.Path;
 62   
 
 63   
 /**
 64   
  * Starts a WebLogic server.
 65   
  * A number of parameters are used to control the operation of the weblogic instance. Note that the task,
 66   
  * and hence ant, will not complete until the weblogic instance is stopped.</p>
 67   
  *
 68   
  * @author Conor MacNeill, Cortex ebusiness Pty Limited
 69   
  */
 70   
 public class WLRun extends Task {
 71   
     protected static final String DEFAULT_WL51_POLICY_FILE = "weblogic.policy";
 72   
     protected static final String DEFAULT_WL60_POLICY_FILE = "lib/weblogic.policy";
 73   
     protected static final String DEFAULT_PROPERTIES_FILE = "weblogic.properties";
 74   
 
 75   
     /**
 76   
      * The classpath to be used when running the Java VM. It must contain the weblogic
 77   
      * classes <b>and</b> the implementation classes of the home and remote interfaces.
 78   
      */
 79   
     private Path classpath;
 80   
 
 81   
     /**
 82   
      * The weblogic classpath to the be used when running weblogic.
 83   
      */
 84   
     private Path weblogicClasspath;
 85   
 
 86   
     private String weblogicMainClass = "weblogic.Server";
 87   
 
 88   
     /**
 89   
      * Addional arguments to pass to the JVM used to run weblogic
 90   
      */
 91   
     private String additionalArgs = "";
 92   
 
 93   
     /**
 94   
      * The security policy to use when running the weblogic server
 95   
      */
 96   
     private String securityPolicy;
 97   
 
 98   
     /**
 99   
      * The weblogic system home directory
 100   
      */
 101   
     private File weblogicSystemHome;
 102   
 
 103   
     /**
 104   
      * The weblogic domain
 105   
      */
 106   
     private String weblogicDomainName;
 107   
 
 108   
     /**
 109   
      * The name of the weblogic server - used to select the server's directory in the
 110   
      * weblogic home directory.
 111   
      */
 112   
     private String weblogicSystemName = "myserver";
 113   
 
 114   
     /**
 115   
      * The file containing the weblogic properties for this server.
 116   
      */
 117   
     private String weblogicPropertiesFile = null;
 118   
 
 119   
     /**
 120   
      * additional args to pass to the spawned jvm
 121   
      */
 122   
     private String additionalJvmArgs = "";
 123   
 
 124   
     /**
 125   
      * The location of the BEA Home under which this server is run.
 126   
      * WL6 only
 127   
      */
 128   
     private File beaHome = null;
 129   
 
 130   
     /**
 131   
      * The management username
 132   
      */
 133   
     private String managementUsername = "system";
 134   
 
 135   
     /**
 136   
      * The management password
 137   
      */
 138   
     private String managementPassword = null;
 139   
 
 140   
     /**
 141   
      * The provate key password - used for SSL
 142   
      */
 143   
     private String pkPassword = null;
 144   
 
 145   
     /**
 146   
      * Add the classpath for the user classes
 147   
      */
 148  0
     public Path createClasspath() {
 149  0
         if (classpath == null) {
 150  0
             classpath = new Path(getProject());
 151   
         }
 152  0
         return classpath.createPath();
 153   
     }
 154   
 
 155   
     /**
 156   
      * Get the classpath to the weblogic classpaths
 157   
      */
 158  0
     public Path createWLClasspath() {
 159  0
         if (weblogicClasspath == null) {
 160  0
             weblogicClasspath = new Path(getProject());
 161   
         }
 162  0
         return weblogicClasspath.createPath();
 163   
     }
 164   
 
 165   
     /**
 166   
      * Do the work.
 167   
      *
 168   
      * The work is actually done by creating a separate JVM to run a helper task.
 169   
      * This approach allows the classpath of the helper task to be set. Since the
 170   
      * weblogic tools require the class files of the project's home and remote
 171   
      * interfaces to be available in the classpath, this also avoids having to
 172   
      * start ant with the class path of the project it is building.
 173   
      *
 174   
      * @exception BuildException if someting goes wrong with the build
 175   
      */
 176  0
     public void execute() throws BuildException {
 177  0
         if (weblogicSystemHome == null) {
 178  0
             throw new BuildException("weblogic home must be set");
 179   
         }
 180  0
         if (!weblogicSystemHome.isDirectory()) {
 181  0
             throw new BuildException("weblogic home directory " + weblogicSystemHome.getPath() +
 182   
                                      " is not valid");
 183   
         }
 184   
 
 185  0
         if (beaHome != null) {
 186  0
             executeWLS6();
 187   
         } else {
 188  0
             executeWLS();
 189   
         }
 190   
     }
 191   
 
 192  0
     private File findSecurityPolicyFile(String defaultSecurityPolicy) {
 193  0
         String securityPolicy = this.securityPolicy;
 194  0
         if (securityPolicy == null) {
 195  0
             securityPolicy = defaultSecurityPolicy;
 196   
         }
 197  0
         File securityPolicyFile = new File(weblogicSystemHome, securityPolicy);
 198   
         // If an explicit securityPolicy file was specified, it maybe an
 199   
         // absolute path.  Use the project to resolve it.
 200  0
         if (this.securityPolicy != null && !securityPolicyFile.exists()) {
 201  0
             securityPolicyFile = getProject().resolveFile(securityPolicy);
 202   
         }
 203   
         // If we still can't find it, complain
 204  0
         if (!securityPolicyFile.exists()) {
 205  0
             throw new BuildException("Security policy " + securityPolicy +
 206   
                                      " was not found.");
 207   
         }
 208  0
         return securityPolicyFile;
 209   
     }
 210   
 
 211  0
     private void executeWLS6() {
 212  0
         File securityPolicyFile
 213   
             = findSecurityPolicyFile(DEFAULT_WL60_POLICY_FILE);
 214  0
         if (!beaHome.isDirectory()) {
 215  0
             throw new BuildException("BEA home " + beaHome.getPath() +
 216   
                                      " is not valid");
 217   
         }
 218   
 
 219  0
         File configFile = new File(weblogicSystemHome, "config/"
 220   
             + weblogicDomainName + "/config.xml");
 221  0
         if (!configFile.exists()) {
 222  0
             throw new BuildException("Server config file " + configFile
 223   
                 + " not found.");
 224   
         }
 225   
 
 226  0
         if (managementPassword == null) {
 227  0
             throw new BuildException("You must supply a management password to start the server");
 228   
         }
 229   
 
 230  0
         Java weblogicServer = (Java) getProject().createTask("java");
 231  0
         weblogicServer.setTaskName(getTaskName());
 232  0
         weblogicServer.setFork(true);
 233  0
         weblogicServer.setDir(weblogicSystemHome);
 234  0
         weblogicServer.setClassname(weblogicMainClass);
 235   
 
 236  0
         String jvmArgs = additionalJvmArgs;
 237   
 
 238  0
         jvmArgs += " -Dweblogic.Domain=" + weblogicDomainName;
 239  0
         jvmArgs += " -Dweblogic.Name=" + weblogicSystemName;
 240  0
         jvmArgs += " -Dweblogic.system.home=" + weblogicSystemHome;
 241   
 
 242  0
         jvmArgs += " -Dbea.home=" + beaHome;
 243  0
         jvmArgs += " -Djava.security.policy==" + securityPolicyFile;
 244   
 
 245  0
         jvmArgs += " -Dweblogic.management.username=" + managementUsername;
 246  0
         jvmArgs += " -Dweblogic.management.password=" + managementPassword;
 247  0
         if (pkPassword != null) {
 248  0
             jvmArgs += " -Dweblogic.pkpassword=" + pkPassword;
 249   
         }
 250   
 
 251   
 
 252  0
         weblogicServer.createJvmarg().setLine(jvmArgs);
 253  0
         weblogicServer.createArg().setLine(additionalArgs);
 254   
 
 255  0
         if (classpath != null) {
 256  0
             weblogicServer.setClasspath(classpath);
 257   
         }
 258   
 
 259  0
         if (weblogicServer.executeJava() != 0) {
 260  0
             throw new BuildException("Execution of weblogic server failed");
 261   
         }
 262   
      }
 263   
 
 264  0
     private void executeWLS() {
 265  0
         File securityPolicyFile
 266   
             = findSecurityPolicyFile(DEFAULT_WL51_POLICY_FILE);
 267  0
         File propertiesFile = null;
 268   
 
 269   
 
 270  0
         if (weblogicPropertiesFile == null) {
 271  0
             weblogicPropertiesFile = DEFAULT_PROPERTIES_FILE;
 272   
         }
 273  0
         propertiesFile = new File(weblogicSystemHome, weblogicPropertiesFile);
 274  0
         if (!propertiesFile.exists()) {
 275   
             // OK, properties file may be absolute
 276  0
             propertiesFile = getProject().resolveFile(weblogicPropertiesFile);
 277  0
             if (!propertiesFile.exists()) {
 278  0
                 throw new BuildException("Properties file " + weblogicPropertiesFile +
 279   
                                          " not found in weblogic home " + weblogicSystemHome +
 280   
                                          " or as absolute file");
 281   
             }
 282   
         }
 283   
 
 284  0
         Java weblogicServer = (Java) getProject().createTask("java");
 285  0
         weblogicServer.setTaskName(getTaskName());
 286  0
         weblogicServer.setFork(true);
 287  0
         weblogicServer.setClassname(weblogicMainClass);
 288   
 
 289  0
         String jvmArgs = additionalJvmArgs;
 290   
 
 291  0
         if (weblogicClasspath != null) {
 292  0
             jvmArgs += " -Dweblogic.class.path=" + weblogicClasspath;
 293   
         }
 294   
 
 295  0
         jvmArgs += " -Djava.security.manager -Djava.security.policy==" + securityPolicyFile;
 296  0
         jvmArgs += " -Dweblogic.system.home=" + weblogicSystemHome;
 297  0
         jvmArgs += " -Dweblogic.system.name=" + weblogicSystemName;
 298  0
         jvmArgs += " -Dweblogic.system.propertiesFile=" + weblogicPropertiesFile;
 299   
 
 300  0
         weblogicServer.createJvmarg().setLine(jvmArgs);
 301  0
         weblogicServer.createArg().setLine(additionalArgs);
 302   
 
 303  0
         if (classpath != null) {
 304  0
             weblogicServer.setClasspath(classpath);
 305   
         }
 306  0
         if (weblogicServer.executeJava() != 0) {
 307  0
             throw new BuildException("Execution of weblogic server failed");
 308   
         }
 309   
     }
 310   
 
 311   
 
 312   
     /**
 313   
      * The classpath to be used with the Java Virtual Machine that runs the Weblogic
 314   
      * Server; required. Prior to Weblogic 6.0, this is typically set to the Weblogic
 315   
      * boot classpath. Under Weblogic 6.0 this should include all the
 316   
      * weblogic jars
 317   
      *
 318   
      * @param classpath the classpath to use when executing the weblogic server.
 319   
      */
 320  0
     public void setClasspath(Path classpath) {
 321  0
         this.classpath = classpath;
 322   
     }
 323   
 
 324   
     /**
 325   
      * Set the weblogic classpath used by the Weblogic Server;
 326   
      * optional, and only applicable to WL4.5.1
 327   
      *
 328   
      * The weblogic classpath is used by weblogic to support dynamic class loading.
 329   
      *
 330   
      * @param weblogicClasspath the weblogic classpath
 331   
      */
 332  0
     public void setWlclasspath(Path weblogicClasspath) {
 333  0
         this.weblogicClasspath = weblogicClasspath;
 334   
     }
 335   
 
 336   
     /**
 337   
      * The name of the security policy file within the weblogic home directory that
 338   
      * is to be used. If not specified, the default policy file <code>weblogic.policy</code>
 339   
      * is used.
 340   
      *
 341   
      * @param securityPolicy the security policy to use.
 342   
      */
 343  0
     public void setPolicy(String securityPolicy) {
 344  0
         this.securityPolicy = securityPolicy;
 345   
     }
 346   
 
 347   
     /**
 348   
      * The location where weblogic lives.
 349   
      * Required. This is the absolute location, not relative to
 350   
      *  BEA home.
 351   
      * @param weblogicHome the home directory of weblogic.
 352   
      *
 353   
      */
 354  0
     public void setHome(File weblogicHome) {
 355  0
         weblogicSystemHome = weblogicHome;
 356   
     }
 357   
 
 358   
     /**
 359   
      * The location of the BEA Home; implicitly
 360   
      * selects Weblogic 6.0; optional.
 361   
      *
 362   
      * @param beaHome the BEA Home directory.
 363   
      *
 364   
      */
 365  0
     public void setBEAHome(File beaHome) {
 366  0
         this.beaHome = beaHome;
 367   
     }
 368   
 
 369   
     /**
 370   
      * The name of the weblogic server within the weblogic home which is to be run.
 371   
      * Optiona, defaults to &quot;myserver&quot;
 372   
      *
 373   
      * @param serverName the name of the server.
 374   
      */
 375  0
     public void setName(String serverName) {
 376  0
         this.weblogicSystemName = serverName;
 377   
     }
 378   
 
 379   
     /**
 380   
      * Set the Domain to run in; required for WL6.0
 381   
      *
 382   
      * @param domain the domain
 383   
      */
 384  0
     public void setDomain(String domain) {
 385  0
         this.weblogicDomainName = domain;
 386   
     }
 387   
 
 388   
     /**
 389   
      * The name of the server's properties file within the weblogic home directory
 390   
      * used to control the weblogic instance;
 391   
      * required for WL4.5.1
 392   
      *
 393   
      *
 394   
      * @param propertiesFilename the properties file name
 395   
      */
 396  0
     public void setProperties(String propertiesFilename) {
 397  0
         this.weblogicPropertiesFile = propertiesFilename;
 398   
     }
 399   
 
 400   
     /**
 401   
      * Set the additional arguments to pass to the weblogic JVM
 402   
      * @param args the arguments to be passed to the JVM
 403   
      */
 404  0
     public void setJvmargs(String args) {
 405  0
         this.additionalJvmArgs = args;
 406   
     }
 407   
 
 408   
     /**
 409   
      * Set the management username to run the server;
 410   
      * optional and only applicable to WL6.0.
 411   
      *
 412   
      * @param username the management username of the server.
 413   
      */
 414  0
     public void setUsername(String username) {
 415  0
         this.managementUsername = username;
 416   
     }
 417   
 
 418   
 
 419   
     /**
 420   
      * Set the management password of the server;
 421   
      * optional and only applicable to WL6.0.
 422   
      * @param password the management pasword of the server.
 423   
      */
 424  0
     public void setPassword(String password) {
 425  0
         this.managementPassword = password;
 426   
     }
 427   
 
 428   
     /**
 429   
      * Set the private key password so the server can decrypt the SSL private key file;
 430   
      * optional and only applicable to WL6.0.
 431   
      * @param pkpassword the private key password,
 432   
      */
 433  0
     public void setPKPassword(String pkpassword) {
 434  0
         this.pkPassword = pkpassword;
 435   
     }
 436   
 
 437   
     /**
 438   
      * Additional argument string passed to the Weblogic instance;
 439   
      * optional.
 440   
      */
 441  0
     public void setArgs(String args) {
 442  0
         additionalArgs = args;
 443   
     }
 444   
 
 445   
     /**
 446   
      * name of the main class for weblogic; optional.
 447   
      */
 448  0
     public void setWeblogicMainClass(String c) {
 449  0
         weblogicMainClass = c;
 450   
     }
 451   
 }
 452