@Override
protected void performDeployment(CloudFoundryApplicationModule appModule, IProgressMonitor monitor)
throws CoreException {
final Server server = (Server) getServer();
final CloudFoundryServer cloudServer = getCloudFoundryServer();
final IModule module = modules[0];
try {
// Update the local cloud module representing the application
// first.
appModule.setErrorStatus(null);
server.setModuleState(modules, IServer.STATE_STARTING);
final String deploymentName = appModule.getDeploymentInfo().getDeploymentName();
// This request does three things:
// 1. Checks if the application external or mapped to a local
// project. If mapped to a local project
// it creates an archive of the application's content
// 2. If an archive file was created, it pushes the archive
// file.
// 3. While pushing the archive file, a check is made to see if
// the application exists remotely. If not, the application is
// created in the
// CF server.
if (!modules[0].isExternal()) {
printlnToConsole(appModule, Messages.CONSOLE_GENERATING_ARCHIVE);
final ApplicationArchive applicationArchive = generateApplicationArchiveFile(
appModule.getDeploymentInfo(), appModule, modules, server, incrementalPublish, monitor);
File warFile = null;
if (applicationArchive == null) {
// Create a full war archive
warFile = CloudUtil.createWarFile(modules, server, monitor);
if (warFile == null || !warFile.exists()) {
throw new CoreException(new Status(IStatus.ERROR, CloudFoundryPlugin.PLUGIN_ID,
"Unable to create war file for application: " + deploymentName)); //$NON-NLS-1$
}
CloudFoundryPlugin.trace("War file " + warFile.getName() + " created"); //$NON-NLS-1$ //$NON-NLS-2$
}
// Tell webtools the module has been published
setModulePublishState(modules, IServer.PUBLISH_STATE_NONE);
// update server publish status
IModule[] serverModules = server.getModules();
boolean allSynched = true;
for (IModule serverModule : serverModules) {
int modulePublishState = server.getModulePublishState(new IModule[] { serverModule });
if (modulePublishState == IServer.PUBLISH_STATE_INCREMENTAL
|| modulePublishState == IServer.PUBLISH_STATE_FULL) {
allSynched = false;
}
}
if (allSynched) {
server.setServerPublishState(IServer.PUBLISH_STATE_NONE);
}
final File warFileFin = warFile;
final CloudFoundryApplicationModule appModuleFin = appModule;
// Now push the application resources to the server
new BehaviourRequest<Void>("Pushing the application " + deploymentName) { //$NON-NLS-1$
@Override
protected Void doRun(final CloudFoundryOperations client, SubMonitor progress)
throws CoreException {
pushApplication(client, appModuleFin, warFileFin, applicationArchive, progress);
CloudFoundryPlugin.trace("Application " + deploymentName //$NON-NLS-1$
+ " pushed to Cloud Foundry server."); //$NON-NLS-1$
cloudServer.tagAsDeployed(module);
return null;
}
}.run(monitor);