1 20 package org.apache.cactus.integration.ant.container.resin; 21 22 import java.io.File ; 23 import java.net.URL ; 24 25 import org.apache.cactus.integration.ant.container.ContainerRunner; 26 import org.apache.cactus.integration.ant.deployment.EarParser; 27 import org.apache.cactus.integration.ant.deployment.WarParser; 28 import org.apache.cactus.integration.ant.util.DefaultAntTaskFactory; 29 import org.apache.tools.ant.BuildException; 30 import org.apache.tools.ant.Task; 31 import org.apache.tools.ant.types.Path; 32 33 39 public abstract class AbstractResinTask extends Task 40 { 41 44 private File dir; 45 46 50 private String action; 51 52 56 private File earFile; 57 58 61 private File warFile; 62 63 66 private URL testURL; 67 68 72 private File resinConf; 73 74 77 private int port = 8080; 78 79 82 private File tmpDir; 83 84 87 private File output; 88 89 93 private boolean append; 94 95 99 private Path containerClasspath; 100 101 106 public final void setDir(File theDir) 107 { 108 this.dir = theDir; 109 } 110 111 116 public void setAction(String theAction) 117 { 118 this.action = theAction; 119 } 120 121 126 public final void setWarFile(File theWarFile) 127 { 128 if (getEarFile() != null) 129 { 130 throw new BuildException( 131 "You may only specify one of [earfile] and [warfile]"); 132 } 133 this.warFile = theWarFile; 134 } 135 136 141 public final void setEarFile(File theEarFile) 142 { 143 if (getWarFile() != null) 144 { 145 throw new BuildException( 146 "You may only specify one of [earfile] and [warfile]"); 147 } 148 this.earFile = theEarFile; 149 } 150 151 156 public void setTestURL(URL theTestURL) 157 { 158 this.testURL = theTestURL; 159 } 160 161 166 public final void setTmpDir(File theTmpDir) 167 { 168 this.tmpDir = theTmpDir; 169 } 170 171 176 public final void setResinConf(File theResinConf) 177 { 178 this.resinConf = theResinConf; 179 } 180 181 186 public final void setPort(int thePort) 187 { 188 this.port = thePort; 189 } 190 191 196 public final void setOutput(File theOutput) 197 { 198 this.output = theOutput; 199 } 200 201 207 public final void setAppend(boolean isAppend) 208 { 209 this.append = isAppend; 210 } 211 212 217 private void verify(AbstractResinContainer theContainer) 218 { 219 theContainer.verify(); 220 221 if (getAction() == null) 222 { 223 throw new BuildException("You must specify an [action] attribute"); 224 } 225 226 if (!getAction().equalsIgnoreCase("start") 227 && !getAction().equalsIgnoreCase("stop")) 228 { 229 throw new BuildException( 230 "Valid actions are: [start] and [stop]"); 231 } 232 } 233 234 237 protected abstract AbstractResinContainer getResinContainer(); 238 239 246 public void execute() 247 { 248 AbstractResinContainer container = getResinContainer(); 251 252 if (getWarFile() != null) 254 { 255 container.setDeployableFile( 256 WarParser.parse(getWarFile())); 257 } 258 else if (getEarFile() != null) 259 { 260 container.setDeployableFile( 261 EarParser.parse(getEarFile())); 262 } 263 264 container.setDir(getDir()); 265 container.setAntTaskFactory(new DefaultAntTaskFactory( 266 getProject(), getTaskName(), getLocation(), getOwningTarget())); 267 container.setPort(getPort()); 268 269 container.setContainerClasspath(this.containerClasspath); 271 272 if (getResinConf() != null) 273 { 274 container.setResinConf(getResinConf()); 275 } 276 277 if (getTmpDir() != null) 278 { 279 container.setTmpDir(getTmpDir()); 280 } 281 282 if (getOutput() != null) 283 { 284 container.setOutput(getOutput()); 285 } 286 287 if (getAppend()) 288 { 289 container.setAppend(getAppend()); 290 } 291 292 verify(container); 294 295 302 ContainerRunner runner = null; 303 if (getTestURL() != null) 304 { 305 runner = new ContainerRunner(container); 306 runner.setURL(getTestURL()); 307 } 308 309 if (getAction().equalsIgnoreCase("start")) 311 { 312 if (getTestURL() != null) 313 { 314 runner.startUpContainer(); 315 } 316 else 317 { 318 container.startUp(); 319 } 320 } 321 else if (getAction().equalsIgnoreCase("stop")) 322 { 323 if (getTestURL() != null) 324 { 325 runner.shutDownContainer(); 326 } 327 else 328 { 329 container.shutDown(); 330 } 331 } 332 } 333 334 337 protected final String getAction() 338 { 339 return this.action; 340 } 341 342 345 protected final File getDir() 346 { 347 return this.dir; 348 } 349 350 353 protected final URL getTestURL() 354 { 355 return this.testURL; 356 } 357 358 361 protected final int getPort() 362 { 363 return this.port; 364 } 365 366 369 protected final File getResinConf() 370 { 371 return this.resinConf; 372 } 373 374 377 protected final File getWarFile() 378 { 379 return this.warFile; 380 } 381 382 385 protected final File getEarFile() 386 { 387 return this.earFile; 388 } 389 390 393 protected final File getTmpDir() 394 { 395 return this.tmpDir; 396 } 397 398 401 protected final File getOutput() 402 { 403 return this.output; 404 } 405 406 410 protected final boolean getAppend() 411 { 412 return this.append; 413 } 414 415 421 public Path createContainerClasspath() 422 { 423 if (this.containerClasspath == null) 424 { 425 this.containerClasspath = new Path(this.project); 426 } 427 428 return this.containerClasspath.createPath(); 429 } 430 } 431 | Popular Tags |