getProject().getBundleVersion(), getProject().getBundleDescription(), complianceToUse);
if (this.preinstallTarget != null) {
getProject().auditLog(AuditStatus.SUCCESS, "Pre-Install Started", "The pre install target will start",
"The pre install target named [" + this.preinstallTarget + "] will start", null);
Target target = (Target) getProject().getTargets().get(this.preinstallTarget);
if (target == null) {
try {
getProject().auditLog(
AuditStatus.FAILURE,
"Pre-Install Failure",
"The pre install target does not exist",
"The pre install target specified in the recipe [" + this.preinstallTarget
+ "] does not exist.", null);
} catch (Throwable ignore) {
// swallow any errors that occur here, we want to throw the real build exception
}
throw new BuildException("Specified preinstall target (" + this.preinstallTarget
+ ") does not exist.");
}
target.performTasks();
getProject().auditLog(AuditStatus.SUCCESS, "Pre-Install Finished",
"The pre install target has finished", null, null);
}
boolean haveSomethingToDo = false;
if (!this.files.isEmpty()) {
haveSomethingToDo = true;
log("Deploying files " + this.files + "...", Project.MSG_VERBOSE);
}
if (!this.urlFiles.isEmpty()) {
haveSomethingToDo = true;
log("Deploying files from URL " + this.urlFiles + "...", Project.MSG_VERBOSE);
}
if (!this.archives.isEmpty()) {
haveSomethingToDo = true;
log("Deploying archives " + this.archives + "...", Project.MSG_VERBOSE);
}
if (!this.urlArchives.isEmpty()) {
haveSomethingToDo = true;
log("Deploying archives from URL " + this.urlArchives + "...", Project.MSG_VERBOSE);
}
if (!this.contentToHandover.isEmpty()) {
haveSomethingToDo = true;
log("Handing over " + this.contentToHandover.size() + " file(s)/archive(s)...", Project.MSG_VERBOSE);
}
if (!haveSomethingToDo) {
throw new BuildException(
"You must specify at least one file to deploy via nested file, archive, url-file, url-archive types in your recipe");
}
log("Destination compliance set to '" + complianceToUse + "'.", Project.MSG_VERBOSE);
switch (complianceToUse) {
case full:
if (!dryRun) {
getProject()
.auditLog(
AuditStatus.INFO,
"Managing Top Level Deployment Directory",
"The top level deployment directory will be managed - files found there will be backed up and removed!",
"The bundle recipe has requested that the top level deployment directory be fully managed by RHQ."
+ "This means any files currently located in the top level deployment directory will be removed and backed up",
null);
}
break;
case filesAndDirectories:
log("Files and directories in the destination directory not contained in the bundle will be kept intact.\n"
+ "Note that the contents of the directories that ARE contained in the bundle will be synced with "
+ "the contents as specified in the bundle. I.e. the subdirectories in the destination that are also "
+ "contained in the bundle are made compliant with the bundle.", Project.MSG_VERBOSE);
break;
default:
throw new IllegalStateException("Unhandled destination compliance mode: " + complianceToUse.toString());
}
Map<File, File> allArchives = new HashMap<File, File>(this.archives);
Map<File, File> allFiles = new HashMap<File, File>(this.files);
Map<File, Pattern> allArchiveReplacePatterns = new HashMap<File, Pattern>(this.archiveReplacePatterns);
Set<File> allRawFilesToReplace = new HashSet<File>(this.rawFilesToReplace);
Map<File, Boolean> allArchivesExploded = new HashMap<File, Boolean>(this.archivesExploded);
downloadFilesFromUrlEndpoints(allArchives, allFiles, allArchiveReplacePatterns, allRawFilesToReplace,
allArchivesExploded);
handoverRemoteContentDownloadDirectory = createTempDirectory("handover-", ".download", baseDir);
Map<HasHandover, File> downloadedFilesToHandover = downloadRemoteContentToHandover(handoverRemoteContentDownloadDirectory);
try {
DeploymentData deploymentData = new DeploymentData(deploymentProps, baseDir, deployDir, allFiles,
allRawFilesToReplace, allArchives, allArchiveReplacePatterns, templateEngine, this.ignorePattern,
allArchivesExploded);
Deployer deployer = new Deployer(deploymentData);
DeployDifferences diffs = getProject().getDeployDifferences();
// we only want to emit audit trail when something is really going to happen on disk; don't log if doing a dry run
if (!dryRun) {
getProject().auditLog(AuditStatus.SUCCESS, "Deployer Started", "The deployer has started its work",
null, null);
}
if (revert) {
deployer.redeployAndRestoreBackupFiles(diffs, clean, dryRun);
} else {
deployer.deploy(diffs, clean, dryRun);
}
HandoverTarget handoverTarget = getProject().getHandoverTarget();
if (handoverTarget != null) {
for (HasHandover hasHandoverReference : contentToHandover) {
Handover handoverTag = hasHandoverReference.getHandover();
File source = getFileSource(hasHandoverReference, downloadedFilesToHandover, templateEngine);
FileInputStream contentStream = new FileInputStream(source);
HandoverInfo.Builder builder = new HandoverInfo.Builder();
builder.setContent(contentStream);
builder.setFilename(source.getName());
builder.setAction(handoverTag.getAction());
builder.setParams(handoverTag.getHandoverParams());
builder.setRevert(revert);
HandoverInfo handoverInfo = builder.createHandoverInfo();
if (!dryRun) {
try {
boolean handoverSuccess = handoverTarget.handoverContent(handoverInfo);
String informationMessage = "Source: " + source.getName() + ", " + handoverTag;
if (handoverSuccess) {
getProject().auditLog(AuditStatus.INFO, "Handover",
"Handover target reported success", informationMessage, null);
} else {
if (handoverTag.isFailonerror()) {
getProject().auditLog(AuditStatus.FAILURE, "Handover",
"Handover target reported a failure", informationMessage, null);
throw new Exception("Handover failed: " + handoverTag);
} else {
getProject().auditLog(AuditStatus.WARN, "Handover",
"Handover target reported a failure", informationMessage, null);
}
}
} finally {
safeClose(contentStream);
}
}
}
}
// we only want to emit audit trail when something is really going to happen on disk; don't log if doing a dry run
if (!dryRun) {
getProject().auditLog(AuditStatus.SUCCESS, "Deployer Finished",
"The deployer has finished its work", null, diffs.toString());
}
} catch (Throwable t) {
try {
getProject().auditLog(AuditStatus.FAILURE, "Deployer Failed",
"The deployer encountered an error and could not finished", ThrowableUtil.getAllMessages(t),
ThrowableUtil.getStackAsString(t));
} catch (Throwable ignore) {
// swallow any errors that occur here, we want to throw the real build exception
}
throw new BuildException("Failed to deploy bundle [" + getProject().getBundleName() + "] version ["
+ getProject().getBundleVersion() + "]: " + t, t);
}
if (this.systemService != null) {
this.systemService.install();
}
if (this.postinstallTarget != null) {
getProject().auditLog(AuditStatus.SUCCESS, "Post-Install Started",
"The post install target will start",
"The post install target named [" + this.postinstallTarget + "] will start", null);
Target target = (Target) getProject().getTargets().get(this.postinstallTarget);
if (target == null) {
try {
getProject().auditLog(
AuditStatus.FAILURE,
"Post-Install Failure",
"The post install target does not exist",
"The post install target specified in the recipe [" + this.postinstallTarget
+ "] does not exist.", null);
} catch (Throwable ignore) {
// swallow any errors that occur here, we want to throw the real build exception
}
throw new BuildException("Specified postinstall target (" + this.postinstallTarget
+ ") does not exist.");
}
target.performTasks();
getProject().auditLog(AuditStatus.SUCCESS, "Post-Install Finished",
"The post install target has finished", null, null);
}
} catch (Throwable t) {
try {