private DeploymentResult deployWork(Connection connection, DeploymentPayload deploymentPayload, boolean checkOnly,
IProgressMonitor monitor) throws InterruptedException, ForceProjectException, FactoryException,
ForceConnectionException, ServiceException, ForceRemoteException, JAXBException {
final ServiceLocator serviceLocator = ContainerDelegate.getInstance().getServiceLocator();
ProjectPackageList projectPackageList = serviceLocator.getProjectService().getProjectPackageListInstance();
projectPackageList.setProject(deploymentPayload.getProject());
PackageManifestFactory factory = projectPackageList.getPackageManifestFactory();
// See W-837427 - we handle custom objects differently upon deploy, and so
// call this specialized manifest factory method.
Package manifest = factory.createSpecialDefaultPackageManifest();
manifest.setVersion(serviceLocator.getProjectService().getLastSupportedEndpointVersion());
monitorCheckSubTask(monitor, "Loading deployment candidates...");
DeploymentComponentSet deploymentComponents = deploymentPayload.getDeploySelectedComponents();
IProject project = deploymentPayload.getProject();
Package packageManifest = serviceLocator.getProjectService().getPackageManifestFactory().getPackageManifest(project);
// Looping through each component that we want to deploy.
//
// Custom object components are handled differently.
for (DeploymentComponent deploymentComponent : deploymentComponents) {
if (deploymentComponent.getDestinationSummary().equals(DeploymentSummary.DELETED)) {
projectPackageList.addDeleteComponent(deploymentComponent.getComponent());
} else {
projectPackageList.addComponent(deploymentComponent.getComponent());
// If this is a custom object component, check to see if it's actually in the manifest -
// maybe a field inside the object was retrieved from the source org into the project,
// but the object itself wasn't.
//
// If so, we don't want to add the object to the deployment manifest. Any fields
// will be included by default because the manifest has a "*" for that component type.
// (In fact it has a "*" for every component type except custom object, because of
// this particular issue. See changelist 1452239.)
//
//Package packageManifest = serviceLocator.getProjectService().getPackageManifestFactory().getPackageManifest(project);
String type = deploymentComponent.getComponent().getComponentType();
boolean isObject = type.equals(Constants.CUSTOM_OBJECT);
boolean isSharingRule = Constants.ABSTRACT_SHARING_RULE_TYPES.contains(type) || Constants.SHARING_RULE_TYPES.contains(type);
if(isObject) {
boolean isPresent = new PackageManifest(packageManifest).contains("CustomObject", deploymentComponent.getComponent().getName());
if (isPresent) {
factory.addComponentToManifest(manifest, deploymentComponent.getComponent());
}
}
//If it's a sharing rule, we will add it from the project manifest
else if (!isSharingRule) {// && !type.equals("Settings")) {
factory.addComponentToManifest(manifest, deploymentComponent.getComponent());
}
}
}
//Add sharing rules from the package manifest file since the component and file structure is
//different than what is required by the package manifest file.
//W-1169372
for (PackageTypeMembers member : packageManifest.getTypes()) {
if (Constants.SHARING_RULE_TYPES.contains(member.getName())) {
manifest.getTypes().add(member);
}
}
monitorWork(monitor);
try {
Component comp = factory.getComponentFactory().getComponentById(Constants.PACKAGE_MANIFEST);
comp.setMetadataFilePath(Constants.PACKAGE_MANIFEST_FILE_NAME);
comp.setBody(manifest.getXMLString());
comp.setName(manifest.getFullName());
projectPackageList.get(0).removePackageManifestComponent();
projectPackageList.get(0).setPackageManifest(comp);
projectPackageList.get(0).addComponent(comp);
} catch (Exception e) {
logger.warn("Unable to change deploy manifest", e);
}
// prepare result and record datetime