objects.add(dobj);
}
DeployFactory deployFactory = null;
if (infusion)
{
if (deployFactory == null)
{
try
{
Class dfClass = Class.forName(DEPLOY_FACTORY_CLASS_NAME, true, Thread.currentThread().getContextClassLoader());
deployFactory = (DeployFactory) dfClass.newInstance();
}
catch (Exception e)
{
throw new MojoExecutionException("Cannot find or load DeployFactory class "+ DEPLOY_FACTORY_CLASS_NAME, e);
}
}
}
String deploySelection = System.getProperty("deploy");
if (deploySelection != null)
{
List selection = new ArrayList();
StringTokenizer st = new StringTokenizer(deploySelection,",;");
while (st.hasMoreTokens())
{
String destination = st.nextToken();
String name = null;
int split = destination.indexOf(":");
if (split > 0)
{
name = destination.substring(split+1);
destination = destination.substring(0, split);
}
for (Iterator iter = objects.iterator(); iter.hasNext(); )
{
DeploymentObject dobj = (DeploymentObject)iter.next();
if (dobj.deployment.destination.equals(destination))
{
if (name == null || name.equals(dobj.deployment.targetName) && !(selection.contains(dobj)))
{
selection.add(dobj);
}
}
}
}
objects = selection;
}
if (objects.size() > 0)
{
getLog().info("Deploying to targetBaseDir "+targetBaseDir.getAbsolutePath());
}
for (Iterator iter = objects.iterator(); iter.hasNext(); )
{
DeploymentObject dobj = (DeploymentObject)iter.next();
String infoPostFix = "";
if (dobj.deployment.infuse.booleanValue())
{
infoPostFix += " (infused";
if (dobj.deployment.expand.booleanValue())
{
infoPostFix += ", expanded";
}
infoPostFix += ")";
}
else if (dobj.deployment.expand.booleanValue())
{
infoPostFix += " (expanded)";
}
getLog().info(" deploying to "+dobj.deployment.destination+": "+dobj.deployment.targetName + infoPostFix);
checkMkdirs(dobj.targetDir);
if (dobj.deployment.delete != null)
{
File delete = new File(dobj.targetDir, dobj.deployment.delete);
if (delete.exists())
{
if (delete.isDirectory())
{
if (!rmdir(delete))
{
throw new MojoExecutionException("Failed to delete directory "+ delete.getAbsolutePath());
}
}
else
{
if (!delete.delete())
{
throw new MojoExecutionException("Failed to delete file "+ delete.getAbsolutePath());
}
}
}
}
File target = new File(dobj.targetDir, dobj.deployment.targetName);
if (target.exists())
{
if (dobj.deployment.expand.booleanValue() && !target.isDirectory())
{
throw new MojoExecutionException("Resolved target directory "+ target.getAbsolutePath()+" points to a file");
}
else if (!dobj.deployment.expand.booleanValue() && target.isDirectory())
{
throw new MojoExecutionException("Resolved target file "+ target.getAbsolutePath()+" points to a directory");
}
}
if ("lib".equals(dobj.deployment.destination) && dobj.artifact != null)
{
deleteMatchingFiles(dobj.targetDir, dobj.artifact.getArtifactId(), dobj.artifact.getType());
}
if (dobj.deployment.infuse.booleanValue())
{
File tmpTarget = null;
try
{
tmpTarget = File.createTempFile(dobj.src.getName()+".infused-", "");
tmpTarget.deleteOnExit();
}
catch (IOException e)
{
throw new MojoExecutionException("Failed to create temporary file",e);
}
try
{
deployFactory.getInstance(dobj.src.getAbsolutePath(), tmpTarget.getAbsolutePath(), dobj.contextName, dobj.deployment.infusionStripLoggers.booleanValue(), dobj.deployment.infusionForcedVersion);
dobj.src = tmpTarget;
}
catch (Exception e)
{
throw new MojoExecutionException("Failed to infuse "+dobj.src.getAbsolutePath(),e);