source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/GenericHotDeploymentTool.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.6 KB
Line 
1/*
2 * Copyright 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 */
17
18package org.apache.tools.ant.taskdefs.optional.j2ee;
19
20import org.apache.tools.ant.BuildException;
21import org.apache.tools.ant.taskdefs.Java;
22import org.apache.tools.ant.types.Commandline;
23
24/**
25 * A generic tool for J2EE server hot deployment.
26 * <p>The simple implementation spawns a JVM with the supplied
27 * class name, jvm args, and arguments.
28 *
29 *
30 * @see org.apache.tools.ant.taskdefs.optional.j2ee.HotDeploymentTool
31 * @see org.apache.tools.ant.taskdefs.optional.j2ee.AbstractHotDeploymentTool
32 * @see org.apache.tools.ant.taskdefs.optional.j2ee.ServerDeploy
33 */
34public class GenericHotDeploymentTool extends AbstractHotDeploymentTool {
35 /** A Java task used to run the deployment tool **/
36 private Java java;
37
38 /** The fully qualified class name of the deployment tool **/
39 private String className;
40
41 /** List of valid actions **/
42 private static final String[] VALID_ACTIONS = {ACTION_DEPLOY};
43
44 /**
45 * Add a nested argument element to hand to the deployment tool; optional.
46 * @return A Commandline.Argument object representing the
47 * command line argument being passed when the deployment
48 * tool is run. IE: "-user=mark", "-password=venture"...
49 */
50 public Commandline.Argument createArg() {
51 return java.createArg();
52 }
53
54 /**
55 * Add a nested argment element to hand to the JVM running the
56 * deployment tool.
57 * Creates a nested arg element.
58 * @return A Commandline.Argument object representing the
59 * JVM command line argument being passed when the deployment
60 * tool is run. IE: "-ms64m", "-mx128m"...
61 */
62 public Commandline.Argument createJvmarg() {
63 return java.createJvmarg();
64 }
65
66 /**
67 * Determines if the "action" attribute defines a valid action.
68 * <p>Subclasses should determine if the action passed in is
69 * supported by the vendor's deployment tool.
70 * For this generic implementation, the only valid action is "deploy"
71 * @return true if the "action" attribute is valid, false if not.
72 */
73 protected boolean isActionValid() {
74 return (getTask().getAction().equals(VALID_ACTIONS[0]));
75 }
76
77 /**
78 * Sets the parent task.
79 * @param task An ServerDeploy object representing the parent task.
80 * @ant.attribute ignored="true"
81 */
82 public void setTask(ServerDeploy task) {
83 super.setTask(task);
84 java = (Java) task.getProject().createTask("java");
85 }
86
87 /**
88 * Perform the actual deployment.
89 * For this generic implementation, a JVM is spawned using the
90 * supplied classpath, classname, JVM args, and command line arguments.
91 * @exception org.apache.tools.ant.BuildException if the attributes are invalid or incomplete.
92 */
93 public void deploy() throws BuildException {
94 java.setClassname(className);
95 java.setClasspath(getClasspath());
96 java.setFork(true);
97 java.setFailonerror(true);
98 java.execute();
99 }
100
101 /**
102 * Validates the passed in attributes.
103 * Ensures the className and arguments attribute have been set.
104 * @exception org.apache.tools.ant.BuildException if the attributes are invalid or incomplete.
105 */
106 public void validateAttributes() throws BuildException {
107 super.validateAttributes();
108
109 if (className == null) {
110 throw new BuildException("The classname attribute must be set");
111 }
112 }
113
114 /**
115 * The name of the class to execute to perfom
116 * deployment; required.
117 * Example: "com.foobar.tools.deploy.DeployTool"
118 * @param className The fully qualified class name of the class
119 * to perform deployment.
120 */
121 public void setClassName(String className) {
122 this.className = className;
123 }
124
125 /**
126 *
127 */
128 public Java getJava() {
129 return java;
130 }
131
132 public String getClassName() {
133 return className;
134 }
135}
Note: See TracBrowser for help on using the repository browser.