1 18 19 package org.apache.tools.ant.taskdefs.optional.j2ee; 20 21 import org.apache.tools.ant.BuildException; 22 import org.apache.tools.ant.taskdefs.Java; 23 24 37 public class WebLogicHotDeploymentTool extends AbstractHotDeploymentTool 38 implements HotDeploymentTool { 39 40 private static final String WEBLOGIC_DEPLOY_CLASS_NAME = "weblogic.deploy"; 41 42 43 private static final String [] VALID_ACTIONS 44 = {ACTION_DELETE, ACTION_DEPLOY, ACTION_LIST, ACTION_UNDEPLOY, ACTION_UPDATE}; 45 46 47 private boolean debug; 48 49 50 private String application; 51 52 53 private String component; 54 55 61 public void deploy() { 62 Java java = new Java(getTask()); 63 java.setFork(true); 64 java.setFailonerror(true); 65 java.setClasspath(getClasspath()); 66 67 java.setClassname(WEBLOGIC_DEPLOY_CLASS_NAME); 68 java.createArg().setLine(getArguments()); 69 java.execute(); 70 } 71 72 81 public void validateAttributes() throws BuildException { 82 super.validateAttributes(); 83 84 String action = getTask().getAction(); 85 86 if ((getPassword() == null)) { 88 throw new BuildException("The password attribute must be set."); 89 } 90 91 if ((action.equals(ACTION_DEPLOY) || action.equals(ACTION_UPDATE)) 93 && application == null) { 94 throw new BuildException("The application attribute must be set " 95 + "if action = " + action); 96 } 97 98 if ((action.equals(ACTION_DEPLOY) || action.equals(ACTION_UPDATE)) 100 && getTask().getSource() == null) { 101 throw new BuildException("The source attribute must be set if " 102 + "action = " + action); 103 } 104 105 if ((action.equals(ACTION_DELETE) || action.equals(ACTION_UNDEPLOY)) 107 && application == null) { 108 throw new BuildException("The application attribute must be set if " 109 + "action = " + action); 110 } 111 } 112 113 119 public String getArguments() throws BuildException { 120 String action = getTask().getAction(); 121 String args = null; 122 123 if (action.equals(ACTION_DEPLOY) || action.equals(ACTION_UPDATE)) { 124 args = buildDeployArgs(); 125 } else if (action.equals(ACTION_DELETE) || action.equals(ACTION_UNDEPLOY)) { 126 args = buildUndeployArgs(); 127 } else if (action.equals(ACTION_LIST)) { 128 args = buildListArgs(); 129 } 130 131 return args; 132 } 133 134 139 protected boolean isActionValid() { 140 boolean valid = false; 141 142 String action = getTask().getAction(); 143 144 for (int i = 0; i < VALID_ACTIONS.length; i++) { 145 if (action.equals(VALID_ACTIONS[i])) { 146 valid = true; 147 break; 148 } 149 } 150 151 return valid; 152 } 153 154 160 protected StringBuffer buildArgsPrefix() { 161 ServerDeploy task = getTask(); 162 return new StringBuffer (1024) 165 .append((getServer() != null) 166 ? "-url " + getServer() 167 : "") 168 .append(" ") 169 .append(debug ? "-debug " : "") 170 .append((getUserName() != null) 171 ? "-username " + getUserName() 172 : "") 173 .append(" ") 174 .append(task.getAction()).append(" ") 175 .append(getPassword()).append(" "); 176 } 177 178 183 protected String buildDeployArgs() { 184 String args = buildArgsPrefix() 185 .append(application).append(" ") 186 .append(getTask().getSource()) 187 .toString(); 188 189 if (component != null) { 190 args = "-component " + component + " " + args; 191 } 192 193 return args; 194 } 195 196 201 protected String buildUndeployArgs() { 202 return buildArgsPrefix() 203 .append(application).append(" ") 204 .toString(); 205 } 206 207 211 protected String buildListArgs() { 212 return buildArgsPrefix() 213 .toString(); 214 } 215 216 221 public void setDebug(boolean debug) { 222 this.debug = debug; 223 } 224 225 230 public void setApplication(String application) { 231 this.application = application; 232 } 233 234 243 public void setComponent(String component) { 244 this.component = component; 245 } 246 } 247 | Popular Tags |