source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WLStop.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 4.7 KB
Line 
1/*
2 * Copyright 2000-2002,2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17package org.apache.tools.ant.taskdefs.optional.ejb;
18
19
20import java.io.File;
21import org.apache.tools.ant.BuildException;
22import org.apache.tools.ant.Task;
23import org.apache.tools.ant.taskdefs.Java;
24import org.apache.tools.ant.types.Path;
25
26/**
27 * Shuts down a WebLogic server.
28 * To shut down an instance you must supply both a username and
29 * a password.
30 *
31 */
32public class WLStop extends Task {
33 /**
34 * The classpath to be used. It must contains the weblogic.Admin class.
35 */
36 private Path classpath;
37
38 /**
39 * The weblogic username to use to request the shutdown.
40 */
41 private String username;
42
43 /**
44 * The password to use to shutdown the weblogic server.
45 */
46 private String password;
47
48 /**
49 * The URL which the weblogic server is listening on.
50 */
51 private String serverURL;
52
53 /**
54 * The delay (in seconds) to wait before shutting down.
55 */
56 private int delay = 0;
57
58 /**
59 * The location of the BEA Home under which this server is run.
60 * WL6 only
61 */
62 private File beaHome = null;
63
64 /**
65 * Do the work.
66 *
67 * The work is actually done by creating a separate JVM to run the weblogic admin task
68 * This approach allows the classpath of the helper task to be set.
69 *
70 * @exception BuildException if someting goes wrong with the build
71 */
72 public void execute() throws BuildException {
73 if (username == null || password == null) {
74 throw new BuildException("weblogic username and password must both be set");
75 }
76
77 if (serverURL == null) {
78 throw new BuildException("The url of the weblogic server must be provided.");
79 }
80
81 Java weblogicAdmin = (Java) getProject().createTask("java");
82 weblogicAdmin.setFork(true);
83 weblogicAdmin.setClassname("weblogic.Admin");
84 String args;
85
86 if (beaHome == null) {
87 args = serverURL + " SHUTDOWN " + username + " " + password + " " + delay;
88 } else {
89 args = " -url " + serverURL
90 + " -username " + username
91 + " -password " + password
92 + " SHUTDOWN " + " " + delay;
93 }
94
95 weblogicAdmin.createArg().setLine(args);
96 weblogicAdmin.setClasspath(classpath);
97 weblogicAdmin.execute();
98 }
99
100 /**
101 * The classpath to be used with the Java Virtual Machine that runs the Weblogic
102 * Shutdown command;
103 *
104 * @param path the classpath to use when executing the weblogic admin task.
105 */
106 public void setClasspath(Path path) {
107 this.classpath = path;
108 }
109
110 /**
111 * The classpath to be used with the Java Virtual Machine that runs the Weblogic
112 * Shutdown command;
113 */
114 public Path createClasspath() {
115 if (classpath == null) {
116 classpath = new Path(getProject());
117 }
118 return classpath.createPath();
119 }
120
121 /**
122 * The username of the account which will be used to shutdown the server;
123 * required.
124 *
125 * @param s the username.
126 */
127 public void setUser(String s) {
128 this.username = s;
129 }
130
131 /**
132 * The password for the account specified in the
133 * user parameter; required
134 *
135 * @param s the password.
136 */
137 public void setPassword(String s) {
138 this.password = s;
139 }
140
141 /**
142 * Set the URL to which the weblogic server is listening
143 * for T3 connections; required.
144 *
145 * @param s the url.
146 */
147 public void setUrl(String s) {
148 this.serverURL = s;
149 }
150
151
152 /**
153 * Set the delay (in seconds) before shutting down the server;
154 * optional.
155 *
156 * @param s the selay.
157 */
158 public void setDelay(String s) {
159 delay = Integer.parseInt(s);
160 }
161
162 /**
163 * The location of the BEA Home; implicitly
164 * selects Weblogic 6.0 shutdown; optional.
165 *
166 * @param beaHome the BEA Home directory.
167 *
168 */
169 public void setBEAHome(File beaHome) {
170 this.beaHome = beaHome;
171 }
172
173}
Note: See TracBrowser for help on using the repository browser.