|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| AbstractResinTask.java | 21.9% | 38.7% | 47.8% | 35.9% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* ========================================================================
|
|
| 3 |
*
|
|
| 4 |
* Copyright 2004 The Apache Software Foundation.
|
|
| 5 |
*
|
|
| 6 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
| 7 |
* you may not use this file except in compliance with the License.
|
|
| 8 |
* You may obtain a copy of the License at
|
|
| 9 |
*
|
|
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
| 11 |
*
|
|
| 12 |
* Unless required by applicable law or agreed to in writing, software
|
|
| 13 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
| 14 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
| 15 |
* See the License for the specific language governing permissions and
|
|
| 16 |
* limitations under the License.
|
|
| 17 |
*
|
|
| 18 |
* ========================================================================
|
|
| 19 |
*/
|
|
| 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 |
/**
|
|
| 34 |
* Task to start/stop a Resin instance.
|
|
| 35 |
*
|
|
| 36 |
* @since Cactus 1.7
|
|
| 37 |
* @version $Id: AbstractResinTask.java 239035 2004-08-15 15:02:27Z vmassol $
|
|
| 38 |
*/
|
|
| 39 |
public abstract class AbstractResinTask extends Task |
|
| 40 |
{
|
|
| 41 |
/**
|
|
| 42 |
* The mandatory Resin installation directory.
|
|
| 43 |
*/
|
|
| 44 |
private File dir;
|
|
| 45 |
|
|
| 46 |
/**
|
|
| 47 |
* The action that will be executed by this task
|
|
| 48 |
* @see #setAction(String)
|
|
| 49 |
*/
|
|
| 50 |
private String action;
|
|
| 51 |
|
|
| 52 |
/**
|
|
| 53 |
* The archive that contains the enterprise application that will be
|
|
| 54 |
* deployed
|
|
| 55 |
*/
|
|
| 56 |
private File earFile;
|
|
| 57 |
|
|
| 58 |
/**
|
|
| 59 |
* The archive that contains the web-app that will be deployed.
|
|
| 60 |
*/
|
|
| 61 |
private File warFile;
|
|
| 62 |
|
|
| 63 |
/**
|
|
| 64 |
* URL used to verify if the container is started.
|
|
| 65 |
*/
|
|
| 66 |
private URL testURL;
|
|
| 67 |
|
|
| 68 |
/**
|
|
| 69 |
* A user-specific resin.conf configuration file. If this variable is not
|
|
| 70 |
* set, the default configuration file from the JAR resources will be used.
|
|
| 71 |
*/
|
|
| 72 |
private File resinConf;
|
|
| 73 |
|
|
| 74 |
/**
|
|
| 75 |
* The port to which the container should be bound.
|
|
| 76 |
*/
|
|
| 77 |
private int port = 8080; |
|
| 78 |
|
|
| 79 |
/**
|
|
| 80 |
* The temporary directory from which the container will be started.
|
|
| 81 |
*/
|
|
| 82 |
private File tmpDir;
|
|
| 83 |
|
|
| 84 |
/**
|
|
| 85 |
* The file to which output of the container should be written.
|
|
| 86 |
*/
|
|
| 87 |
private File output;
|
|
| 88 |
|
|
| 89 |
/**
|
|
| 90 |
* Whether output of the container should be appended to an existing file,
|
|
| 91 |
* or the existing file should be truncated.
|
|
| 92 |
*/
|
|
| 93 |
private boolean append; |
|
| 94 |
|
|
| 95 |
/**
|
|
| 96 |
* Additional classpath entries for the classpath that will be used to
|
|
| 97 |
* start the containers.
|
|
| 98 |
*/
|
|
| 99 |
private Path containerClasspath;
|
|
| 100 |
|
|
| 101 |
/**
|
|
| 102 |
* Sets the Resin installation directory.
|
|
| 103 |
*
|
|
| 104 |
* @param theDir The directory to set
|
|
| 105 |
*/
|
|
| 106 | 0 |
public final void setDir(File theDir) |
| 107 |
{
|
|
| 108 | 0 |
this.dir = theDir;
|
| 109 |
} |
|
| 110 |
|
|
| 111 |
/**
|
|
| 112 |
* Sets the action to execute (either "start" or "stop").
|
|
| 113 |
*
|
|
| 114 |
* @param theAction the action that will be executed by this task
|
|
| 115 |
*/
|
|
| 116 | 0 |
public void setAction(String theAction) |
| 117 |
{
|
|
| 118 | 0 |
this.action = theAction;
|
| 119 |
} |
|
| 120 |
|
|
| 121 |
/**
|
|
| 122 |
* Sets a web application archive to deploy in the container.
|
|
| 123 |
*
|
|
| 124 |
* @param theWarFile The WAR file to deploy
|
|
| 125 |
*/
|
|
| 126 | 0 |
public final void setWarFile(File theWarFile) |
| 127 |
{
|
|
| 128 | 0 |
if (getEarFile() != null) |
| 129 |
{
|
|
| 130 | 0 |
throw new BuildException( |
| 131 |
"You may only specify one of [earfile] and [warfile]");
|
|
| 132 |
} |
|
| 133 | 0 |
this.warFile = theWarFile;
|
| 134 |
} |
|
| 135 |
|
|
| 136 |
/**
|
|
| 137 |
* Sets an enterprise application aarchive to deploy.
|
|
| 138 |
*
|
|
| 139 |
* @param theEarFile The EAR file to deploy
|
|
| 140 |
*/
|
|
| 141 | 0 |
public final void setEarFile(File theEarFile) |
| 142 |
{
|
|
| 143 | 0 |
if (getWarFile() != null) |
| 144 |
{
|
|
| 145 | 0 |
throw new BuildException( |
| 146 |
"You may only specify one of [earfile] and [warfile]");
|
|
| 147 |
} |
|
| 148 | 0 |
this.earFile = theEarFile;
|
| 149 |
} |
|
| 150 |
|
|
| 151 |
/**
|
|
| 152 |
* Sets the URL to call for testing if the server is running.
|
|
| 153 |
*
|
|
| 154 |
* @param theTestURL the test URL to ping
|
|
| 155 |
*/
|
|
| 156 | 0 |
public void setTestURL(URL theTestURL) |
| 157 |
{
|
|
| 158 | 0 |
this.testURL = theTestURL;
|
| 159 |
} |
|
| 160 |
|
|
| 161 |
/**
|
|
| 162 |
* Sets the temporary directory from which the container is run.
|
|
| 163 |
*
|
|
| 164 |
* @param theTmpDir The temporary directory to set
|
|
| 165 |
*/
|
|
| 166 | 0 |
public final void setTmpDir(File theTmpDir) |
| 167 |
{
|
|
| 168 | 0 |
this.tmpDir = theTmpDir;
|
| 169 |
} |
|
| 170 |
|
|
| 171 |
/**
|
|
| 172 |
* Sets the configuration file to use for the test installation of Resin
|
|
| 173 |
*
|
|
| 174 |
* @param theResinConf The resin.conf file
|
|
| 175 |
*/
|
|
| 176 | 0 |
public final void setResinConf(File theResinConf) |
| 177 |
{
|
|
| 178 | 0 |
this.resinConf = theResinConf;
|
| 179 |
} |
|
| 180 |
|
|
| 181 |
/**
|
|
| 182 |
* Sets the port to which the container should listen.
|
|
| 183 |
*
|
|
| 184 |
* @param thePort The port to set
|
|
| 185 |
*/
|
|
| 186 | 0 |
public final void setPort(int thePort) |
| 187 |
{
|
|
| 188 | 0 |
this.port = thePort;
|
| 189 |
} |
|
| 190 |
|
|
| 191 |
/**
|
|
| 192 |
* Sets the file to which output of the container should be written.
|
|
| 193 |
*
|
|
| 194 |
* @param theOutput The output file to set
|
|
| 195 |
*/
|
|
| 196 | 0 |
public final void setOutput(File theOutput) |
| 197 |
{
|
|
| 198 | 0 |
this.output = theOutput;
|
| 199 |
} |
|
| 200 |
|
|
| 201 |
/**
|
|
| 202 |
* Sets whether output of the container should be appended to an existing
|
|
| 203 |
* file, or the existing file should be truncated.
|
|
| 204 |
*
|
|
| 205 |
* @param isAppend Whether output should be appended
|
|
| 206 |
*/
|
|
| 207 | 0 |
public final void setAppend(boolean isAppend) |
| 208 |
{
|
|
| 209 | 0 |
this.append = isAppend;
|
| 210 |
} |
|
| 211 |
|
|
| 212 |
/**
|
|
| 213 |
* Checks if the task is correctly initialized.
|
|
| 214 |
*
|
|
| 215 |
* @param theContainer the Resin container to verify
|
|
| 216 |
*/
|
|
| 217 | 1 |
private void verify(AbstractResinContainer theContainer) |
| 218 |
{
|
|
| 219 | 1 |
theContainer.verify(); |
| 220 |
|
|
| 221 | 0 |
if (getAction() == null) |
| 222 |
{
|
|
| 223 | 0 |
throw new BuildException("You must specify an [action] attribute"); |
| 224 |
} |
|
| 225 |
|
|
| 226 | 0 |
if (!getAction().equalsIgnoreCase("start") |
| 227 |
&& !getAction().equalsIgnoreCase("stop"))
|
|
| 228 |
{
|
|
| 229 | 0 |
throw new BuildException( |
| 230 |
"Valid actions are: [start] and [stop]");
|
|
| 231 |
} |
|
| 232 |
} |
|
| 233 |
|
|
| 234 |
/**
|
|
| 235 |
* @return the instance of a Resin container to start/stop
|
|
| 236 |
*/
|
|
| 237 |
protected abstract AbstractResinContainer getResinContainer();
|
|
| 238 |
|
|
| 239 |
/**
|
|
| 240 |
* Start or stop the container depending on the action asked by the user.
|
|
| 241 |
* When starting the container, also prepare a valid container
|
|
| 242 |
* configuration and optionally deploy a war or ear in it.
|
|
| 243 |
*
|
|
| 244 |
* @see Task#execute()
|
|
| 245 |
*/
|
|
| 246 | 1 |
public void execute() |
| 247 |
{
|
|
| 248 |
// Resin container that prepares, starts and stops a Resin
|
|
| 249 |
// instance.
|
|
| 250 | 1 |
AbstractResinContainer container = getResinContainer(); |
| 251 |
|
|
| 252 |
// Sets the file to be deployed in the container.
|
|
| 253 | 1 |
if (getWarFile() != null) |
| 254 |
{
|
|
| 255 | 0 |
container.setDeployableFile( |
| 256 |
WarParser.parse(getWarFile())); |
|
| 257 |
} |
|
| 258 | 1 |
else if (getEarFile() != null) |
| 259 |
{
|
|
| 260 | 0 |
container.setDeployableFile( |
| 261 |
EarParser.parse(getEarFile())); |
|
| 262 |
} |
|
| 263 |
|
|
| 264 | 1 |
container.setDir(getDir()); |
| 265 | 1 |
container.setAntTaskFactory(new DefaultAntTaskFactory(
|
| 266 |
getProject(), getTaskName(), getLocation(), getOwningTarget())); |
|
| 267 | 1 |
container.setPort(getPort()); |
| 268 |
|
|
| 269 |
// Add specific additional user-defined classpath
|
|
| 270 | 1 |
container.setContainerClasspath(this.containerClasspath);
|
| 271 |
|
|
| 272 | 1 |
if (getResinConf() != null) |
| 273 |
{
|
|
| 274 | 0 |
container.setResinConf(getResinConf()); |
| 275 |
} |
|
| 276 |
|
|
| 277 | 1 |
if (getTmpDir() != null) |
| 278 |
{
|
|
| 279 | 0 |
container.setTmpDir(getTmpDir()); |
| 280 |
} |
|
| 281 |
|
|
| 282 | 1 |
if (getOutput() != null) |
| 283 |
{
|
|
| 284 | 0 |
container.setOutput(getOutput()); |
| 285 |
} |
|
| 286 |
|
|
| 287 | 1 |
if (getAppend())
|
| 288 |
{
|
|
| 289 | 0 |
container.setAppend(getAppend()); |
| 290 |
} |
|
| 291 |
|
|
| 292 |
// Verify that the task is correctly set up.
|
|
| 293 | 1 |
verify(container); |
| 294 |
|
|
| 295 |
// If the user has provided a test URL, we use a ContainerRunner
|
|
| 296 |
// that continuously polls this test URL to verify if the container
|
|
| 297 |
// is started. In that case, this task will only return when the
|
|
| 298 |
// container is up and running. If no test URL has been started
|
|
| 299 |
// we simply start the container and give back the control to the user
|
|
| 300 |
// without waiting for container to be up and running.
|
|
| 301 |
|
|
| 302 | 0 |
ContainerRunner runner = null;
|
| 303 | 0 |
if (getTestURL() != null) |
| 304 |
{
|
|
| 305 | 0 |
runner = new ContainerRunner(container);
|
| 306 | 0 |
runner.setURL(getTestURL()); |
| 307 |
} |
|
| 308 |
|
|
| 309 |
// Decide whether to start or stop the container
|
|
| 310 | 0 |
if (getAction().equalsIgnoreCase("start")) |
| 311 |
{
|
|
| 312 | 0 |
if (getTestURL() != null) |
| 313 |
{
|
|
| 314 | 0 |
runner.startUpContainer(); |
| 315 |
} |
|
| 316 |
else
|
|
| 317 |
{
|
|
| 318 | 0 |
container.startUp(); |
| 319 |
} |
|
| 320 |
} |
|
| 321 | 0 |
else if (getAction().equalsIgnoreCase("stop")) |
| 322 |
{
|
|
| 323 | 0 |
if (getTestURL() != null) |
| 324 |
{
|
|
| 325 | 0 |
runner.shutDownContainer(); |
| 326 |
} |
|
| 327 |
else
|
|
| 328 |
{
|
|
| 329 | 0 |
container.shutDown(); |
| 330 |
} |
|
| 331 |
} |
|
| 332 |
} |
|
| 333 |
|
|
| 334 |
/**
|
|
| 335 |
* @return the action to execute ("start" or "stop")
|
|
| 336 |
*/
|
|
| 337 | 0 |
protected final String getAction()
|
| 338 |
{
|
|
| 339 | 0 |
return this.action; |
| 340 |
} |
|
| 341 |
|
|
| 342 |
/**
|
|
| 343 |
* @return the directory where Resin is installed
|
|
| 344 |
*/
|
|
| 345 | 1 |
protected final File getDir()
|
| 346 |
{
|
|
| 347 | 1 |
return this.dir; |
| 348 |
} |
|
| 349 |
|
|
| 350 |
/**
|
|
| 351 |
* @return the test URL to ping to verify if the container is started
|
|
| 352 |
*/
|
|
| 353 | 0 |
protected final URL getTestURL()
|
| 354 |
{
|
|
| 355 | 0 |
return this.testURL; |
| 356 |
} |
|
| 357 |
|
|
| 358 |
/**
|
|
| 359 |
* @return the port to use to start the container
|
|
| 360 |
*/
|
|
| 361 | 1 |
protected final int getPort() |
| 362 |
{
|
|
| 363 | 1 |
return this.port; |
| 364 |
} |
|
| 365 |
|
|
| 366 |
/**
|
|
| 367 |
* @return the configuration file to use for the test installation of Resin
|
|
| 368 |
*/
|
|
| 369 | 1 |
protected final File getResinConf()
|
| 370 |
{
|
|
| 371 | 1 |
return this.resinConf; |
| 372 |
} |
|
| 373 |
|
|
| 374 |
/**
|
|
| 375 |
* @return the WAR file to deploy or null if none
|
|
| 376 |
*/
|
|
| 377 | 1 |
protected final File getWarFile()
|
| 378 |
{
|
|
| 379 | 1 |
return this.warFile; |
| 380 |
} |
|
| 381 |
|
|
| 382 |
/**
|
|
| 383 |
* @return the EAR file to deploy or null if none
|
|
| 384 |
*/
|
|
| 385 | 1 |
protected final File getEarFile()
|
| 386 |
{
|
|
| 387 | 1 |
return this.earFile; |
| 388 |
} |
|
| 389 |
|
|
| 390 |
/**
|
|
| 391 |
* @return the temporary directory from which the container is run
|
|
| 392 |
*/
|
|
| 393 | 1 |
protected final File getTmpDir()
|
| 394 |
{
|
|
| 395 | 1 |
return this.tmpDir; |
| 396 |
} |
|
| 397 |
|
|
| 398 |
/**
|
|
| 399 |
* @return the file to which output of the container should be written
|
|
| 400 |
*/
|
|
| 401 | 1 |
protected final File getOutput()
|
| 402 |
{
|
|
| 403 | 1 |
return this.output; |
| 404 |
} |
|
| 405 |
|
|
| 406 |
/**
|
|
| 407 |
* @return whether output of the container should be appended to an
|
|
| 408 |
* existing file, or the existing file should be truncated
|
|
| 409 |
*/
|
|
| 410 | 1 |
protected final boolean getAppend() |
| 411 |
{
|
|
| 412 | 1 |
return this.append; |
| 413 |
} |
|
| 414 |
|
|
| 415 |
/**
|
|
| 416 |
* Adds container classpath to the classpath that will be used for starting
|
|
| 417 |
* the container.
|
|
| 418 |
*
|
|
| 419 |
* @return reference to the classpath
|
|
| 420 |
*/
|
|
| 421 | 1 |
public Path createContainerClasspath()
|
| 422 |
{
|
|
| 423 | 1 |
if (this.containerClasspath == null) |
| 424 |
{
|
|
| 425 | 1 |
this.containerClasspath = new Path(this.project); |
| 426 |
} |
|
| 427 |
|
|
| 428 | 1 |
return this.containerClasspath.createPath(); |
| 429 |
} |
|
| 430 |
} |
|
| 431 |
|
|
||||||||||