{
getLog().info("Analyzing war: " + this.srcFile.getAbsolutePath());
}
WebXml webXml = null;
MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(warArchiver);
archiver.setOutputFile(destFile);
File tmpWebXml = null;
File tempLocation = null;
try
{
if (srcFile != null)
{
webXml = getOriginalWebXml();
if (webXml == null)
{
if (this.version == null)
{
throw new MojoExecutionException("Your source file "
+ "does not contain a web.xml. Please provide a "
+ "war with a web.xml or specify the [version] "
+ "attribute.");
}
WebXmlVersion webXmlVersion = null;
if (this.version.equals("2.2"))
{
webXmlVersion = WebXmlVersion.V2_2;
}
else if (this.version.equals("2.3"))
{
webXmlVersion = WebXmlVersion.V2_3;
}
else
{
webXmlVersion = WebXmlVersion.V2_4;
}
webXml = WebXmlIo.newWebXml(webXmlVersion);
}
}
else
{
if (this.version == null)
{
throw new MojoExecutionException("You need to specify "
+ "either the [srcFile] or the [version] attribute");
}
else
{
WebXmlVersion webXmlVersion = null;
if (this.version.equals("2.2"))
{
webXmlVersion = WebXmlVersion.V2_2;
}
else if (this.version.equals("2.3"))
{
webXmlVersion = WebXmlVersion.V2_3;
}
else
{
webXmlVersion = WebXmlVersion.V2_4;
}
webXml = WebXmlIo.newWebXml(webXmlVersion);
}
}
tmpWebXml = cactifyWebXml(webXml);
//Add the required libs for Cactus.
addJarWithClass("org.aspectj.lang.JoinPoint",
"AspectJ Runtime");
addJarWithClass("org.apache.cactus."
+ "ServletTestCase", "Cactus Framework");
addJarWithClass("org.apache.commons.logging.Log",
"Commons-Logging");
addJarWithClass("org.apache.commons."
+ "httpclient.HttpClient", "Commons-HttpClient");
addJarWithClass("junit.framework."
+ "TestCase", "JUnit");
tempLocation = createTempFile("cactus", "explode.tmp.dir",
getProject().getBasedir(), true);
tempLocation.mkdirs();
tempLocation.deleteOnExit();
if (testClasses != null)
{
//Add the classes.
warArchiver.addClasses(new File(testClasses.getDirectory()),
testClasses.getIncludesArray(),
testClasses.getExcludesArray());
}
//Now add all of the additional lib files.
for (Iterator iter = libDependencies.iterator(); iter.hasNext();)
{
org.apache.cactus.maven2.mojos.Dependency dependency =
(org.apache.cactus.maven2.mojos.Dependency) iter.next();
warArchiver.addLib(new File(dependency.getDependencyPath(
project, getLog())));
}
try
{
if(this.srcFile != null)
{
AssemblyFileUtils.unpack(this.srcFile, tempLocation,
archiverManager);
}
}
catch (ArchiveExpansionException e)
{
throw new MojoExecutionException("Error extracting the"
+ " archive.", e);
}
catch (NoSuchArchiverException e)
{
throw new MojoExecutionException("Problem reading the "
+ "source archive.", e);
}
warArchiver.addDirectory(tempLocation);
warArchiver.setWebxml(tmpWebXml);
archiver.createArchive(getProject(), getArchive());
}
catch (ArchiverException e)
{
throw new MojoExecutionException("Problem reading the "
+ "source archive.", e);