throw new BuildException("You must specify either the [warfile] or "
+ "the [earfile] attribute but not both");
}
// Parse deployment descriptors for WAR or EAR files
DeployableFile deployableFile;
if (this.warFile != null)
{
deployableFile = WarParser.parse(this.warFile);
}
else
{
deployableFile = EarParser.parse(this.earFile);
}
addRedirectorNameProperties(deployableFile);
if (this.containerSet == null)
{
log("No containers specified, tests will run locally",
Project.MSG_VERBOSE);
super.execute();
}
else
{
Container[] containers = this.containerSet.getContainers();
Variable contextUrl = new Variable();
contextUrl.setKey("cactus.contextURL");
addSysproperty(contextUrl);
AntTaskFactory antTaskFactory = new DefaultAntTaskFactory(
getProject(), getTaskName(), getLocation(), getOwningTarget());
for (int i = 0; i < containers.length; i++)
{
containers[i].setAntTaskFactory(antTaskFactory);
containers[i].setLog(new AntLog(this));
// Clone the DeployableFile instance as each container can
// override default deployment properties (e.g. port, context
// root, etc).
DeployableFile thisDeployable = null;
try
{
thisDeployable = (DeployableFile) deployableFile.clone();
}
catch (CloneNotSupportedException e)
{
throw new BuildException(e);
}
containers[i].setDeployableFile(thisDeployable);
// Allow the container to override the default test context.
// This is to support container extensions to the web.xml file.
// Most containers allow defining the root context in these
// extensions.
if (containers[i].getTestContext() != null)
{
thisDeployable.setTestContext(
containers[i].getTestContext());
}
containers[i].setSystemProperties(
(Variable[]) this.systemProperties.toArray(
new Variable[0]));
// Add extra classpath entries
containers[i].setContainerClasspath(this.containerClasspath);
if (containers[i].isEnabled())
{
containers[i].init();
log("--------------------------------------------------"
+ "---------------", Project.MSG_INFO);
log("Running tests against " + containers[i].getName()
+ " @ " + containers[i].getBaseURL(),
Project.MSG_INFO);
log("--------------------------------------------------"
+ "---------------", Project.MSG_INFO);
contextUrl.setValue(containers[i].getBaseURL() + "/"
+ thisDeployable.getTestContext());
executeInContainer(containers[i], thisDeployable);
}
}
}
}