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 (containerSet == null || containerSet.getCargos() == null)
{
log("No cargo configurations specified, tests will run locally",
Project.MSG_VERBOSE);
super.execute();
}
else
{
CargoElement[] cargoElements = this.containerSet.getCargos();
Variable contextUrl = new Variable();
contextUrl.setKey("cactus.contextURL");
addSysproperty(contextUrl);
for (int i = 0; i < cargoElements.length; i++)
{
CargoElement element = (CargoElement) cargoElements[i];
Container container = element.getCargoContainer();
ContainerWrapper wrapper = new ContainerWrapper(container);
wrapper.setLogger(new AntLogger(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);
}
// 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.
wrapper.setSystemProperties(this.systemProperties);
// Add extra classpath entries
if (containerClasspath != null)
{
wrapper.setContainerClasspath(this.containerClasspath
.list());
}
if (wrapper.isEnabled())
{
wrapper.init();
log("--------------------------------------------------"
+ "---------------", Project.MSG_INFO);
log("Running tests against " + wrapper.getName()
+ " @ " + wrapper.getBaseURL(),
Project.MSG_INFO);
log("--------------------------------------------------"
+ "---------------", Project.MSG_INFO);
contextUrl.setValue(wrapper.getBaseURL() + "/"
+ thisDeployable.getTestContext());
executeInContainer(wrapper, thisDeployable);
}
}
}
}