return true;
}
public String fileAdded(File file) {
log.info("Deploying " + file.getName());
DeploymentManager mgr = null;
TargetModuleID[] modules = null;
boolean completed = false;
try {
mgr = getDeploymentManager();
Target[] targets = mgr.getTargets();
if (null == targets) {
throw new IllegalStateException("No target to distribute to");
}
targets = new Target[] {targets[0]};
ProgressObject po;
if (DeployUtils.isJarFile(file) || file.isDirectory()) {
po = mgr.distribute(targets, file, null);
} else {
po = mgr.distribute(targets, null, file);
}
waitForProgress(po);
if (po.getDeploymentStatus().isCompleted()) {
modules = po.getResultTargetModuleIDs();
po = mgr.start(modules);
waitForProgress(po);
if (po.getDeploymentStatus().isCompleted()) {
completed = true;
} else {
log.warn("Unable to start some modules for " + file.getAbsolutePath());
}
modules = po.getResultTargetModuleIDs();
for (int i = 0; i < modules.length; i++) {
TargetModuleID result = modules[i];
log.info(DeployUtils.reformat("Deployed " + result.getModuleID() + (targets.length > 1 ? " to " + result.getTarget().getName() : "") + (result.getWebURL() == null ? "" : " @ " + result.getWebURL()), 4, 72));
if (result.getChildTargetModuleID() != null) {
for (int j = 0; j < result.getChildTargetModuleID().length; j++) {
TargetModuleID child = result.getChildTargetModuleID()[j];
log.info(DeployUtils.reformat(" `-> " + child.getModuleID() + (child.getWebURL() == null ? "" : " @ " + child.getWebURL()), 4, 72));
}
}
}
} else {
//Try to delete the module , that failed to successfully hot-deploy
log.error("Unable to deploy: " + po.getDeploymentStatus().getMessage());
String delfile=file.getAbsolutePath();
File fd = new File(delfile);
if(fd.isDirectory()){
log.info("Deleting the Directory: "+delfile);
if(DeploymentUtil.recursiveDelete(fd))
log.debug("Successfully deleted the Directory: "+delfile);
else
log.error("Couldn't delete the hot deployed directory"+delfile);
}else if(fd.isFile()){
log.info("Deleting the File: "+delfile);
if(fd.delete()){
log.debug("Successfully deleted the File: "+delfile);
}else
log.error("Couldn't delete the hot deployed directory"+delfile);
}
return null;
}
} catch (DeploymentManagerCreationException e) {
log.error("Unable to open deployer", e);
return null;
} catch (DeploymentException e) {
log.error("Unable to determine if file is a jar", e);
} finally {
if (mgr != null) mgr.release();
}
if (completed && modules != null) {
if (modules.length == 1) {
return modules[0].getModuleID();
} else {