diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WLRun.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WLRun.java index 6579b8d83..0322db781 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WLRun.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WLRun.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 2000, 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -69,7 +69,9 @@ import java.io.File; * @author Conor MacNeill, Cortex ebusiness Pty Limited */ public class WLRun extends Task { - static private final String defaultPolicyFile = "weblogic.policy"; + static protected final String DEFAULT_WL51_POLICY_FILE = "weblogic.policy"; + static protected final String DEFAULT_WL60_POLICY_FILE = "lib/weblogic.policy"; + static protected final String DEFAULT_PROPERTIES_FILE = "weblogic.properties"; /** * The classpath to be used when running the Java VM. It must contain the weblogic @@ -83,6 +85,10 @@ public class WLRun extends Task { private Path weblogicClasspath; private String weblogicMainClass = "weblogic.Server"; + + /** + * Addional arguments to pass to the JVM used to run weblogic + */ private String additionalArgs = ""; /** @@ -94,6 +100,11 @@ public class WLRun extends Task { * The weblogic system home directory */ private File weblogicSystemHome; + + /** + * The weblogic domain + */ + private String weblogicDomainName; /** * The name of the weblogic server - used to select the server's directory in the @@ -104,13 +115,54 @@ public class WLRun extends Task { /** * The file containing the weblogic properties for this server. */ - private String weblogicPropertiesFile = "weblogic.properties"; + private String weblogicPropertiesFile = null; /** * additional args to pass to the spawned jvm */ private String additionalJvmArgs = ""; + + /** + * The location of the BEA Home under which this server is run. + * WL6 only + */ + private File beaHome = null; + + /** + * The management username + */ + private String managementUsername = "system"; + /** + * The management password + */ + private String managementPassword = null; + + /** + * The provate key password - used for SSL + */ + private String pkPassword = null; + + /** + * Add the classpath for the user classes + */ + public Path createClasspath() { + if (classpath == null) { + classpath = new Path(project); + } + return classpath.createPath(); + } + + /** + * Get the classpath to the weblogic classpaths + */ + public Path createWLClasspath() { + if (weblogicClasspath == null) { + weblogicClasspath = new Path(project); + } + return weblogicClasspath.createPath(); + } + /** * Do the work. * @@ -130,9 +182,83 @@ public class WLRun extends Task { throw new BuildException("weblogic home directory " + weblogicSystemHome.getPath() + " is not valid"); } - - File propertiesFile = new File(weblogicSystemHome, weblogicPropertiesFile); + + if (beaHome != null) { + executeWLS6(); + } + else { + executeWLS(); + } + } + + private void executeWLS6() { + + if (!beaHome.isDirectory()) { + throw new BuildException("BEA home " + beaHome.getPath() + + " is not valid"); + } + + File securityPolicyFile = null; + if (securityPolicy == null) { + securityPolicyFile = new File(weblogicSystemHome, DEFAULT_WL60_POLICY_FILE); + } + else { + securityPolicyFile = new File(weblogicSystemHome, securityPolicy); + } + + File configFile = new File(weblogicSystemHome, "config/" + weblogicDomainName + "/config.xml"); + if (!configFile.exists()) { + throw new BuildException("Server config file " + configFile + " not found."); + } + + if (managementPassword == null) { + throw new BuildException("You must supply a management password to start the server"); + } + + Java weblogicServer = (Java)project.createTask("java"); + weblogicServer.setTaskName(getTaskName()); + weblogicServer.setFork(true); + weblogicServer.setDir(weblogicSystemHome); + weblogicServer.setClassname(weblogicMainClass); + + String jvmArgs = additionalJvmArgs; + + jvmArgs += " -Dweblogic.Domain=" + weblogicDomainName; + jvmArgs += " -Dweblogic.Name=" + weblogicSystemName; + jvmArgs += " -Dweblogic.system.home=" + weblogicSystemHome; + + jvmArgs += " -Dbea.home=" + beaHome; + jvmArgs += " -Djava.security.policy==" + securityPolicyFile; + + jvmArgs += " -Dweblogic.management.username=" + managementUsername; + jvmArgs += " -Dweblogic.management.password=" + managementPassword; + if (pkPassword != null) { + jvmArgs += " -Dweblogic.pkpassword=" + pkPassword; + } + + + weblogicServer.createJvmarg().setLine(jvmArgs); + weblogicServer.createArg().setLine(additionalArgs); + + if (classpath != null) { + weblogicServer.setClasspath(classpath); + } + + if (weblogicServer.executeJava() != 0) { + throw new BuildException("Execution of weblogic server failed"); + } + } + + private void executeWLS() { + + File propertiesFile = null; + if (weblogicPropertiesFile == null) { + propertiesFile = new File(weblogicSystemHome, DEFAULT_PROPERTIES_FILE); + } + else { + propertiesFile = new File(weblogicSystemHome, weblogicPropertiesFile); + } if (!propertiesFile.exists()) { throw new BuildException("Properties file " + weblogicPropertiesFile + " not found in weblogic home " + weblogicSystemHome); @@ -140,7 +266,7 @@ public class WLRun extends Task { File securityPolicyFile = null; if (securityPolicy == null) { - securityPolicyFile = new File(weblogicSystemHome, defaultPolicyFile); + securityPolicyFile = new File(weblogicSystemHome, DEFAULT_WL51_POLICY_FILE); } else { securityPolicyFile = new File(weblogicSystemHome, securityPolicy); @@ -170,7 +296,9 @@ public class WLRun extends Task { weblogicServer.createJvmarg().setLine(jvmArgs); weblogicServer.createArg().setLine(additionalArgs); - weblogicServer.setClasspath(classpath); + if (classpath != null) { + weblogicServer.setClasspath(classpath); + } if (weblogicServer.executeJava() != 0) { throw new BuildException("Execution of weblogic server failed"); } @@ -178,9 +306,9 @@ public class WLRun extends Task { /** - * Set the classpath to be used for this compilation. + * Set the classpath to be used for this execution. * - * @param s the classpath to use when executing the weblogic task. + * @param s the classpath to use when executing the weblogic server. */ public void setClasspath(Path classpath) { this.classpath = classpath; @@ -212,8 +340,18 @@ public class WLRun extends Task { * @param weblogicHome the home directory of weblogic. * */ - public void setHome(String weblogicHome) { - weblogicSystemHome = new File(weblogicHome); + public void setHome(File weblogicHome) { + weblogicSystemHome = weblogicHome; + } + + /** + * The location of the BEA Home. + * + * @param beaHome the BEA Home directory. + * + */ + public void setBEAHome(File beaHome) { + this.beaHome = beaHome; } /** @@ -225,6 +363,15 @@ public class WLRun extends Task { this.weblogicSystemName = serverName; } + /** + * Set the Domain to run in + * + * @param domain the domain + */ + public void setDomain(String domain) { + this.weblogicDomainName = domain; + } + /** * Set the properties file to use. * @@ -244,9 +391,38 @@ public class WLRun extends Task { this.additionalJvmArgs = args; } + /** + * Set the management username to run the server + * + * @param username the management username of the server. + */ + public void setUsername(String username) { + this.managementUsername = username; + } + + + /** + * Set the management password of the server + * + * @param password the management pasword of the server. + */ + public void setPassword(String password) { + this.managementPassword = password; + } + + /** + * Set the private key password so the server can decrypt the SSL private key file. + * + * @param pkpassword the private key password, + */ + public void setPKPassword(String pkpassword) { + this.pkPassword = pkpassword; + } + public void setArgs(String args) { additionalArgs = args; } + public void setWeblogicMainClass(String c) { weblogicMainClass = c; diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WLStop.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WLStop.java index a0c3e19fa..9db3ee6cc 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WLStop.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WLStop.java @@ -94,6 +94,12 @@ public class WLStop extends Task { */ private int delay = 0; + /** + * The location of the BEA Home under which this server is run. + * WL6 only + */ + private File beaHome = null; + /** * Do the work. * @@ -116,7 +122,17 @@ public class WLStop extends Task { Java weblogicAdmin = (Java)project.createTask("java"); weblogicAdmin.setFork(true); weblogicAdmin.setClassname("weblogic.Admin"); - String args = serverURL + " SHUTDOWN " + username + " " + password + " " + delay; + String args; + + if (beaHome == null) { + args = serverURL + " SHUTDOWN " + username + " " + password + " " + delay; + } + else { + args = " -url " + serverURL + + " -username " + username + + " -password " + password + + " SHUTDOWN " + " " + delay; + } weblogicAdmin.setArgs(args); weblogicAdmin.setClasspath(new Path(project, execClassPath)); @@ -168,4 +184,15 @@ public class WLStop extends Task { public void setDelay(String s) { delay = Integer.parseInt(s); } + + /** + * The location of the BEA Home. + * + * @param beaHome the BEA Home directory. + * + */ + public void setBEAHome(File beaHome) { + this.beaHome = beaHome; + } + }