// operation from the wizard.
// THe working copy should only be saved by the wizard if a user
// clicks "OK".
DeploymentInfoWorkingCopy workingCopy = null;
try {
workingCopy = new ManifestParser(appModule, server).load(monitor);
}
catch (Throwable ce) {
// Some failure occurred reading the manifest file. Proceed
// anyway, to allow the user to manually enter deployment
// values.
CloudFoundryPlugin.logError(ce);
}
// A working copy of the deployment descriptor is needed in order to
// prepopulate the application deployment wizard.
if (workingCopy == null) {
workingCopy = appModule.resolveDeploymentInfoWorkingCopy(monitor);
}
// Get the old working copy in case during the deployment wizard,
// the app name changes
// Apps are looked up by app name in the manifest, therefore if the
// app name changed,
// the old entry in the manifest
ApplicationDeploymentInfo oldInfo = workingCopy.copy();
final boolean[] cancelled = { false };
final boolean[] writeToManifest = { false };
final IStatus[] status = { Status.OK_STATUS };
final DeploymentInfoWorkingCopy finWorkingCopy = workingCopy;
final DeploymentConfiguration[] configuration = new DeploymentConfiguration[1];
Display.getDefault().syncExec(new Runnable() {
public void run() {
CloudFoundryApplicationWizard wizard = new CloudFoundryApplicationWizard(server, appModule,
finWorkingCopy, providerDelegate);
try {
// Update the lookup
ApplicationUrlLookupService.update(server, monitor);
WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getModalDialogShellProvider()
.getShell(), wizard);
int dialogueStatus = dialog.open();
if (dialogueStatus == Dialog.OK) {
// First add any new services to the server
final List<CloudService> addedServices = wizard.getCloudServicesToCreate();
writeToManifest[0] = wizard.persistManifestChanges();
configuration[0] = wizard.getDeploymentConfiguration();
if (addedServices != null && !addedServices.isEmpty()) {
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, addedServices.size());
try {
server.getBehaviour().createService(addedServices.toArray(new CloudService[0]),
subMonitor);
}
catch (CoreException e) {
// Do not let service creation errors
// stop the application deployment
CloudFoundryPlugin.log(e);
}
finally {
subMonitor.done();
}
}
}
else {
cancelled[0] = true;
}
}
catch (Throwable t) {
// Any error in the wizard should result in the module
// being deleted (i.e. cancelled)
cancelled[0] = true;
status[0] = CloudFoundryPlugin.getErrorStatus(t);
}
}
});
if (cancelled[0]) {
if (!status[0].isOK()) {
CloudFoundryPlugin.logError("Failed to deploy application due to: " + status[0].getMessage(), //$NON-NLS-1$
status[0].getException());
}
throw new OperationCanceledException();
}
else {
if (status[0].isOK()) {
status[0] = appModule.validateDeploymentInfo();
}
if (!status[0].isOK()) {
throw new CoreException(status[0]);
}
else if (writeToManifest[0]) {
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
try {
new ManifestParser(appModule, server).write(subMonitor, oldInfo);
}
catch (Throwable ce) {
// Do not let this error propagate, as failing to write
// to the manifest should not stop the app's deployment
CloudFoundryPlugin.logError(ce);