if (logger.isInfoEnabled()) {
logger.info("Generating deployment plan for " + destinationProject.getLogDisplay());
}
// initialize payload container
DeploymentPayload deploymentPayload = new DeploymentPayload(model.getProject(), deployResources);
deploymentPayload.setDestinationOrgUsername(destinationProject.getUserName());
monitorCheckSubTask(monitor, "Getting connection to destination organization...");
Connection connection = ContainerDelegate.getInstance().getFactoryLocator().getConnectionFactory().getConnection(destinationProject);
monitorWork(monitor);
monitorCheckSubTask(monitor, "Getting permissible object types for destination organization...");
String[] enabledComponentTypes = ContainerDelegate.getInstance().getServiceLocator().getMetadataService().getEnabledComponentTypes(connection, true, true);
if (Utils.isEmpty(enabledComponentTypes)) {
logger.warn("No object types are enabled for " + connection.getLogDisplay());
return deploymentPayload;
}
monitorWork(monitor);
List<String> remoteEnabledComponentTypes = new ArrayList<String>(enabledComponentTypes.length);
remoteEnabledComponentTypes.addAll(Arrays.asList(enabledComponentTypes));
monitorCheckSubTask(monitor, "Gathering project contents for resource(s)");
// get local and remote components
localProjectPackageList = ContainerDelegate.getInstance().getServiceLocator().getProjectService().getProjectContents(deployResources, true, monitor);
localProjectPackageList.setProject(model.getProject());
monitorWork(monitor);
// there's nothing to deploy if local is empty
if (localProjectPackageList.isEmpty()) {
logger.warn("Local package list is empty");
return deploymentPayload;
}
// retrieve remote components
try {
loadRemoteProjectPackageList(connection, deployResources, monitor);
} catch (Exception e) {
logger.warn("Unable to retrieve remote components for resources", ForceExceptionUtils.getRootCause(e));
}
// if remote is empty, are components are considered new
if (Utils.isEmpty(remoteProjectPackageList)) {
if (logger.isInfoEnabled()) {
logger.info("Remote package list is empty. Assuming all local components are new.");
}
ComponentList componentList = localProjectPackageList.getAllComponents();
for (Component component : componentList) {
DeploymentComponent deploymentComponent =
createNewDeploymentComponent(component, remoteEnabledComponentTypes);
deploymentComponent.setRemoteFound(false);
boolean added = deploymentPayload.add(deploymentComponent, true);
if (added) {
if (logger.isDebugEnabled()) {
logger.debug("Added " + deploymentComponent.getFullDisplayName() + " to deployment set");
}
} else {
if (logger.isDebugEnabled()) {
logger.debug(deploymentComponent.getDisplayName() + " already exists in deployment set");
}
}
}
} else {
// evaluate local against remote retrieved
if (logger.isDebugEnabled()) {
logger.debug("Local package count [" + localProjectPackageList.size() + "] and component count ["
+ localProjectPackageList.getComponentCount(true) + "]");
logger.debug("Remote package count ["
+ (Utils.isNotEmpty(remoteProjectPackageList) ? remoteProjectPackageList.size() : 0)
+ "] and component count ["
+ (Utils.isNotEmpty(remoteProjectPackageList) ? remoteProjectPackageList
.getComponentCount(true) : 0) + "]");
}
ComponentList remoteComponents = remoteProjectPackageList.getAllComponents();
if (Utils.isNotEmpty(remoteComponents)) {
deploymentPayload.setRemoteComponentList(remoteComponents);
}
monitorCheckSubTask(monitor, "Evaluating project and remote components...");
// test either project package
for (ProjectPackage localProjectPackage : localProjectPackageList) {
monitorCheck(monitor);
DeploymentComponentSet deploymentComponentSet =
getDeploymentComponentSetForPackage(localProjectPackage, remoteProjectPackageList,
remoteEnabledComponentTypes, monitor);
deploymentPayload.addAll(deploymentComponentSet);
}
monitorWork(monitor);
if (logger.isDebugEnabled()) {
logger.debug("Deployment load count [" + deploymentPayload.size() + "]");
logger.debug(deploymentPayload.getDeploymentPlanSummary());
}
}
return deploymentPayload;
}