From 26bcb07fc3e4a4f56b459297334f27eaf2ead489 Mon Sep 17 00:00:00 2001 From: Alex Ventura Date: Wed, 27 May 2015 17:37:12 -0400 Subject: [PATCH 01/50] refactoring the validation files --- .../undeploy/SmartFilesValidator.groovy | 2 +- .../enforce/utils/ManagementFile.groovy | 79 ++++++++----------- .../DocumentSalesforceValidator.groovy | 21 +++++ .../validators/FileSalesforceValidator.groovy | 22 ++++++ .../validators/SalesforceValidator.groovy | 8 ++ .../SalesforceValidatorManager.groovy | 14 ++++ .../enforce/utils/ManagementFileTest.groovy | 30 ------- .../DocumentSalesforceValidatorTest.groovy | 35 ++++++++ .../FileSalesforceValidatorTest.groovy | 68 ++++++++++++++++ .../SalesforceValidatorManagerTest.groovy | 25 ++++++ 10 files changed, 227 insertions(+), 77 deletions(-) create mode 100644 src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/DocumentSalesforceValidator.groovy create mode 100644 src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/FileSalesforceValidator.groovy create mode 100644 src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidator.groovy create mode 100644 src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidatorManager.groovy create mode 100644 src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/DocumentSalesforceValidatorTest.groovy create mode 100644 src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/FileSalesforceValidatorTest.groovy create mode 100644 src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidatorManagerTest.groovy diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/undeploy/SmartFilesValidator.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/undeploy/SmartFilesValidator.groovy index 83ec6cb..e4356fa 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/undeploy/SmartFilesValidator.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/undeploy/SmartFilesValidator.groovy @@ -85,7 +85,7 @@ class SmartFilesValidator { ArrayList invalidFolders = [] files.each { file -> String relativePath = Util.getRelativePath(file, basePath) - String folderName = Paths.get(relativePath).getName(0) + String folderName = Util.getFirstPath(relativePath) MetadataComponents component = MetadataComponents.getComponentByRelativePath(relativePath as String) if (component) { filesInOrganization = queryResult.get(component.getTypeName()) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy index 64461d8..c7b5947 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy @@ -6,6 +6,8 @@ package org.fundacionjala.gradle.plugins.enforce.utils import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.MetadataComponents +import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.SalesforceValidator +import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.SalesforceValidatorManager import java.nio.file.Files import java.nio.file.Path @@ -58,19 +60,7 @@ class ManagementFile { if (sourceFolder.exists()) { sourceFolder.eachFile { File folder -> if (folder.isDirectory()) { - folder.eachFile { file -> - if (validateFileByFolder(folder.getName(), file.getName()) && !file.isDirectory()) { - arrayValidFiles.push(file) - File xmlFile = getValidateXmlFile(file) - if (xmlFile) { - arrayValidFiles.push(xmlFile) - } - } else if (COMPONENTS_HAVE_SUB_FOLDER.contains(folder.getName())) { - if (file.isDirectory()) { - arrayValidFiles.addAll(getFilesByFolder(folder.getName(), file)) - } - } - } + arrayValidFiles.addAll(getFiles(folder)) } if (folder.getName() == PACKAGE_XML) { arrayValidFiles.add(folder) @@ -87,14 +77,14 @@ class ManagementFile { * @return an array of valid files */ private ArrayList getFilesByFolder(String parentName, File file) { - ArrayList result = [:] + ArrayList result = [] file.eachFile { File reportFile -> File xmlReportFile = getValidateXmlFile(file) if (xmlReportFile) { result.push(xmlReportFile) } - - if (validateFileByFolder(parentName, reportFile.getName())) { + SalesforceValidator validator = SalesforceValidatorManager.getValidator(parentName) + if (validator.validateFileByFolder(parentName, reportFile)) { result.push(reportFile) } } @@ -134,22 +124,6 @@ class ManagementFile { return null } - /** - * Validates the file based in the folder name who belongs, following the saleforce definitions - * @param folderName - * @param file - * @return - */ - public boolean validateFileByFolder(String folderName, String file) { - if (folderName == MetadataComponents.DOCUMENTS.getDirectory() && file.contains('.')) { - return true - } - String componentExtension = MetadataComponents.getExtensionByFolder(folderName) - if (!componentExtension) { - return false - } - return file.endsWith(componentExtension) - } /** * Copies array file in the path copy @@ -289,7 +263,7 @@ class ManagementFile { /** * Gets array valid files by folders * @param sourcePath is type String - * @param folders ys type ArrayList + * @param folders is type ArrayList * @return files validated by folders */ public ArrayList getFilesByFolders(String sourcePath, ArrayList folders) { @@ -298,24 +272,37 @@ class ManagementFile { folders.each { folderName -> File folder = new File(Paths.get(sourcePath, folderName).toString()) if (folder.exists()) { - folder.eachFile { file -> - if (validateFileByFolder(folderName, file.getName()) && !file.isDirectory()) { - filesByFolder.push(file) - File xmlFile = new File("${file.getAbsolutePath().toString()}${METADATA_EXTENSION}") - if (xmlFile.exists()) { - filesByFolder.push(xmlFile) - } - } else if (COMPONENTS_HAVE_SUB_FOLDER.contains(folder.getName())) { - if (file.isDirectory()) { - filesByFolder.addAll(getFilesByFolder(folder.getName(), file)) - } - } - } + filesByFolder.addAll(getFiles(folder)) } } return filesByFolder } + /** + * Gets array valid files by folder + * @param folders is type ArrayList + * @return files validated by folders + */ + private ArrayList getFiles(File folder) { + ArrayList result = [] + folder.eachFile { file -> + SalesforceValidator validator = SalesforceValidatorManager.getValidator(folder.getName()) + if (validator.validateFileByFolder(folder.getName(), file)) { + result.push(file) + File xmlFile = new File("${file.getAbsolutePath().toString()}${METADATA_EXTENSION}") + if (xmlFile.exists()) { + result.push(xmlFile) + } + } else if (COMPONENTS_HAVE_SUB_FOLDER.contains(folder.getName())) { + if (file.isDirectory()) { + result.addAll(getFilesByFolder(folder.getName(), file)) + } + } + } + + return result + } + /** * Gets files from source directory path directory by regular expression * @param regex the regular expression diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/DocumentSalesforceValidator.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/DocumentSalesforceValidator.groovy new file mode 100644 index 0000000..3ad6bad --- /dev/null +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/DocumentSalesforceValidator.groovy @@ -0,0 +1,21 @@ +package org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators + +import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.MetadataComponents + +public class DocumentSalesforceValidator implements SalesforceValidator{ + + /** + * Validates the document file that belongs to documents folder defined in Salesforce + * @param folderName + * @param file + * @return + */ + @Override + boolean validateFileByFolder(String folderName, File file) { + if (folderName == MetadataComponents.DOCUMENTS.getDirectory() && !file.isDirectory()) { + return true + } + + return false + } +} diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/FileSalesforceValidator.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/FileSalesforceValidator.groovy new file mode 100644 index 0000000..00b7de1 --- /dev/null +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/FileSalesforceValidator.groovy @@ -0,0 +1,22 @@ +package org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators + +import org.fundacionjala.gradle.plugins.enforce.utils.Util +import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.MetadataComponents + +public class FileSalesforceValidator implements SalesforceValidator{ + + /** + * Validates the file based in the folder name who belongs, following the Saleforce definitions + * @param folderName + * @param file + * @return boolean + */ + @Override + public boolean validateFileByFolder(String folderName, File file) { + String componentExtension = MetadataComponents.getExtensionByFolder(folderName) + if (!componentExtension) { + return false + } + return Util.getFileExtension(file).equals(componentExtension) + } +} diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidator.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidator.groovy new file mode 100644 index 0000000..92e1cf1 --- /dev/null +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidator.groovy @@ -0,0 +1,8 @@ +package org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators +/** + * Defines the different kind of validate a file + * based in Salesforce definitions + */ +public interface SalesforceValidator { + boolean validateFileByFolder(String folderName, File file) +} \ No newline at end of file diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidatorManager.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidatorManager.groovy new file mode 100644 index 0000000..5443974 --- /dev/null +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidatorManager.groovy @@ -0,0 +1,14 @@ +package org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators + +public class SalesforceValidatorManager { + private static Map validatorMap = [ + 'documents': new DocumentSalesforceValidator() + ] + + public static SalesforceValidator getValidator(String folderName) { + if (validatorMap.containsKey(folderName)) { + return validatorMap.get(folderName) + } + return new FileSalesforceValidator() + } +} diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFileTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFileTest.groovy index 2d13476..da6f3be 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFileTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFileTest.groovy @@ -24,36 +24,6 @@ class ManagementFileTest extends Specification { managementFile = new ManagementFile(targetPath) } - def "Test get valid file true"() { - given: - def file = 'class1.cls' - def folder = 'classes' - when: - def result = managementFile.validateFileByFolder(folder, file) - then: - result == true - } - - def "Test get valid file false"() { - given: - def file = 'class1.data' - def folder = 'classes' - when: - def result = managementFile.validateFileByFolder(folder, file) - then: - !result - } - - def "Test get wrong file xml"() { - given: - def file = 'package.xml' - def folder = 'classes' - when: - def result = managementFile.validateFileByFolder(folder, file) - then: - !result - } - def "Test get valid elements with path source"() { when: ArrayList arrayResult = managementFile.getValidElements(targetPath) diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/DocumentSalesforceValidatorTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/DocumentSalesforceValidatorTest.groovy new file mode 100644 index 0000000..59e6bf8 --- /dev/null +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/DocumentSalesforceValidatorTest.groovy @@ -0,0 +1,35 @@ +package org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators + +import spock.lang.Shared +import spock.lang.Specification + +class DocumentSalesforceValidatorTest extends Specification { + + @Shared + SalesforceValidator validator + + + def setup() { + validator = new DocumentSalesforceValidator() + } + + def "Test should validate is not valid the folder that contains the document"() { + given: + def file = new File('account.docx') + def folder = 'classes' + when: + def result = validator.validateFileByFolder(folder, file) + then: + !result + } + + def "Test should validate a document in the valid folder"() { + given: + def file = new File('mydocuments/doc1.docx') + def folder = 'documents' + when: + def result = validator.validateFileByFolder(folder, file) + then: + result + } +} diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/FileSalesforceValidatorTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/FileSalesforceValidatorTest.groovy new file mode 100644 index 0000000..adf6f9a --- /dev/null +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/FileSalesforceValidatorTest.groovy @@ -0,0 +1,68 @@ +package org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators + +import spock.lang.Shared +import spock.lang.Specification + +import java.nio.file.Paths + +class FileSalesforceValidatorTest extends Specification { + + @Shared + SalesforceValidator validator + + + def setup() { + validator = new FileSalesforceValidator() + } + + def "Test get valid file true"() { + given: + def file = new File('class1.cls') + def folder = 'classes' + when: + def result = validator.validateFileByFolder(folder, file) + then: + result + } + + + def "Test get valid file false"() { + given: + def file = new File('class1.data') + def folder = 'classes' + when: + def result = validator.validateFileByFolder(folder, file) + then: + !result + } + + def "Test get wrong file xml"() { + given: + def file = new File('package.xml') + def folder = 'classes' + when: + def result = validator.validateFileByFolder(folder, file) + then: + !result + } + + def "Test should validate the report file"() { + given: + def file = new File(Paths.get('testFolder/account.report').toString()) + def folder = 'reports' + when: + def result = validator.validateFileByFolder(folder, file) + then: + result + } + + def "Test should validate is not areport file"() { + given: + def file = new File(Paths.get('testFolder/account.notreport').toString()) + def folder = 'reports' + when: + def result = validator.validateFileByFolder(folder, file) + then: + !result + } +} diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidatorManagerTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidatorManagerTest.groovy new file mode 100644 index 0000000..30dcfc9 --- /dev/null +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidatorManagerTest.groovy @@ -0,0 +1,25 @@ +package org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators + +import spock.lang.Specification + + +class SalesforceValidatorManagerTest extends Specification { + + def "Test should return a FileSalesforceValidator"() { + given: + def folder = 'classes' + when: + def validator = SalesforceValidatorManager.getValidator(folder) + then: + validator instanceof FileSalesforceValidator + } + + def "Test should return a DocumentSalesforceValidator"() { + given: + def folder = 'documents' + when: + def validator = SalesforceValidatorManager.getValidator(folder) + then: + validator instanceof DocumentSalesforceValidator + } +} From ad4ca506591c9e5678ae5ef67ea19c571d0b8a37 Mon Sep 17 00:00:00 2001 From: Alex Ventura Date: Wed, 27 May 2015 18:29:53 -0400 Subject: [PATCH 02/50] updated the Metadata Components --- .../enforce/interceptor/InterceptorManager.groovy | 2 +- .../enforce/undeploy/SmartFilesValidator.groovy | 4 +--- .../plugins/enforce/utils/ManagementFile.groovy | 6 +++--- .../utils/salesforce/MetadataComponents.groovy | 12 +++--------- .../enforce/utils/salesforce/PackageBuilder.groovy | 6 ++---- .../plugins/enforce/wsc/rest/QueryBuilder.groovy | 4 ++-- .../utils/salesforce/MetadataComponentsTest.groovy | 4 ++-- 7 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/InterceptorManager.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/InterceptorManager.groovy index 5ac32ad..1332255 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/InterceptorManager.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/InterceptorManager.groovy @@ -35,7 +35,7 @@ class InterceptorManager { */ public void buildInterceptors() { truncatedDirectories.each { dir -> - MetadataComponents componentType = MetadataComponents.getComponentByRelativePath(dir as String) + MetadataComponents componentType = MetadataComponents.getComponentByPath(dir as String) FactoryInterceptor factoryComponent = new FactoryInterceptor() MetadataInterceptor interceptor = factoryComponent.getInterceptor(componentType) if (interceptor) { diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/undeploy/SmartFilesValidator.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/undeploy/SmartFilesValidator.groovy index e4356fa..6724f1e 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/undeploy/SmartFilesValidator.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/undeploy/SmartFilesValidator.groovy @@ -14,8 +14,6 @@ import org.fundacionjala.gradle.plugins.enforce.wsc.Credential import org.fundacionjala.gradle.plugins.enforce.wsc.rest.QueryBuilder import org.fundacionjala.gradle.plugins.enforce.wsc.rest.ToolingAPI -import java.nio.file.Paths - /** * Validates files according salesForce json queries */ @@ -86,7 +84,7 @@ class SmartFilesValidator { files.each { file -> String relativePath = Util.getRelativePath(file, basePath) String folderName = Util.getFirstPath(relativePath) - MetadataComponents component = MetadataComponents.getComponentByRelativePath(relativePath as String) + MetadataComponents component = MetadataComponents.getComponentByPath(relativePath as String) if (component) { filesInOrganization = queryResult.get(component.getTypeName()) pushIfItIsPossible(file, folderName, filesClassified, filesInOrganization) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy index c7b5947..19a2fd3 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy @@ -60,7 +60,7 @@ class ManagementFile { if (sourceFolder.exists()) { sourceFolder.eachFile { File folder -> if (folder.isDirectory()) { - arrayValidFiles.addAll(getFiles(folder)) + arrayValidFiles.addAll(getValidFilesByForder(folder)) } if (folder.getName() == PACKAGE_XML) { arrayValidFiles.add(folder) @@ -272,7 +272,7 @@ class ManagementFile { folders.each { folderName -> File folder = new File(Paths.get(sourcePath, folderName).toString()) if (folder.exists()) { - filesByFolder.addAll(getFiles(folder)) + filesByFolder.addAll(getValidFilesByForder(folder)) } } return filesByFolder @@ -283,7 +283,7 @@ class ManagementFile { * @param folders is type ArrayList * @return files validated by folders */ - private ArrayList getFiles(File folder) { + private ArrayList getValidFilesByForder(File folder) { ArrayList result = [] folder.eachFile { file -> SalesforceValidator validator = SalesforceValidatorManager.getValidator(folder.getName()) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/MetadataComponents.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/MetadataComponents.groovy index bcebfe6..d3e12ae 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/MetadataComponents.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/MetadataComponents.groovy @@ -24,20 +24,17 @@ public enum MetadataComponents { ASSIGNMENTRULES("AssignmentRules", "assignmentRules", "assignmentRules"), OBJECTTRANSLATIONS("CustomObjectTranslation", "objectTranslation", "objectTranslations"), APPROVALPROCESSES("ApprovalProcess", "approvalProcess", "approvalProcesses"), - CAMPAIGNSHARINGRULES("CampaignSharingRules", "", "campaignSharingRules"), + SHARINGRULES("SharingRules", ".sharingRules", "sharingRules"), APPLICATIONS("CustomApplication", "app", "applications"), WEBLINKS("CustomPageWebLink", "weblink", "weblinks"), DASHBOARDS("Dashboard", "dashboard", "dashboards"), OBJECTS("CustomObject", "object", "objects"), - ACCOUNTSHARINGRULES("AccountSharingRules", "", "accountSharingRules"), GROUPS("Group", "group", "groups"), STATICRESOURCES("StaticResource", "resource", "staticresources"), - ESCALATIONRULES("EscalationRules", "", "escalationRules"), - CUSTOMOBJECTSHARINGRULES("CustomObjectSharingRules", "", "customObjectSharingRules"), + ESCALATIONRULES("EscalationRules", "escalationRules", "escalationRules"), REPORTS("Report", "report", "reports"), HOMEPAGECOMPONENTS("HomePageComponent", "homePageComponent", "homePageComponents"), LABELS("CustomLabels", "labels", "labels"), - OPPORTUNITYSHARINGRULES("OpportunitySharingRules", "", "opportunitySharingRules"), CONNECTEDAPPS("ConnectedApp", "connectedapp", "connectedApps"), FLOWS("Flow", "flow", "flows"), AUTHPROVIDERS("AuthProvider", "authprovider", "authproviders"), @@ -45,11 +42,9 @@ public enum MetadataComponents { EMAIL("EmailTemplate", "email", "email"), ROLES("Role", "role", "roles"), COMPONENTS("ApexComponent", "component", "components"), - LEADSHARINGRULES("LeadSharingRules", "", "leadSharingRules"), CUSTOMAPPLICATIONCOMPONENTS("CustomApplicationComponent", "customApplicationComponent", "customApplicationComponents"), LAYOUTS("Layout", "layout", "layouts"), HOMEPAGELAYOUTS("HomePageLayout", "homePageLayout", "homePageLayouts"), - CONTACTSHARINGRULES("ContactSharingRules", "", "contactSharingRules"), ANALYTICSNAPSHOTS("AnalyticSnapshot", "analyticsnapshot", "analyticSnapshots"), AUTORESPONSERULES("AutoResponseRules", "autoResponseRules", "autoResponseRules"), DATACATEGORYGROUPS("DataCategoryGroup", "datacategorygroup", "datacategorygroups"), @@ -59,7 +54,6 @@ public enum MetadataComponents { PAGES("ApexPage", "page", "pages"), LETTERHEAD("Letterhead", "letter", "letterhead"), REPORTTYPES("ReportType", "reportType", "reportTypes"), - CASESHARINGRULES("CaseSharingRules", "", "caseSharingRules"), SYNONYMDICTIONARIES("SynonymDictionary", "synonymDictionary", "synonymDictionaries"), POSTTEMPLATES("PostTemplate", "postTemplate", "postTemplates"), QUICKACTIONS("QuickAction", "quickAction", "quickActions"), @@ -121,7 +115,7 @@ public enum MetadataComponents { * @param path is the relative path in the project * @return a MetadataComponent */ - public static MetadataComponents getComponentByRelativePath(String path) { + public static MetadataComponents getComponentByPath(String path) { MetadataComponents metadataComponent String folder = Util.getFirstPath(path) for (MetadataComponents component : values()) { diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageBuilder.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageBuilder.groovy index 24fecea..bf84722 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageBuilder.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageBuilder.groovy @@ -13,13 +13,11 @@ import groovy.xml.MarkupBuilder import groovy.xml.XmlUtil import groovy.xml.dom.DOMCategory import org.fundacionjala.gradle.plugins.enforce.utils.Constants -import org.fundacionjala.gradle.plugins.enforce.utils.ManagementFile import org.fundacionjala.gradle.plugins.enforce.utils.Util import org.fundacionjala.gradle.plugins.enforce.wsc.Connector import org.w3c.dom.Document import org.w3c.dom.Element -import java.nio.file.Path import java.nio.file.Paths /** @@ -203,7 +201,7 @@ class PackageBuilder { PackageTypeMembers packageTypeMembers ArrayList invalidFolders = [] folders.each { folder -> - MetadataComponents component = MetadataComponents.getComponentByRelativePath(folder as String) + MetadataComponents component = MetadataComponents.getComponentByPath(folder as String) if (component) { packageTypeMembers = new PackageTypeMembers() ArrayList filesMembers = selectFilesMembers(folder, files, basePath) @@ -230,7 +228,7 @@ class PackageBuilder { PackageTypeMembers packageTypeMembers ArrayList invalidFolders = [] folders.each { folder -> - MetadataComponents component = MetadataComponents.getComponentByRelativePath(folder as String) + MetadataComponents component = MetadataComponents.getComponentByPath(folder as String) if (component) { packageTypeMembers = new PackageTypeMembers() packageTypeMembers.members = WILDCARD diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/rest/QueryBuilder.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/rest/QueryBuilder.groovy index cf12814..ff8f9a5 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/rest/QueryBuilder.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/rest/QueryBuilder.groovy @@ -67,7 +67,7 @@ class QueryBuilder { ArrayList invalidFolders = [] files.each { file -> String folderName = file.getParentFile().getName() - MetadataComponents component = MetadataComponents.getComponentByRelativePath(folderName) + MetadataComponents component = MetadataComponents.getComponentByPath(folderName) if (component && isDefaultComponent(component.getTypeName())) { String query = component.getExtension() != 'sbc'? """${SELECT_NAME} ${component.getTypeName()} ${WHERE_NAME} '${ @@ -93,7 +93,7 @@ class QueryBuilder { * @return String which contain type name of file */ public String getComponent(File file) { - return MetadataComponents.getComponentByRelativePath(file.getParentFile().getName()).getTypeName() + return MetadataComponents.getComponentByPath(file.getParentFile().getName()).getTypeName() } /** diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/MetadataComponentsTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/MetadataComponentsTest.groovy index a648104..55a4598 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/MetadataComponentsTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/MetadataComponentsTest.groovy @@ -76,11 +76,11 @@ class MetadataComponentsTest extends Specification { def "Test a component by folder"() { expect: - MetadataComponents.getComponentByRelativePath("classes").typeName == "ApexClass" + MetadataComponents.getComponentByPath("classes").typeName == "ApexClass" } def "Test a component by folder has contains sub folder"() { expect: - MetadataComponents.getComponentByRelativePath("reports/reportTest").typeName == "Report" + MetadataComponents.getComponentByPath("reports/reportTest").typeName == "Report" } } From 082bf93543f9e86e9da2f6830f9602e56bbe5660 Mon Sep 17 00:00:00 2001 From: Alex Ventura Date: Thu, 28 May 2015 14:25:46 -0400 Subject: [PATCH 03/50] fixed unit test it was broken in windows operating system --- .../validators/SalesforceValidatorManager.groovy | 9 ++++++++- .../validators/DocumentSalesforceValidatorTest.groovy | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidatorManager.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidatorManager.groovy index 5443974..80af631 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidatorManager.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidatorManager.groovy @@ -1,10 +1,17 @@ package org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators - +/** + * Manages the different kind of validate a file + * based in Salesforce definitions + */ public class SalesforceValidatorManager { private static Map validatorMap = [ 'documents': new DocumentSalesforceValidator() ] + /** + * Returns a object validator based in the folderName + * defined in Salesforce + */ public static SalesforceValidator getValidator(String folderName) { if (validatorMap.containsKey(folderName)) { return validatorMap.get(folderName) diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/DocumentSalesforceValidatorTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/DocumentSalesforceValidatorTest.groovy index 59e6bf8..a270e74 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/DocumentSalesforceValidatorTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/DocumentSalesforceValidatorTest.groovy @@ -3,6 +3,8 @@ package org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.vali import spock.lang.Shared import spock.lang.Specification +import java.nio.file.Paths + class DocumentSalesforceValidatorTest extends Specification { @Shared @@ -25,7 +27,7 @@ class DocumentSalesforceValidatorTest extends Specification { def "Test should validate a document in the valid folder"() { given: - def file = new File('mydocuments/doc1.docx') + def file = new File(Paths.get('mydocuments/doc1.docx').toString()) def folder = 'documents' when: def result = validator.validateFileByFolder(folder, file) From ca348b26a4013e42cc146f3459abebd513f6babe Mon Sep 17 00:00:00 2001 From: marco_cadima Date: Thu, 28 May 2015 17:11:38 -0400 Subject: [PATCH 04/50] deploy, upload task now taken in account package xml file from project directory --- .../tasks/salesforce/SalesforceTask.groovy | 2 + .../tasks/salesforce/deployment/Deploy.groovy | 7 ++-- .../salesforce/deployment/Deployment.groovy | 9 ++++- .../salesforce/deployment/Undeploy.groovy | 38 ++++++------------- .../tasks/salesforce/deployment/Update.groovy | 18 ++++----- .../tasks/salesforce/deployment/Upload.groovy | 33 +++++++--------- .../plugins/enforce/utils/Constants.groovy | 29 +++++++++++++- .../utils/salesforce/PackageCombiner.groovy | 4 +- .../salesforce/deployment/DeployTest.groovy | 2 + .../salesforce/deployment/UndeployTest.groovy | 4 +- .../salesforce/deployment/UpdateTest.groovy | 2 + 11 files changed, 84 insertions(+), 64 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy index d3bc1d6..e5be57a 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy @@ -39,6 +39,7 @@ abstract class SalesforceTask extends ForceTask { public int poll public int waitTime public ArrayList arrayPaths + public String projectPackagePath /** * Sets description and group task @@ -153,6 +154,7 @@ abstract class SalesforceTask extends ForceTask { logger.debug('Finished load credential') fileManager.createDirectory(buildFolderPath) logger.debug('Created directory at: ' + buildFolderPath) + projectPackagePath = Paths.get(projectPath, PACKAGE_NAME) runTask() } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deploy.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deploy.groovy index af2be50..4e09660 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deploy.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deploy.groovy @@ -10,7 +10,6 @@ import org.fundacionjala.gradle.plugins.enforce.interceptor.Interceptor import org.fundacionjala.gradle.plugins.enforce.utils.AnsiColor import org.fundacionjala.gradle.plugins.enforce.utils.Constants import org.fundacionjala.gradle.plugins.enforce.utils.Util -import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.PackageCombiner import java.nio.file.Files import java.nio.file.Paths @@ -23,7 +22,6 @@ class Deploy extends Deployment { private boolean deprecateTruncateOn private boolean codeTruncateOn private String deployPackagePath - private String projectPackagePath public ArrayList foldersNotDeploy public String folderDeploy @@ -33,7 +31,7 @@ class Deploy extends Deployment { * Sets description task and its group */ Deploy() { - super(Constants.DESCRIPTION_OF_TASK, Constants.DEPLOYMENT) + super(Constants.DEPLOY_DESCRIPTION, Constants.DEPLOYMENT) deprecateTruncateOn = true codeTruncateOn = true } @@ -63,7 +61,6 @@ class Deploy extends Deployment { public void setupFilesToDeploy() { folderDeploy = Paths.get(buildFolderPath, Constants.FOLDER_DEPLOY).toString() deployPackagePath = Paths.get(folderDeploy, PACKAGE_NAME).toString() - projectPackagePath = Paths.get(projectPath, PACKAGE_NAME).toString() } /** @@ -115,6 +112,7 @@ class Deploy extends Deployment { componentDeploy.startMessage = Constants.DEPLOYING_TRUNCATED_CODE componentDeploy.successMessage = Constants.DEPLOYING_TRUNCATED_CODE_SUCCESSFULLY logger.debug("Deploying to truncate components from: $folderDeploy") + combinePackage(deployPackagePath) executeDeploy(folderDeploy) createDeploymentDirectory(folderDeploy) } @@ -155,6 +153,7 @@ class Deploy extends Deployment { truncateComponents(folderDeploy) } logger.debug("Deploying all components from: $folderDeploy") + combinePackage(deployPackagePath) executeDeploy(folderDeploy) updateFileTracker() } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy index 39b62fb..3621b96 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy @@ -11,6 +11,7 @@ import org.fundacionjala.gradle.plugins.enforce.tasks.salesforce.SalesforceTask import org.fundacionjala.gradle.plugins.enforce.utils.Constants import org.fundacionjala.gradle.plugins.enforce.utils.Util import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.MetadataComponents +import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.PackageCombiner import org.gradle.api.file.FileTree import org.gradle.api.tasks.bundling.Zip @@ -20,7 +21,6 @@ import java.nio.file.Paths * Represent base class for needs deploy code in salesforce */ abstract class Deployment extends SalesforceTask { - private final String NAME_TASK_ZIP = "createZip" DeployMetadata componentDeploy InterceptorManager componentManager @@ -314,4 +314,11 @@ abstract class Deployment extends SalesforceTask { throw new Exception(errorMessage) } } + + public void combinePackage(String buildPackagePath) { + PackageCombiner.packageCombine(projectPackagePath, buildPackagePath) + if (excludes) { + PackageCombiner.removeMembersFromPackage(buildPackagePath, getFilesExcludes(excludes)) + } + } } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Undeploy.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Undeploy.groovy index 5510a70..32cb366 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Undeploy.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Undeploy.groovy @@ -12,8 +12,6 @@ import org.fundacionjala.gradle.plugins.enforce.utils.Constants import org.fundacionjala.gradle.plugins.enforce.utils.Util import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.MetadataComponent import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.MetadataComponents -import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.PackageBuilder -import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.PackageCombiner import org.fundacionjala.gradle.plugins.enforce.wsc.rest.QueryBuilder import org.fundacionjala.gradle.plugins.enforce.wsc.rest.ToolingAPI import org.gradle.api.GradleException @@ -27,26 +25,18 @@ import java.nio.file.StandardCopyOption * Undeploys an org using metadata API */ class Undeploy extends Deployment { - private final String START_MESSAGE_TRUNCATE = 'Starting undeploy...' - private final String SUCCESS_MESSAGE_TRUNCATE = 'All components truncated were successfully uploaded' - private final String SUCCESS_MESSAGE_DELETE = 'The files were successfully deleted' - private final String FILE_NAME_DESTRUCTIVE = "destructiveChanges.xml" - private final String CUSTOM_FIELD_NAME = 'CustomField' - private final String WORK_FLOW_RULE_NAME = 'WorkflowRule' - private final String DIR_UN_DEPLOY = "undeploy" private List includesComponents private FileTree files private ArrayList workflowNames private ArrayList workflowFiles private QueryBuilder queryBuilder - public final String LOOKUP_NAME = 'Lookup' + public ToolingAPI toolingAPI public PackageComponent packageComponent public ArrayList filesToTruncate public String folderUnDeploy public String unDeployPackagePath public String unDeployDestructivePath - public String projectPackagePath public SmartFilesValidator smartFilesValidator InterceptorManager componentManager List standardComponents @@ -57,7 +47,7 @@ class Undeploy extends Deployment { * @param group is the group typeName the task */ Undeploy() { - super('This task removes all components in your organization according to local repository', Constants.DEPLOYMENT) + super(Constants.UN_DEPLOY_DESCRIPTION, Constants.DEPLOYMENT) filesToTruncate = new ArrayList() componentManager = new InterceptorManager() componentManager.buildInterceptors() @@ -79,15 +69,13 @@ class Undeploy extends Deployment { /** * Creates undeploy folder into build directory - * Sets package path from build directory and project directory * Sets destructive path to build directory */ def setupFilesToUnDeploy() { - folderUnDeploy = Paths.get(buildFolderPath, DIR_UN_DEPLOY).toString() + folderUnDeploy = Paths.get(buildFolderPath, Constants.DIR_UN_DEPLOY).toString() createDeploymentDirectory(folderUnDeploy) unDeployPackagePath = Paths.get(folderUnDeploy, PACKAGE_NAME).toString() - unDeployDestructivePath = Paths.get(folderUnDeploy, FILE_NAME_DESTRUCTIVE).toString() - projectPackagePath = Paths.get(projectPath, PACKAGE_NAME).toString() + unDeployDestructivePath = Paths.get(folderUnDeploy, Constants.FILE_NAME_DESTRUCTIVE).toString() } /** @@ -116,8 +104,9 @@ class Undeploy extends Deployment { */ def deployTruncatedComponents() { writePackage(unDeployPackagePath, filesToTruncate) - componentDeploy.startMessage = START_MESSAGE_TRUNCATE - componentDeploy.successMessage = SUCCESS_MESSAGE_TRUNCATE + componentDeploy.startMessage = Constants.START_MESSAGE_TRUNCATE + componentDeploy.successMessage = Constants.SUCCESS_MESSAGE_TRUNCATE + combinePackage(unDeployPackagePath) executeDeploy(folderUnDeploy) } @@ -139,18 +128,15 @@ class Undeploy extends Deployment { ArrayList objectFiles = files.getFiles().sort() objectFiles = excludeFiles(objectFiles) savePackage() - updatePackage(CUSTOM_FIELD_NAME, getFields(objectFiles), unDeployDestructivePath) + updatePackage(Constants.CUSTOM_FIELD_NAME, getFields(objectFiles), unDeployDestructivePath) if (!workflowNames.empty) { workflowFiles = project.fileTree(dir: projectPath, includes: workflowNames).toList() workflowFiles = excludeFiles(workflowFiles) - updatePackage(WORK_FLOW_RULE_NAME, getRules(workflowFiles), unDeployDestructivePath) + updatePackage(Constants.WORK_FLOW_RULE_NAME, getRules(workflowFiles), unDeployDestructivePath) } componentDeploy.startMessage = "" - componentDeploy.successMessage = SUCCESS_MESSAGE_DELETE - PackageCombiner.packageCombine(projectPackagePath, unDeployDestructivePath) - if (excludes) { - PackageCombiner.removeMembersFromPackage(unDeployDestructivePath, getFilesExcludes(excludes)) - } + componentDeploy.successMessage = Constants.SUCCESS_MESSAGE_DELETE + combinePackage(unDeployDestructivePath) executeDeploy(folderUnDeploy) } @@ -253,7 +239,7 @@ class Undeploy extends Deployment { CustomObject.fields.each { field -> def type = field.type.text() String objReference = "${field.referenceTo.text()}.${MetadataComponents.OBJECTS.getExtension()}" - if (type == LOOKUP_NAME && PackageComponent.existObject(objectFile.parent, objReference)) { + if (type == Constants.LOOKUP_NAME && PackageComponent.existObject(objectFile.parent, objReference)) { customFields.add("${objectName}.${field.fullName.text()}") } } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Update.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Update.groovy index de06ab5..337eef1 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Update.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Update.groovy @@ -16,12 +16,8 @@ import java.nio.file.Paths * Updates an org using metadata API */ class Update extends Deployment { - private static final String DESCRIPTION_OF_TASK = "This task deploys just the files that were changed" - private final String FOLDERS_DEPLOY = "folders" - private final String DIR_UPDATE_FOLDER = "update" - private final String FILE_NAME_DESTRUCTIVE = "destructiveChanges.xml" - private final String NOT_FILES_CHANGED = "There are not files changed" public String pathUpdate + public String updatePackagePath ArrayList filesToCopy ArrayList filesToUpdate String folders @@ -34,7 +30,7 @@ class Update extends Deployment { * @param group is the group typeName the task */ Update() { - super(DESCRIPTION_OF_TASK, Constants.DEPLOYMENT) + super(Constants.UPDATE_DESCRIPTION, Constants.DEPLOYMENT) filesToCopy = new ArrayList() filesToUpdate = new ArrayList() filesExcludes = new ArrayList() @@ -47,14 +43,15 @@ class Update extends Deployment { */ @Override void runTask() { - pathUpdate = Paths.get(buildFolderPath, DIR_UPDATE_FOLDER).toString() + pathUpdate = Paths.get(buildFolderPath, Constants.DIR_UPDATE_FOLDER).toString() + updatePackagePath = Paths.get(pathUpdate, PACKAGE_NAME).toString() createDeploymentDirectory(pathUpdate) loadFilesChanged() verifyParameter() excludeFilesFromFilesChanged() showFilesChanged() if (packageGenerator.fileTrackerMap.isEmpty()) { - logger.quiet(NOT_FILES_CHANGED) + logger.quiet(Constants.NOT_FILES_CHANGED) return } createDestructive() @@ -62,6 +59,7 @@ class Update extends Deployment { copyFilesChanged() showFilesExcludes() truncate(pathUpdate) + combinePackage(updatePackagePath) executeDeploy(pathUpdate) packageGenerator.saveFileTrackerMap() } @@ -87,7 +85,7 @@ class Update extends Deployment { * Creates package to all files which has been deleted */ def createDestructive() { - packageGenerator.buildDestructive(Paths.get(pathUpdate, FILE_NAME_DESTRUCTIVE).toString()) + packageGenerator.buildDestructive(Paths.get(pathUpdate, Constants.FILE_NAME_DESTRUCTIVE).toString()) } /** @@ -102,7 +100,7 @@ class Update extends Deployment { * Verifies if there is files changed in folders inserted by user */ def verifyParameter() { - if (Util.isValidProperty(project, FOLDERS_DEPLOY)) { + if (Util.isValidProperty(project, Constants.FOLDERS_DEPLOY)) { folders = project.folders } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Upload.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Upload.groovy index 51f9578..8ba8b0b 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Upload.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Upload.groovy @@ -17,28 +17,20 @@ import java.nio.file.Paths * Uploads files to an organization using metadata API without truncate values */ class Upload extends Deployment { - private static final String DESCRIPTION_OF_TASK = "This task uploads all specific files or folders as user wants" - private final String ALL_FILES_UPLOAD = "All files will be uploaded from: " - private final String QUESTION_CONTINUE = " Do you want to continue? (y/n) :" - private final String UPLOAD_CANCELED ='Upload all files was canceled!!' - private final String DIR_UPLOAD_FOLDER = "upload" - private final String FILES_TO_UPLOAD = "files" - private final String ALL_FILES_TO_UPLOAD = "all" - public ArrayList specificFilesToUpload public ArrayList filesToUpload public PackageGenerator packageGenerator public String pathUpload + public String uploadPackagePath public String files public String option = 'y' - public final String YES_OPTION = 'y' public String all = Constants.FALSE /** * Sets description and group task */ Upload() { - super(DESCRIPTION_OF_TASK, Constants.DEPLOYMENT) + super(Constants.UPLOAD_DESCRIPTION, Constants.DEPLOYMENT) specificFilesToUpload = new ArrayList() packageGenerator = new PackageGenerator() filesToUpload = new ArrayList() @@ -50,24 +42,27 @@ class Upload extends Deployment { */ @Override void runTask() { - pathUpload = Paths.get(buildFolderPath, DIR_UPLOAD_FOLDER).toString() + pathUpload = Paths.get(buildFolderPath, Constants.DIR_UPLOAD_FOLDER).toString() + uploadPackagePath = Paths.get(pathUpload, PACKAGE_NAME).toString() createDeploymentDirectory(pathUpload) loadFilesChangedToUpload() loadParameter() loadAllFiles() if (specificFilesToUpload.empty && !Util.isValidProperty(project, EXCLUDES) && all == Constants.FALSE) { - logger.warn("${ALL_FILES_UPLOAD}${projectPath}") - option = System.console().readLine(QUESTION_CONTINUE) + logger.warn("${Constants.ALL_FILES_UPLOAD}${projectPath}") + option = System.console().readLine(Constants.QUESTION_CONTINUE) + } - if (option == YES_OPTION) { + if (option == Constants.YES_OPTION) { loadFiles() copyFilesToUpload() createPackage() truncate(pathUpload) + combinePackage(uploadPackagePath) executeDeploy(pathUpload) saveMapOfFilesChanged() } else { - logger.error(UPLOAD_CANCELED) + logger.error(Constants.UPLOAD_CANCELED) } } @@ -119,8 +114,8 @@ class Upload extends Deployment { * By default the 'all' variable has the value equals to false. */ void loadAllFiles() { - if (Util.isValidProperty(project, ALL_FILES_TO_UPLOAD) && !Util.isEmptyProperty(project, ALL_FILES_TO_UPLOAD)) { - all = project.properties[ALL_FILES_TO_UPLOAD].toString() + if (Util.isValidProperty(project, Constants.ALL_FILES_TO_UPLOAD) && !Util.isEmptyProperty(project, Constants.ALL_FILES_TO_UPLOAD)) { + all = project.properties[Constants.ALL_FILES_TO_UPLOAD].toString() } } @@ -128,8 +123,8 @@ class Upload extends Deployment { * Loads files that will be uploaded into specificFilesToUpload array. */ def loadParameter() { - if (Util.isValidProperty(project, FILES_TO_UPLOAD) && !Util.isEmptyProperty(project, FILES_TO_UPLOAD)) { - files = project.properties[FILES_TO_UPLOAD].toString() + if (Util.isValidProperty(project, Constants.FILES_TO_UPLOAD) && !Util.isEmptyProperty(project, Constants.FILES_TO_UPLOAD)) { + files = project.properties[Constants.FILES_TO_UPLOAD].toString() } ArrayList filesName = new ArrayList() if (files == null) { diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy index 72db853..ca9811d 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy @@ -44,7 +44,7 @@ public class Constants { public static final String DEPLOYING_CODE_SUCCESSFULLY = 'Code were successfully deployed' public static final String TRUNCATE_DEPRECATE_TURNED_OFF = 'truncate deprecate statement has been deactivated' public static final String TRUNCATE_CODE_TURNED_OFF = 'truncate code has been deactivated' - public static final String DESCRIPTION_OF_TASK = 'This task deploys all the project' + public static final String DEPLOY_DESCRIPTION = 'This task deploys all the project' public static final String FOLDERS_DEPLOY = "folders" public static final String FOLDER_DEPLOY = 'deploy' public static final String TURN_OFF_TRUNCATE = 'turnOffTruncate' @@ -54,4 +54,31 @@ public class Constants { public static final Integer NOT_FOUND = -1 public static final ArrayList FOLDERS_TO_TRUNCATE = ['classes', 'objects', 'triggers', 'pages', 'components', 'workflows'] + + //UnDeploy task constants + public static final String UN_DEPLOY_DESCRIPTION = 'This task removes all components in your organization according to local repository' + public static final String START_MESSAGE_TRUNCATE = 'Starting undeploy...' + public static final String SUCCESS_MESSAGE_TRUNCATE = 'All components truncated were successfully uploaded' + public static final String SUCCESS_MESSAGE_DELETE = 'The files were successfully deleted' + public static final String FILE_NAME_DESTRUCTIVE = "destructiveChanges.xml" + public static final String CUSTOM_FIELD_NAME = 'CustomField' + public static final String WORK_FLOW_RULE_NAME = 'WorkflowRule' + public static final String DIR_UN_DEPLOY = "undeploy" + public static final String LOOKUP_NAME = 'Lookup' + + //Upload task constants + public static final String UPLOAD_DESCRIPTION = "This task uploads all specific files or folders as user wants" + public static final String ALL_FILES_UPLOAD = "All files will be uploaded from: " + public static final String QUESTION_CONTINUE = " Do you want to continue? (y/n) :" + public static final String UPLOAD_CANCELED ='Upload all files was canceled!!' + public static final String DIR_UPLOAD_FOLDER = "upload" + public static final String FILES_TO_UPLOAD = "files" + public static final String ALL_FILES_TO_UPLOAD = "all" + public static final String YES_OPTION = 'y' + + //Update task constants + public static final String UPDATE_DESCRIPTION = "This task deploys just the files that were changed" + public static final String DIR_UPDATE_FOLDER = "update" + public static final String NOT_FILES_CHANGED = "There are not files changed" + } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombiner.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombiner.groovy index 09fb087..424e8ff 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombiner.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombiner.groovy @@ -34,10 +34,10 @@ class PackageCombiner { buildPackage.metaPackage.types.each { PackageTypeMembers type -> if (SUB_COMPONENTS.contains(type.name)) { - membersOfCustomField = type.members as ArrayList + membersOfCustomField.addAll(type.members as ArrayList) } if (type.name == CUSTOM_OBJECT) { - membersOfCustomObject = type.members as ArrayList + membersOfCustomObject.addAll(type.members as ArrayList) } } ArrayList membersToRemove = getMembersToDelete(membersOfCustomField, membersOfCustomObject) diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeployTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeployTest.groovy index c1c0b6b..fdb9645 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeployTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeployTest.groovy @@ -119,6 +119,7 @@ class DeployTest extends Specification { instanceDeploy.poll = 200 instanceDeploy.waitTime = 10 instanceDeploy.credential = credential + instanceDeploy.projectPackagePath = Paths.get(SRC_PATH, 'src', 'package.xml').toString() when: instanceDeploy.runTask() def packageXmlToDeployDirectory = new File(Paths.get(SRC_PATH, 'build', 'deploy', 'package.xml').toString()).text @@ -354,6 +355,7 @@ class DeployTest extends Specification { instanceDeploy.poll = 200 instanceDeploy.waitTime = 10 instanceDeploy.credential = credential + instanceDeploy.projectPackagePath = Paths.get(SRC_PATH, 'src', 'package.xml').toString() def deployFileZipPath = Paths.get(SRC_PATH,'build','deploy.zip').toString() def deployFolderPath = Paths.get(SRC_PATH,'build','deploy').toString() File deployFileZip = new File(deployFileZipPath) diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/UndeployTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/UndeployTest.groovy index a7d6e8d..611197e 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/UndeployTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/UndeployTest.groovy @@ -99,7 +99,6 @@ class UndeployTest extends Specification { def "Integration test should deploy truncate components"() { given: undeployInstance.createDeploymentDirectory(Paths.get(SRC_PATH, 'build').toString()) - def undeployDirectory = Paths.get(SRC_PATH, 'build', 'undeploy').toString() undeployInstance.unDeployPackagePath = Paths.get(undeployDirectory,'package.xml').toString() undeployInstance.filesToTruncate = [new File(Paths.get(SRC_PATH,'src', 'classes','Class1.cls').toString()), @@ -109,6 +108,7 @@ class UndeployTest extends Specification { undeployInstance.buildFolderPath = Paths.get(SRC_PATH, 'build').toString() undeployInstance.createDeploymentDirectory(undeployDirectory) undeployInstance.fileManager.copy(SRC_PATH, undeployInstance.filesToTruncate, undeployDirectory) + undeployInstance.projectPackagePath = Paths.get(SRC_PATH, 'src', 'package.xml').toString() undeployInstance.poll = 200 undeployInstance.waitTime = 10 undeployInstance.credential = credential @@ -135,6 +135,7 @@ class UndeployTest extends Specification { undeployInstance.projectPath = srcpath undeployInstance.createDeploymentDirectory(undeployDirectory) undeployInstance.setupFilesToUnDeploy() + undeployInstance.projectPackagePath = Paths.get(SRC_PATH, 'src', 'package.xml').toString() undeployInstance.smartFilesValidator = new SmartFilesValidator(undeployInstance.getJsonQueries()) undeployInstance.truncateFiles() Files.copy(Paths.get(SRC_PATH, 'src', 'package.xml' ), Paths.get(undeployDirectory, 'package.xml'), StandardCopyOption.REPLACE_EXISTING) @@ -165,6 +166,7 @@ class UndeployTest extends Specification { undeployInstance.poll = 200 undeployInstance.waitTime = 10 undeployInstance.credential = credential + undeployInstance.projectPackagePath = Paths.get(SRC_PATH, 'src', 'package.xml').toString() undeployInstance.executeDeploy(Paths.get(SRC_PATH, 'src').toString()) def destructiveExpect = "${""}${"Class1ApexClass"}${"Object1__cCustomObject"}${"Trigger1ApexTrigger"}${"32.0"}" def packageExpect = "${""}${""}${"32.0"}" diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/UpdateTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/UpdateTest.groovy index 690c767..401ddbf 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/UpdateTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/UpdateTest.groovy @@ -230,6 +230,7 @@ class UpdateTest extends Specification { componentSerializer.save(mapMock) updateInstance.buildFolderPath = Paths.get(SRC_PATH, 'build').toString() updateInstance.projectPath = Paths.get(SRC_PATH, 'src').toString() + updateInstance.projectPackagePath = Paths.get(SRC_PATH, 'src', 'package.xml').toString() def newFilePath = Paths.get(SRC_PATH, 'src', 'classes', 'Class2.cls').toString() def newXmlFilePath = Paths.get(SRC_PATH, 'src', 'classes', 'Class2.cls-meta.xml').toString() FileWriter newFile = new FileWriter(newFilePath) @@ -274,6 +275,7 @@ class UpdateTest extends Specification { updateInstance.credential = credential updateInstance.project.enforce.deleteTemporaryFiles = true componentMonitor.srcProject = Paths.get(SRC_PATH,'src').toString() + updateInstance.projectPackagePath = Paths.get(SRC_PATH, 'src', 'package.xml').toString() componentSerializer.sourcePath = Paths.get(SRC_PATH,'src','.fileTracker.data').toString() componentSerializer.save(componentMonitor.getComponentsSignature([])) def newTemporalClassPath = Paths.get(SRC_PATH, 'src', 'classes', 'Class2.cls').toString() From 9bf4def771696a111f9d0ed51821c0f9385be108 Mon Sep 17 00:00:00 2001 From: Marcelo Oporto Fernandez Date: Fri, 29 May 2015 11:09:09 -0400 Subject: [PATCH 05/50] Add new class Delete.groovy --- .../tasks/salesforce/deployment/Delete.groovy | 182 ++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy new file mode 100644 index 0000000..a9cf391 --- /dev/null +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy @@ -0,0 +1,182 @@ +/* + * Copyright (c) Fundacion Jala. All rights reserved. + * Licensed under the MIT license. See LICENSE file in the project root for full license information. + */ + +package org.fundacionjala.gradle.plugins.enforce.tasks.salesforce.deployment + +import org.fundacionjala.gradle.plugins.enforce.filemonitor.ComponentStates +import org.fundacionjala.gradle.plugins.enforce.utils.Constants +import org.fundacionjala.gradle.plugins.enforce.utils.Util +import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.PackageGenerator + +import java.nio.file.Paths + +/** + * Updates an org using metadata API + */ +class Delete extends Deployment { + private static final String DESCRIPTION_OF_TASK = "This task deploys just the files that were changed" + private final String FOLDERS_DEPLOY = "folders" + private final String DIR_UPDATE_FOLDER = "delete" + private final String FILE_NAME_DESTRUCTIVE = "destructiveChanges.xml" + private final String NOT_FILES_CHANGED = "There are not files changed" + public String pathUpdate + ArrayList filesToCopy + ArrayList filesToUpdate + String folders + ArrayList filesExcludes + PackageGenerator packageGenerator + + /** + * Sets description and group task + * @param description is description tasks + * @param group is the group typeName the task + */ + Delete() { + super(DESCRIPTION_OF_TASK, Constants.DEPLOYMENT) + filesToCopy = new ArrayList() + filesToUpdate = new ArrayList() + filesExcludes = new ArrayList() + packageGenerator = new PackageGenerator() + interceptorsToExecute = [org.fundacionjala.gradle.plugins.enforce.interceptor.Interceptor.REMOVE_DEPRECATE.id] + } + + /** + * Executes the task + */ + @Override + void runTask() { + pathUpdate = Paths.get(buildFolderPath, DIR_UPDATE_FOLDER).toString() + createDeploymentDirectory(pathUpdate) + loadFilesChanged() + verifyParameter() + + createDestructive() + createPackage() + copyFilesChanged() + // truncate(pathUpdate) + + /* executeDeploy(pathUpdate) + packageGenerator.saveFileTrackerMap()*/ + + } + + def truncate(String pathToTruncate) { + interceptorsToExecute += interceptors + truncateComponents(pathToTruncate) + } + + /** + * Creates packages to all files which has been changed + */ + def createPackage() { + println "\n** CreatePackage()" + println "fileTrackerMap : "+packageGenerator.fileTrackerMap + packageGenerator.fileTrackerMap.each { nameFile, resultTracker -> + println "-- "+resultTracker.state+ " == "+ComponentStates.DELETED + if (resultTracker.state == ComponentStates.DELETED) { + filesToCopy.add(new File(nameFile)) + } + } + println "filesToCopy : "+filesToCopy + packageGenerator.buildPackage(Paths.get(pathUpdate, PACKAGE_NAME).toString()) + } + + /** + * Creates package to all files which has been deleted + */ + def createDestructive() { + println "\n** CreateDestructive " + packageGenerator.buildDestructive(Paths.get(pathUpdate, FILE_NAME_DESTRUCTIVE).toString()) + } + + /** + * Loads all files which has been changed on filesChanged + */ + def loadFilesChanged() { + packageGenerator.init(projectPath, credential) + } + + /** + * Verifies if there is files changed in folders inserted by user + */ + def verifyParameter() { + if (Util.isValidProperty(project, "folders")) { + folders = project.folders + } + if (folders) { + ArrayList foldersName = folders.split(Constants.COMMA) + + ArrayList invalidFolders = Util.getInvalidFolders(foldersName) + validateFolders(foldersName) + if (!invalidFolders.empty) { + throw new Exception("${Constants.INVALID_FOLDER}: ${invalidFolders}") + } + ArrayList validatedFiles = fileManager.getValidElements(projectPath, excludeFilesToMonitor) + packageGenerator.listFileToDelete(foldersName,validatedFiles) + } + } + + /** + * Copies files using fileManager + */ + def copyFilesChanged() { + println "\n** CopyFilesChanged()" + println "filesCopy : "+filesToCopy + filesToCopy.each { file -> + File xmlFile = fileManager.getValidateXmlFile(file) + if (xmlFile) { + filesToUpdate.push(xmlFile) + } + filesToUpdate.push(file) + } + println "filesToUpdate : "+filesToUpdate + println "pathUpdate : "+pathUpdate + fileManager.copy(projectPath,filesToUpdate, pathUpdate) + } + + /** + * Prints files changed + */ + def showFilesChanged() { + if (packageGenerator.fileTrackerMap.size() > 0) { + logger.quiet("*********************************************") + logger.quiet(" Status Files Changed ") + logger.quiet("*********************************************") + packageGenerator.fileTrackerMap.each { nameFile, status -> + logger.quiet("${Paths.get(nameFile).getFileName().toString()}${" - "}${status.toString()}") + } + logger.quiet("*********************************************") + } + } + + /** + * Shows files excluded if there are more than five this shows just a message. + * @return + */ + def showFilesExcludes() { + if (filesExcludes.empty) { + return + } + if (filesExcludes.size() < 5) { + logger.quiet("*********************************************") + logger.quiet(" Files excluded ") + logger.quiet("*********************************************") + filesExcludes.each { File file -> + logger.quiet("${file.getName()}${" - "} excluded") + } + logger.quiet("*********************************************") + } else { + logger.quiet("${filesExcludes.size()}${' files were excluded\n'}") + } + } + + /** + * ExcludeFiles from filesExcludes map + */ + private void excludeFilesFromFilesChanged() { + ArrayList filesFiltered = excludeFiles(packageGenerator.getFiles()) + filesExcludes = packageGenerator.excludeFiles(filesFiltered) + } +} \ No newline at end of file From 583f46bd734b11d47443b6108859c51f196790b5 Mon Sep 17 00:00:00 2001 From: Navor Nunez Date: Fri, 29 May 2015 13:51:24 -0400 Subject: [PATCH 06/50] Improve progress bar - Now processed files and percent are displayed. - Deploy status is displayed to cover pending and canceled statuses. --- .../enforce/wsc/InspectorResults.groovy | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy index 6ade6c0..51dddc0 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy @@ -6,6 +6,7 @@ package org.fundacionjala.gradle.plugins.enforce.wsc import com.sforce.soap.metadata.DeployResult +import com.sforce.soap.metadata.DeployStatus import com.sforce.soap.metadata.MetadataConnection import com.sforce.soap.metadata.RetrieveResult import org.fundacionjala.gradle.plugins.enforce.utils.Constants @@ -37,19 +38,21 @@ class InspectorResults { * @throws Exception if an request timed out or could not retrieve the metadata */ public DeployResult waitForDeployResult(String asyncResultId, int maxPolls, int waitTimeMilliSecs) throws Exception { - int poll = Constants.ZERO - DeployResult deployResult = metadataConnection.checkDeployStatus(asyncResultId, true) + DeployResult deployResult = null + int poll = Constants.ZERO int percent = Constants.ZERO - percent = getDeployPercentage(deployResult) - writePercent(percent) - while (!deployResult.isDone()) { - if (poll++ > maxPolls) { - throw new Exception(TIMEOUT_EXCEPTION) + while ((null == deployResult) || !deployResult.isDone()) { + if (null != deployResult) { + if (poll++ > maxPolls) { + throw new Exception(TIMEOUT_EXCEPTION) + } + Thread.sleep(waitTimeMilliSecs) } - Thread.sleep(waitTimeMilliSecs) deployResult = metadataConnection.checkDeployStatus(asyncResultId, true) - percent = getDeployPercentage(deployResult) - writePercent(percent) + if (percent != HUNDRED) { + percent = getDeployPercentage(deployResult) + } + writePercent(percent, deployResult) if (percent == HUNDRED && deployResult.done) { break } @@ -86,18 +89,21 @@ class InspectorResults { return (int)percent } - public void writePercent(int percent) { - StringBuilder progressBar = new StringBuilder("[") - - for (int i = Constants.ZERO; i < END_VAL_PROGRESS_BAR; i++) { - if (i < (percent / 2)) { - progressBar.append("=") - } else { - progressBar.append(" ") + public void writePercent(int percent, DeployResult deployResult) { + if (DeployStatus.InProgress == deployResult.status) { + StringBuilder progressBar = new StringBuilder("[") + for (int i = Constants.ZERO; i < END_VAL_PROGRESS_BAR; i++) { + if (i < (percent / 2)) { + progressBar.append("=") + } else { + progressBar.append(" ") + } } + progressBar.append("] ${deployResult.numberComponentsDeployed}/${deployResult.numberComponentsTotal}(${percent}%)"); + outputStream.write("\r${progressBar.toString()}".getBytes(Charset.forName("UTF-8"))) + } else { + outputStream.write(Util.getBytes("\r\nDeploy Status: ${deployResult.status}...", "UTF-8")) } - progressBar.append("] " + percent + "% "); - outputStream.write("\r${progressBar.toString()}".getBytes(Charset.forName("UTF-8"))) outputStream.flush() } } From 51740ca7b03a20d5a6bf5a6fe472bfe73ccc4e65 Mon Sep 17 00:00:00 2001 From: marco_cadima Date: Fri, 29 May 2015 15:47:43 -0400 Subject: [PATCH 07/50] Delete object member from CustomObject and CustomField is covered --- .../utils/salesforce/PackageCombiner.groovy | 63 ++++++++++++++++--- .../salesforce/PackageCombinerTest.groovy | 43 +++++++++++++ 2 files changed, 97 insertions(+), 9 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombiner.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombiner.groovy index 424e8ff..5d948be 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombiner.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombiner.groovy @@ -4,11 +4,11 @@ import com.sforce.soap.metadata.PackageTypeMembers import org.fundacionjala.gradle.plugins.enforce.utils.Constants import org.fundacionjala.gradle.plugins.enforce.utils.Util -import java.nio.file.Paths - class PackageCombiner { private static final ArrayList SUB_COMPONENTS = ['CustomField', 'FieldSet', 'ValidationRule', - 'CompactLayout', 'SharingReason'] + 'CompactLayout', 'SharingReason', 'RecordType', 'WebLink', + 'SharingRecalculation', 'SearchLayout', 'ListView', + 'HistoryRetentionPolicy', 'BusinessProcess', 'ActionOverride'] //RecordType //WebLink //SharingRecalculation @@ -46,6 +46,20 @@ class PackageCombiner { } } + /** + * Gets a map with name and its members + * @param buildPackage is of type PackageBuilder + * @return a map + */ + private static Map> getMembersByNameType(PackageBuilder buildPackage) { + Map> membersByNameType = [:] + + buildPackage.metaPackage.types.each { PackageTypeMembers type -> + membersByNameType.put(type.name as String, type.members as ArrayList) + } + return membersByNameType + } + /** * Removes components from package xml file * @param packagePath is package path @@ -57,11 +71,11 @@ class PackageCombiner { packageBuilder.read(packageFileReader) Map> componentToDelete = [:] - excludedFiles.each {String fileName -> + excludedFiles.each { String fileName -> String componentType = getComponentType(fileName) String componentName = getComponentName(fileName) - if (!componentToDelete.containsKey(componentType)){ + if (!componentToDelete.containsKey(componentType)) { componentToDelete.put(componentType, [componentName]) } @@ -70,12 +84,14 @@ class PackageCombiner { componentToDelete.get(componentType).push(componentName) } String parentName = Util.getFirstPath(componentName) - if(parentName != componentName) { + if (parentName != componentName) { componentToDelete.get(componentType).push(parentName) } } - componentToDelete.each {String componentType, ArrayList componentNames -> + Map> components = getComponentsToDelete(componentToDelete, packageBuilder) + + components.each { String componentType, ArrayList componentNames -> packageBuilder.removeMembers(componentType, componentNames) } @@ -83,6 +99,35 @@ class PackageCombiner { packageBuilder.write(fileWriter) } + /** + * Gets components to delete with its sub components + * @param componentToDelete is a map with components to delete + * @param componentsFromPackage is a map with all components from package xml file + * @return a map with components that will delete + */ + private static Map> getComponentsToDelete(Map> componentToDelete, + PackageBuilder packageBuilder) { + + Map> components = componentToDelete.clone() + Map> componentsFromPackage = getMembersByNameType(packageBuilder) + + componentsFromPackage.each { String Name, ArrayList members -> + if (SUB_COMPONENTS.contains(Name)) { + members.each { String member -> + String objectName = member.substring(0, member.indexOf('.')) + if (components.get(CUSTOM_OBJECT).contains(objectName)) { + if (!components.containsKey(Name)) { + components.put(Name, [member]) + } else { + components.get(Name).push(member) + } + } + } + } + } + return components + } + /** * Gets a component name without extension * @param fileName is component name @@ -91,7 +136,7 @@ class PackageCombiner { private static String getComponentName(String fileName) { String componentName = fileName if (fileName.contains(Constants.SLASH)) { - componentName = fileName.substring( fileName.indexOf(Constants.SLASH) + 1, fileName.length()) + componentName = fileName.substring(fileName.indexOf(Constants.SLASH) + 1, fileName.length()) } if (!componentName.contains(Constants.SLASH)) { componentName = Util.getFileName(componentName) @@ -138,7 +183,7 @@ class PackageCombiner { */ private static ArrayList getMembersToDelete(ArrayList membersOfCustomField, ArrayList membersOfCustomObject) { ArrayList membersToRemove = new ArrayList() - membersOfCustomField.each {String customFieldMember -> + membersOfCustomField.each { String customFieldMember -> String objectName = customFieldMember.substring(0, customFieldMember.indexOf('.')) if (membersOfCustomObject.contains(objectName)) { membersToRemove.add(objectName) diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombinerTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombinerTest.groovy index ea1377f..2574a57 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombinerTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombinerTest.groovy @@ -204,11 +204,54 @@ class PackageCombinerTest extends Specification { xmlDiff.similar() } + def 'Test should remove CustomField subcomponent from package xml file'() { + given: + String packagePath = Paths.get(SRC_PATH, 'packageTestField.xml') + String packageContent = ''' + + + Object1__c.MyCustomField1__c + Object1__c.MyCustomField2__c + Object2__c.MyCustomField2__c + CustomField + + + Object1__c.MyFieldSet1__c + Object2__c.MyFieldSet2__c + FieldSet + + 32.0 + + ''' + File packageFile = new File(packagePath) + packageFile.write(packageContent) + String packageExpect = ''' + + + Object2__c.MyCustomField2__c + CustomField + + + Object2__c.MyFieldSet2__c + FieldSet + + 32.0 + + ''' + when: + PackageCombiner.removeMembersFromPackage(packagePath, ['objects/Object1__c.object']) + XMLUnit.ignoreWhitespace = true + def xmlDiff = new Diff(packageFile.text, packageExpect) + then: + xmlDiff.similar() + } + def cleanupSpec() { new File(Paths.get(SRC_PATH, 'projectPackage.xml').toString()).delete() new File(Paths.get(SRC_PATH, 'buildPackage.xml').toString()).delete() new File(Paths.get(SRC_PATH, 'packageTest.xml').toString()).delete() new File(Paths.get(SRC_PATH, 'packageTestDocument.xml').toString()).delete() new File(Paths.get(SRC_PATH, 'packageTestReport.xml').toString()).delete() + new File(Paths.get(SRC_PATH, 'packageTestField.xml').toString()).delete() } } From 88c2e26a3594a492d80a74ea7c6e947a76b18f02 Mon Sep 17 00:00:00 2001 From: Alex Ventura Date: Fri, 29 May 2015 16:21:54 -0400 Subject: [PATCH 08/50] changed the literal text by MetadataComponets definition --- .../component/validators/SalesforceValidatorManager.groovy | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidatorManager.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidatorManager.groovy index 80af631..36e6f66 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidatorManager.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidatorManager.groovy @@ -1,11 +1,14 @@ package org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators + +import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.MetadataComponents + /** * Manages the different kind of validate a file * based in Salesforce definitions */ public class SalesforceValidatorManager { private static Map validatorMap = [ - 'documents': new DocumentSalesforceValidator() + MetadataComponents.DOCUMENTS.getDirectory(): new DocumentSalesforceValidator() ] /** From 09f95a24ebdd08aaa9be33f515fe87197159e989 Mon Sep 17 00:00:00 2001 From: Alex Ventura Date: Mon, 1 Jun 2015 09:16:41 -0400 Subject: [PATCH 09/50] changed the literal string to constants defined in Metadatacomponets --- .../validators/SalesforceValidatorManager.groovy | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidatorManager.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidatorManager.groovy index 36e6f66..c4e11d8 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidatorManager.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/SalesforceValidatorManager.groovy @@ -1,5 +1,6 @@ package org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators +import org.codehaus.groovy.runtime.GStringImpl import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.MetadataComponents /** @@ -8,7 +9,7 @@ import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.MetadataCompone */ public class SalesforceValidatorManager { private static Map validatorMap = [ - MetadataComponents.DOCUMENTS.getDirectory(): new DocumentSalesforceValidator() + "${MetadataComponents.DOCUMENTS.getDirectory()}": new DocumentSalesforceValidator() ] /** @@ -16,8 +17,9 @@ public class SalesforceValidatorManager { * defined in Salesforce */ public static SalesforceValidator getValidator(String folderName) { - if (validatorMap.containsKey(folderName)) { - return validatorMap.get(folderName) + GStringImpl key = "${folderName}" + if (validatorMap.containsKey(key)) { + return validatorMap.get(key) } return new FileSalesforceValidator() } From 9861a8786a4cb01669c60fd54dfe18781cd145c0 Mon Sep 17 00:00:00 2001 From: Marco Cadima Date: Mon, 1 Jun 2015 11:58:31 -0400 Subject: [PATCH 10/50] Code review observations were applied --- .../utils/salesforce/PackageCombiner.groovy | 11 ++++++----- .../salesforce/deployment/DeployTest.groovy | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombiner.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombiner.groovy index 5d948be..6d68e41 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombiner.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombiner.groovy @@ -9,6 +9,7 @@ class PackageCombiner { 'CompactLayout', 'SharingReason', 'RecordType', 'WebLink', 'SharingRecalculation', 'SearchLayout', 'ListView', 'HistoryRetentionPolicy', 'BusinessProcess', 'ActionOverride'] + //The next sub components are part of custom objects: //RecordType //WebLink //SharingRecalculation @@ -111,15 +112,15 @@ class PackageCombiner { Map> components = componentToDelete.clone() Map> componentsFromPackage = getMembersByNameType(packageBuilder) - componentsFromPackage.each { String Name, ArrayList members -> - if (SUB_COMPONENTS.contains(Name)) { + componentsFromPackage.each { String name, ArrayList members -> + if (SUB_COMPONENTS.contains(name)) { members.each { String member -> String objectName = member.substring(0, member.indexOf('.')) if (components.get(CUSTOM_OBJECT).contains(objectName)) { - if (!components.containsKey(Name)) { - components.put(Name, [member]) + if (!components.containsKey(name)) { + components.put(name, [member]) } else { - components.get(Name).push(member) + components.get(name).push(member) } } } diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeployTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeployTest.groovy index fdb9645..f258bb0 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeployTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeployTest.groovy @@ -375,37 +375,44 @@ class DeployTest extends Specification { ArrayList result = instanceDeploy.getFilesExcludes(criterion) then: result.size() == 1 - result[0] == "classes/class1.cls" + result[0] == "classes${File.separator}class1.cls" } def "Test should return objects that were excluded"() { given: String criterion = "objects" instanceDeploy.projectPath = SRC_PATH + String object2 = "objects${File.separator}Object2__c.object" + String object1 = "objects${File.separator}Object1__c.object" + String object3 = "objects${File.separator}Account.object" when: ArrayList result = instanceDeploy.getFilesExcludes(criterion) then: - result.sort() == ["objects/Object2__c.object", "objects/Account.object", "objects/Object1__c.object"].sort() + result.sort() == [object1, object2, object3].sort() } def "Test should return Account object that were excluded"() { given: String criterion = "**/Account.object" instanceDeploy.projectPath = SRC_PATH + String accountObject1 = "objects${File.separator}Account.object" + String accountObject2 = "src${File.separator}objects${File.separator}Account.object" when: ArrayList result = instanceDeploy.getFilesExcludes(criterion) then: - result.sort() == ["objects/Account.object", "src/objects/Account.object"].sort() + result.sort() == [accountObject1, accountObject2].sort() } def "Test should return Document component that was excluded"() { given: String criterion = "documents" instanceDeploy.projectPath = SRC_PATH + String document1 = "documents${File.separator}myDocuments${File.separator}doc.txt" + String document2 = "documents${File.separator}myDocuments${File.separator}doc2.txt" when: ArrayList result = instanceDeploy.getFilesExcludes(criterion) then: - result.sort() == ["documents/myDocuments/doc.txt", "documents/myDocuments/doc2.txt"].sort() + result.sort() == [document1, document2].sort() } def "Test should return Report component that was excluded"() { @@ -415,7 +422,7 @@ class DeployTest extends Specification { when: ArrayList result = instanceDeploy.getFilesExcludes(criterion) then: - result.sort() == ["reports/myreports/reportTest.report"].sort() + result.sort() == ["reports${File.separator}myreports${File.separator}reportTest.report"].sort() } def cleanupSpec() { From 1c6fb82e2d801c674ff8661818a7146fb6731988 Mon Sep 17 00:00:00 2001 From: Marcelo Oporto Fernandez Date: Mon, 1 Jun 2015 18:29:00 -0400 Subject: [PATCH 11/50] Start feature Create a new delete task --- .../plugins/enforce/EnforcePlugin.groovy | 2 + .../tasks/salesforce/deployment/Delete.groovy | 103 +++--------- .../utils/salesforce/PackageGenerator.groovy | 21 +++ .../salesforce/deployment/DeleteTest.groovy | 152 ++++++++++++++++++ 4 files changed, 199 insertions(+), 79 deletions(-) create mode 100644 src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/EnforcePlugin.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/EnforcePlugin.groovy index 622a18e..ef91db2 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/EnforcePlugin.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/EnforcePlugin.groovy @@ -13,6 +13,7 @@ import org.fundacionjala.gradle.plugins.enforce.tasks.salesforce.deployment.Depl import org.fundacionjala.gradle.plugins.enforce.tasks.salesforce.deployment.Undeploy import org.fundacionjala.gradle.plugins.enforce.tasks.salesforce.deployment.Update import org.fundacionjala.gradle.plugins.enforce.tasks.salesforce.deployment.Upload +import org.fundacionjala.gradle.plugins.enforce.tasks.salesforce.deployment.Delete import org.fundacionjala.gradle.plugins.enforce.tasks.salesforce.execute.ApexExecutor import org.fundacionjala.gradle.plugins.enforce.tasks.salesforce.managepackage.InstallPackageTask import org.fundacionjala.gradle.plugins.enforce.tasks.salesforce.managepackage.UninstallPackageTask @@ -49,6 +50,7 @@ class EnforcePlugin implements Plugin { project.task('undeploy', type: Undeploy) project.task('update', type: Update) project.task('upload', type: Upload) + project.task('delete', type: Delete) project.task("addCredential", type: CredentialAdder) project.task("updateCredential", type: CredentialUpdater) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy index a9cf391..4d6c648 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy @@ -17,12 +17,10 @@ import java.nio.file.Paths */ class Delete extends Deployment { private static final String DESCRIPTION_OF_TASK = "This task deploys just the files that were changed" - private final String FOLDERS_DEPLOY = "folders" - private final String DIR_UPDATE_FOLDER = "delete" + private final String DIR_DELETE_FOLDER = "delete" + private static final String PARAMETER_FOLDERS= "folders" private final String FILE_NAME_DESTRUCTIVE = "destructiveChanges.xml" - private final String NOT_FILES_CHANGED = "There are not files changed" public String pathUpdate - ArrayList filesToCopy ArrayList filesToUpdate String folders ArrayList filesExcludes @@ -35,7 +33,6 @@ class Delete extends Deployment { */ Delete() { super(DESCRIPTION_OF_TASK, Constants.DEPLOYMENT) - filesToCopy = new ArrayList() filesToUpdate = new ArrayList() filesExcludes = new ArrayList() packageGenerator = new PackageGenerator() @@ -47,19 +44,14 @@ class Delete extends Deployment { */ @Override void runTask() { - pathUpdate = Paths.get(buildFolderPath, DIR_UPDATE_FOLDER).toString() + pathUpdate = Paths.get(buildFolderPath, DIR_DELETE_FOLDER).toString() createDeploymentDirectory(pathUpdate) loadFilesChanged() verifyParameter() - + excludeFilesFromFilesChanged() createDestructive() createPackage() - copyFilesChanged() - // truncate(pathUpdate) - - /* executeDeploy(pathUpdate) - packageGenerator.saveFileTrackerMap()*/ - +// executeDeploy(pathUpdate) } def truncate(String pathToTruncate) { @@ -71,15 +63,6 @@ class Delete extends Deployment { * Creates packages to all files which has been changed */ def createPackage() { - println "\n** CreatePackage()" - println "fileTrackerMap : "+packageGenerator.fileTrackerMap - packageGenerator.fileTrackerMap.each { nameFile, resultTracker -> - println "-- "+resultTracker.state+ " == "+ComponentStates.DELETED - if (resultTracker.state == ComponentStates.DELETED) { - filesToCopy.add(new File(nameFile)) - } - } - println "filesToCopy : "+filesToCopy packageGenerator.buildPackage(Paths.get(pathUpdate, PACKAGE_NAME).toString()) } @@ -87,8 +70,13 @@ class Delete extends Deployment { * Creates package to all files which has been deleted */ def createDestructive() { - println "\n** CreateDestructive " - packageGenerator.buildDestructive(Paths.get(pathUpdate, FILE_NAME_DESTRUCTIVE).toString()) + ArrayList files = new ArrayList(); + packageGenerator.fileTrackerMap.each { nameFile, resultTracker -> + if (resultTracker.state == ComponentStates.DELETED) { + files.add(new File(Paths.get(projectPath, nameFile).toString())) + } + } + writePackage(Paths.get(pathUpdate, FILE_NAME_DESTRUCTIVE).toString(), files) } /** @@ -102,9 +90,13 @@ class Delete extends Deployment { * Verifies if there is files changed in folders inserted by user */ def verifyParameter() { - if (Util.isValidProperty(project, "folders")) { + println "|*| : "+project + println "|*| : "+Util.isValidProperty(project, PARAMETER_FOLDERS) + if (Util.isValidProperty(project, PARAMETER_FOLDERS)) { folders = project.folders } + println "|*| : "+folders + ArrayList validatedFiles if (folders) { ArrayList foldersName = folders.split(Constants.COMMA) @@ -113,63 +105,11 @@ class Delete extends Deployment { if (!invalidFolders.empty) { throw new Exception("${Constants.INVALID_FOLDER}: ${invalidFolders}") } - ArrayList validatedFiles = fileManager.getValidElements(projectPath, excludeFilesToMonitor) + validatedFiles = fileManager.getValidElements(projectPath, excludeFilesToMonitor) packageGenerator.listFileToDelete(foldersName,validatedFiles) } - } - /** - * Copies files using fileManager - */ - def copyFilesChanged() { - println "\n** CopyFilesChanged()" - println "filesCopy : "+filesToCopy - filesToCopy.each { file -> - File xmlFile = fileManager.getValidateXmlFile(file) - if (xmlFile) { - filesToUpdate.push(xmlFile) - } - filesToUpdate.push(file) - } - println "filesToUpdate : "+filesToUpdate - println "pathUpdate : "+pathUpdate - fileManager.copy(projectPath,filesToUpdate, pathUpdate) - } - - /** - * Prints files changed - */ - def showFilesChanged() { - if (packageGenerator.fileTrackerMap.size() > 0) { - logger.quiet("*********************************************") - logger.quiet(" Status Files Changed ") - logger.quiet("*********************************************") - packageGenerator.fileTrackerMap.each { nameFile, status -> - logger.quiet("${Paths.get(nameFile).getFileName().toString()}${" - "}${status.toString()}") - } - logger.quiet("*********************************************") - } - } - - /** - * Shows files excluded if there are more than five this shows just a message. - * @return - */ - def showFilesExcludes() { - if (filesExcludes.empty) { - return - } - if (filesExcludes.size() < 5) { - logger.quiet("*********************************************") - logger.quiet(" Files excluded ") - logger.quiet("*********************************************") - filesExcludes.each { File file -> - logger.quiet("${file.getName()}${" - "} excluded") - } - logger.quiet("*********************************************") - } else { - logger.quiet("${filesExcludes.size()}${' files were excluded\n'}") - } + println "File to delete : "+packageGenerator.fileTrackerMap } /** @@ -177,6 +117,11 @@ class Delete extends Deployment { */ private void excludeFilesFromFilesChanged() { ArrayList filesFiltered = excludeFiles(packageGenerator.getFiles()) + filesFiltered.add(new File("classes/Class2.cls")) filesExcludes = packageGenerator.excludeFiles(filesFiltered) + println "\nFile to exclude : "+filesFiltered + println "File to exclude : "+filesExcludes } + + } \ No newline at end of file diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageGenerator.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageGenerator.groovy index e790391..82f6c72 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageGenerator.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageGenerator.groovy @@ -23,6 +23,13 @@ class PackageGenerator { componentMonitor = new ComponentMonitor() } + public void init(String projectPath, Credential credential) { + this.projectPath = projectPath + this.credential = credential + componentMonitor = new ComponentMonitor(projectPath) + } + + public void init(String projectPath, ArrayList files, Credential credential) { this.projectPath = projectPath this.credential = credential @@ -107,6 +114,20 @@ class PackageGenerator { fileTrackerMap = componentMonitor.getFoldersFiltered(folders, fileTrackerMap) } + public void listFileToDelete(ArrayList folders,ArrayList files) { + Map foldersFiltered = [:] + + files.each { file -> + String parentFile = file.getParentFile().getName() + folders.each { nameFolder -> + if (parentFile == nameFolder) { + foldersFiltered.put(Paths.get(parentFile,file.getName().toString()).toString(), new ResultTracker(ComponentStates.DELETED)) + } + } + } + fileTrackerMap = foldersFiltered; + } + public ArrayList excludeFiles(ArrayList files) { Map fileTrackerMapClone = fileTrackerMap.clone() as Map ArrayList excludedFiles = [] diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy new file mode 100644 index 0000000..737b480 --- /dev/null +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy @@ -0,0 +1,152 @@ +/* + * Copyright (c) Fundacion Jala. All rights reserved. + * Licensed under the MIT license. See LICENSE file in the project root for full license information. + */ + +package org.fundacionjala.gradle.plugins.enforce.tasks.salesforce.deployment + +import org.fundacionjala.gradle.plugins.enforce.EnforcePlugin +import org.fundacionjala.gradle.plugins.enforce.filemonitor.ComponentMonitor +import org.fundacionjala.gradle.plugins.enforce.filemonitor.ComponentSerializer +import org.fundacionjala.gradle.plugins.enforce.metadata.DeployMetadata +import org.fundacionjala.gradle.plugins.enforce.utils.ManagementFile +import org.fundacionjala.gradle.plugins.enforce.wsc.Credential +import org.fundacionjala.gradle.plugins.enforce.wsc.LoginType +import org.fundacionjala.gradle.plugins.enforce.wsc.rest.ToolingAPI +import org.fundacionjala.gradle.plugins.enforce.wsc.soap.ApexAPI +import org.gradle.api.Project +import org.gradle.testfixtures.ProjectBuilder +import spock.lang.Shared +import spock.lang.Specification + +import java.nio.file.Paths + +class DeleteTest extends Specification { + @Shared + Project project + + @Shared + def deleteInstance + + @Shared + def SRC_PATH = Paths.get(System.getProperty("user.dir"), "src", "test", "groovy", "org", + "fundacionjala", "gradle", "plugins","enforce","tasks", "salesforce", "resources").toString() + + @Shared + Credential credential + + @Shared + ComponentSerializer componentSerializer + + @Shared + ComponentMonitor componentMonitor + + def setup() { + project = ProjectBuilder.builder().build() + project.apply(plugin: EnforcePlugin) + project.enforce.srcPath = SRC_PATH + deleteInstance = project.tasks.delete + deleteInstance.fileManager = new ManagementFile(SRC_PATH) + deleteInstance.project.enforce.deleteTemporaryFiles = false + deleteInstance.createDeploymentDirectory(Paths.get(SRC_PATH, 'build').toString()) + deleteInstance.createDeploymentDirectory(Paths.get(SRC_PATH, 'build', 'delete').toString()) + deleteInstance.projectPath = SRC_PATH + def fileTrackerPath = Paths.get(SRC_PATH,'.fileTracker.data').toString() + componentSerializer = new ComponentSerializer(fileTrackerPath) + componentMonitor = new ComponentMonitor(SRC_PATH) + + def class1 = new File(Paths.get(SRC_PATH, 'classes', 'class1.cls').toString()) + def class1Cls = new File(Paths.get(SRC_PATH, 'src', 'classes', 'Class1.cls').toString()) + def class1ClsXml = new File(Paths.get(SRC_PATH, 'src', 'classes', 'Class1.cls-meta.xml').toString()) + def object1__c = new File(Paths.get(SRC_PATH, 'src', 'objects', 'Object1__c.object').toString()) + def account = new File(Paths.get(SRC_PATH, 'src', 'objects', 'Account.object').toString()) + def trigger = new File(Paths.get(SRC_PATH, 'src', 'triggers', 'Trigger1.trigger').toString()) + def triggerXml = new File(Paths.get(SRC_PATH, 'src', 'triggers', 'Trigger1.trigger-meta.xml').toString()) + + def mapMock = componentMonitor.getComponentsSignature([class1, class1Cls, class1ClsXml, object1__c, object1__c, account, trigger, triggerXml]) + componentSerializer.save(mapMock) + + credential = new Credential() + credential.id = 'id' + credential.username = 'salesforce2014.test@gmail.com' + credential.password = '123qwe2014' + credential.token = 'UO1Jx5vDQl97xCKkwXBH8tg3T' + credential.loginFormat = LoginType.DEV.value() + credential.type = 'normal' + } + + def "Integration testing must create two files for the next test"() { + given: + deleteInstance.packageGenerator.fileTrackerMap = [:] + deleteInstance.buildFolderPath = Paths.get(SRC_PATH, 'build').toString() + deleteInstance.projectPath = Paths.get(SRC_PATH, 'src').toString() + deleteInstance.componentDeploy = new DeployMetadata() + deleteInstance.poll = 200 + deleteInstance.waitTime = 10 + deleteInstance.credential = credential + deleteInstance.project.enforce.deleteTemporaryFiles = true + componentMonitor.srcProject = Paths.get(SRC_PATH,'src').toString() + componentSerializer.save(componentMonitor.getComponentsSignature([])) + + def newTemporalClassPath2 = Paths.get(SRC_PATH, 'src', 'classes', 'Class2.cls').toString() + def newTemporalXmlPath2 = Paths.get(SRC_PATH, 'src', 'classes', 'Class2.cls-meta.xml').toString() + def newTemporalClassPath3 = Paths.get(SRC_PATH, 'src', 'classes', 'Class3.cls').toString() + def newTemporalXmlPath3 = Paths.get(SRC_PATH, 'src', 'classes', 'Class3.cls-meta.xml').toString() + + FileWriter writerClass2 = new FileWriter(newTemporalClassPath2) + FileWriter writerXml2 = new FileWriter(newTemporalXmlPath2) + FileWriter writerClass3 = new FileWriter(newTemporalClassPath3) + FileWriter writerXml3 = new FileWriter(newTemporalXmlPath3) + + def contentTemporalClass2 = "public with sharing class Class2 {public Class2(Integer a, Integer b){ }}" + def contentTemporalClass3 = "public with sharing class Class2 {public Class3(Integer a, Integer b){ }}" + def contentTemporalXml2 = "${""}${""}${"24.0Active"}" + def contentTemporalXml3 = "${""}${""}${"24.0Active"}" + + writerClass2.write(contentTemporalClass2) + writerClass3.write(contentTemporalClass3) + writerXml2.write(contentTemporalXml2) + writerXml3.write(contentTemporalXml3) + + writerClass2.close() + writerClass3.close() + writerXml2.close() + writerXml3.close() + + File fileClass2 = new File(newTemporalClassPath2) + File fileClass3 = new File(newTemporalClassPath3) + File fileXML2 = new File(newTemporalXmlPath2) + File fileXML3 = new File(newTemporalXmlPath3) + + ToolingAPI toolingAPI + ApexAPI apexAPI + String jsonByClasses + String jsonCoverageLines + String jsonByTriggers + deleteInstance.folders = "classes" + String QUERY_CLASSES = "SELECT Name FROM ApexPage" + toolingAPI = new ToolingAPI(credential) + apexAPI = new ApexAPI(credential) + jsonByClasses = toolingAPI.httpAPIClient.executeQuery(QUERY_CLASSES) + + println "Js : "+jsonByClasses + + when: + deleteInstance.runTask() + then: + fileClass2.exists() + fileClass3.exists() + fileXML2.exists() + fileXML3.exists() + } + + def cleanupSpec() { + new File(Paths.get(SRC_PATH, 'build').toString()).deleteDir() + new File(Paths.get(SRC_PATH, 'classes', 'Class2.cls').toString()).delete() + new File(Paths.get(SRC_PATH, 'src', 'classes', 'Class2.cls').toString()).delete() + new File(Paths.get(SRC_PATH, 'src', 'classes', 'Class2.cls-meta.xml').toString()).delete() + new File(Paths.get(SRC_PATH, 'src', 'classes', 'Class3.cls').toString()).delete() + new File(Paths.get(SRC_PATH, 'src', 'classes', 'Class3.cls-meta.xml').toString()).delete() + new File(Paths.get(SRC_PATH, 'src', '.fileTracker.data').toString()).delete() + } +} \ No newline at end of file From 824c178fd0d24721a68810a9e47ab0dc26d2b110 Mon Sep 17 00:00:00 2001 From: Rodrigo Ruiz Date: Mon, 1 Jun 2015 22:00:05 -0400 Subject: [PATCH 12/50] enhancement to delete temporary files on retrieve task and use unzip method of gradle --- .../tasks/salesforce/SalesforceTask.groovy | 82 ++++++++++++++++++- .../salesforce/deployment/Deployment.groovy | 37 +-------- .../salesforce/retrieve/Retrieval.groovy | 2 +- .../tasks/salesforce/retrieve/Retrieve.groovy | 3 +- .../plugins/enforce/utils/Constants.groovy | 3 + 5 files changed, 88 insertions(+), 39 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy index d3bc1d6..1b24872 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy @@ -16,6 +16,8 @@ import org.fundacionjala.gradle.plugins.enforce.utils.Util import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.PackageBuilder import org.fundacionjala.gradle.plugins.enforce.wsc.Credential import org.gradle.api.GradleException +import org.gradle.api.tasks.Copy +import org.gradle.api.tasks.bundling.Zip import java.nio.file.Paths @@ -23,6 +25,7 @@ import java.nio.file.Paths * Base class for deployment tasks */ abstract class SalesforceTask extends ForceTask { + private final String NAME_TASK_ZIP = "createZip" private final String CREDENTIAL_NAME = "credentials.dat" private final String SAVE_PACKAGE_ERROR = "path package not defined, you need prepare package first" private final String UPDATE_PACKAGE_ERROR = "you need to prepare package first" @@ -140,7 +143,84 @@ abstract class SalesforceTask extends ForceTask { } File file = new File(pathPackage) packageBuilder.update(nameOfType, members, file) - } + } + + + + /** + * Creates a zip file + * @param destination is folder where will create zip + * @param fileName is name of file zip + * @param sourcePath is folder will compress + * @return a path zip was created + */ + String createZip(String sourcePath, String destination, String fileName) { + File folderDestination = new File(destination) + + if (!folderDestination.exists()) { + throw new Exception("Cannot find the folder: $destination ") + } + + String fileNameZip = "${fileName}.zip" + File fileZip = new File(Paths.get(destination, fileNameZip).toString()) + if (fileZip.exists()) { + fileZip.delete() + } + + project.task(NAME_TASK_ZIP, type: Zip, overwrite: true) { + destinationDir new File(destination) + archiveName fileNameZip + from sourcePath + }.execute() + + return fileZip.getAbsolutePath() + } + + /** + * Unzips a file to specific destination + * @param zipPath the file zip path + * @param folderUnZip the folder where will be unzipped + */ + public void unZip(String zipPath, String folderUnZip) { + project.copy { + def zipFile = project.file(zipPath) + def outputDir = project.file(folderUnZip) + from project.zipTree(zipFile) + into outputDir + } + } + + /** + * Deletes a directory excluding another specific directory + * @param dirToDelete the directory to delete + * @param dirToExclude the directory to exclude + */ + public void deleteDir(String dirToDelete, String dirToExclude){ + String tempDirPath = System.getProperty(Constants.TEMP_DIR_PATH) + def tempDir = new File(Paths.get(tempDirPath,"${Constants.TEMP_FOLDER_NAME}${Long.toString(System.nanoTime())}").toString()) + if(!tempDir.mkdir()){ + throw new IOException("Could not create temp directory: ${tempDir.getAbsolutePath()}"); + } + project.copy { + from dirToExclude + into tempDir.absolutePath + } + project.delete project.files(dirToDelete) + project.copy { + from tempDir.absolutePath + into dirToExclude + } + } + + /** + * Deletes all temporary files excluding the log files + */ + public void deleteTemporaryFiles(){ + if(project.enforce.deleteTemporaryFiles) { + deleteDir(buildFolderPath, Paths.get(buildFolderPath, Constants.LOGS_FOLDER_NAME).toString()) + } + } + /** * Load credential, gets version api and execute the method run diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy index 41c736f..4f52f3f 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy @@ -21,7 +21,6 @@ import java.nio.file.Paths */ abstract class Deployment extends SalesforceTask { - private final String NAME_TASK_ZIP = "createZip" DeployMetadata componentDeploy InterceptorManager componentManager List interceptorsToExecute = [] @@ -59,12 +58,7 @@ abstract class Deployment extends SalesforceTask { componentDeploy.setPath(pathZipToDeploy) logger.debug('Deploying components') componentDeploy.deploy(poll, waitTime, credential) - if(project.enforce.deleteTemporaryFiles) { - def deleteZipFile = new File(pathZipToDeploy) - def deleteFolder = new File(sourcePath) - deleteZipFile.delete() - deleteFolder.deleteDir() - } + deleteTemporaryFiles() } /** @@ -111,35 +105,6 @@ abstract class Deployment extends SalesforceTask { fileManager.createNewDirectory(pathDirectory) } - /** - * Creates a zip file - * @param destination is folder where will create zip - * @param fileName is name of file zip - * @param sourcePath is folder will compress - * @return a path zip was created - */ - String createZip(String sourcePath, String destination, String fileName) { - File folderDestination = new File(destination) - - if (!folderDestination.exists()) { - throw new Exception("Cannot find the folder: $destination ") - } - - String fileNameZip = "${fileName}.zip" - File fileZip = new File(Paths.get(destination, fileNameZip).toString()) - if (fileZip.exists()) { - fileZip.delete() - } - - project.task(NAME_TASK_ZIP, type: Zip, overwrite: true) { - destinationDir new File(destination) - archiveName fileNameZip - from sourcePath - }.execute() - - return fileZip.getAbsolutePath() - } - /** * Excludes file or files using criterion * @param files to exclude diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/retrieve/Retrieval.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/retrieve/Retrieval.groovy index 7be7c1a..c0c736a 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/retrieve/Retrieval.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/retrieve/Retrieval.groovy @@ -49,7 +49,7 @@ abstract class Retrieval extends SalesforceTask { void saveOnDiskFileUnzipped(byte[] zipFile) { ZipFileManager zipFileManager = new ZipFileManager() zipFileManager.flushZipFile(zipFile, buildFolderPath, ZIP_FILE_NAME) - zipFileManager.unzipZipRetrieved(Paths.get(buildFolderPath, ZIP_FILE_NAME).toString(), buildFolderPath) + unZip(Paths.get(buildFolderPath, ZIP_FILE_NAME).toString(), buildFolderPath) } /** diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/retrieve/Retrieve.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/retrieve/Retrieve.groovy index 9c9da61..5ed2ff1 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/retrieve/Retrieve.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/retrieve/Retrieve.groovy @@ -20,7 +20,7 @@ import java.nio.file.Paths class Retrieve extends Retrieval { private static final String GROUP_OF_TASK = "Retrieve" private static final String DESCRIPTION_OF_TASK = 'This task recover specific files from an organization' - private static final String MESSAGE_WARNING = 'Warning: All files according to package will be downloaded' + private static final String MESSAGE_WARNING = 'Warning: All files will be downloaded according to the package' private static final String MESSAGE_CANCELED = 'Retrieve task was canceled!!' private static final String QUESTION_TO_CONTINUE = 'Do you want to continue? (y/n) : ' private final String FILES_RETRIEVE = 'files' @@ -69,6 +69,7 @@ class Retrieve extends Retrieval { } retrieveWithPackageXml() } + deleteTemporaryFiles() } /** diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy index 6bb3a5d..0cc6e9b 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy @@ -27,6 +27,9 @@ public class Constants { public static final String UNSUPPORTED_FOLDERS = "unsupported folders" public static final String JENKINS_CHART_NAME = "Code coverage" public static final String FALSE = "false" + public static final String TEMP_DIR_PATH = "java.io.tmpdir" + public static final String TEMP_FOLDER_NAME = "temp_enforce" + public static final String LOGS_FOLDER_NAME = "logs" public static final int ZERO = 0 From 8a0c250e7161a9d12e5e3052881d25a88dc667eb Mon Sep 17 00:00:00 2001 From: Rodrigo Ruiz Date: Tue, 2 Jun 2015 09:10:04 -0400 Subject: [PATCH 13/50] merge from develop --- .../enforce/tasks/salesforce/deployment/Deployment.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy index 357b725..71f7e9f 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy @@ -11,6 +11,7 @@ import org.fundacionjala.gradle.plugins.enforce.tasks.salesforce.SalesforceTask import org.fundacionjala.gradle.plugins.enforce.utils.Constants import org.fundacionjala.gradle.plugins.enforce.utils.Util import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.MetadataComponents +import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.PackageCombiner import org.gradle.api.file.FileTree import org.gradle.api.tasks.bundling.Zip From eb4ffee428375d86d98e66c1ad5e247f3388bcf6 Mon Sep 17 00:00:00 2001 From: Rodrigo Ruiz Date: Tue, 2 Jun 2015 14:55:33 -0400 Subject: [PATCH 14/50] deleteDir method was improved --- .../tasks/salesforce/SalesforceTask.groovy | 27 +++++++++++-------- .../enforce/utils/ManagementFile.groovy | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy index 6661fa2..3a8e510 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy @@ -197,19 +197,24 @@ abstract class SalesforceTask extends ForceTask { * @param dirToExclude the directory to exclude */ public void deleteDir(String dirToDelete, String dirToExclude){ - String tempDirPath = System.getProperty(Constants.TEMP_DIR_PATH) - def tempDir = new File(Paths.get(tempDirPath,"${Constants.TEMP_FOLDER_NAME}${Long.toString(System.nanoTime())}").toString()) - if(!tempDir.mkdir()){ - throw new IOException("Could not create temp directory: ${tempDir.getAbsolutePath()}"); - } - project.copy { - from dirToExclude - into tempDir.absolutePath + File dirExcluded = new File(dirToExclude) + if(dirExcluded.exists()) { + String tempDirPath = System.getProperty(Constants.TEMP_DIR_PATH) + def tempDir = new File(Paths.get(tempDirPath, "${Constants.TEMP_FOLDER_NAME}${Long.toString(System.nanoTime())}").toString()) + if (!tempDir.mkdir()) { + throw new IOException("Could not create temp directory: ${tempDir.getAbsolutePath()}"); + } + project.copy { + from dirToExclude + into tempDir.absolutePath + } } project.delete project.files(dirToDelete) - project.copy { - from tempDir.absolutePath - into dirToExclude + if(dirExcluded.exists()) { + project.copy { + from tempDir.absolutePath + into dirToExclude + } } } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy index 19a2fd3..827a9b0 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy @@ -214,7 +214,7 @@ class ManagementFile { if (dir.exists()) { dir.deleteDir() } - dir.mkdir() + dir.mkdirs() } /** From 9939a4b2fe822ab5634f4f8e478ec69613f3bdfe Mon Sep 17 00:00:00 2001 From: Rodrigo Ruiz Date: Tue, 2 Jun 2015 16:08:56 -0400 Subject: [PATCH 15/50] class Salesforce was reformatted --- .../tasks/salesforce/SalesforceTask.groovy | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy index 3a8e510..8ffc56f 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy @@ -16,7 +16,6 @@ import org.fundacionjala.gradle.plugins.enforce.utils.Util import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.PackageBuilder import org.fundacionjala.gradle.plugins.enforce.wsc.Credential import org.gradle.api.GradleException -import org.gradle.api.tasks.Copy import org.gradle.api.tasks.bundling.Zip import java.nio.file.Paths @@ -105,7 +104,7 @@ abstract class SalesforceTask extends ForceTask { */ void writePackage(String packagePath, ArrayList files) { FileWriter fileWriter = new FileWriter(packagePath) - files = files.grep({ file-> + files = files.grep({ file -> !file.name.endsWith(Constants.META_XML_NAME) }) packageBuilder.createPackage(files, projectPath) @@ -122,13 +121,13 @@ abstract class SalesforceTask extends ForceTask { this.packageLoaded = packagePath packageBuilder.createPackage(files, projectPath) } - + /** * Saves package created */ void savePackage() { if (!this.packageLoaded) { - throw new DeployException(SAVE_PACKAGE_ERROR,[]) + throw new DeployException(SAVE_PACKAGE_ERROR, []) } FileWriter fileWriter = new FileWriter(this.packageLoaded) packageBuilder.write(fileWriter) @@ -138,7 +137,7 @@ abstract class SalesforceTask extends ForceTask { /** * Updates the package prepared */ - void updatePackage(String nameOfType,ArrayList members, String pathPackage) { + void updatePackage(String nameOfType, ArrayList members, String pathPackage) { if (packageBuilder == null && !this.packageLoaded) { throw new DeployException(UPDATE_PACKAGE_ERROR, []) } @@ -146,8 +145,6 @@ abstract class SalesforceTask extends ForceTask { packageBuilder.update(nameOfType, members, file) } - - /** * Creates a zip file * @param destination is folder where will create zip @@ -196,9 +193,9 @@ abstract class SalesforceTask extends ForceTask { * @param dirToDelete the directory to delete * @param dirToExclude the directory to exclude */ - public void deleteDir(String dirToDelete, String dirToExclude){ + public void deleteDir(String dirToDelete, String dirToExclude) { File dirExcluded = new File(dirToExclude) - if(dirExcluded.exists()) { + if (dirExcluded.exists()) { String tempDirPath = System.getProperty(Constants.TEMP_DIR_PATH) def tempDir = new File(Paths.get(tempDirPath, "${Constants.TEMP_FOLDER_NAME}${Long.toString(System.nanoTime())}").toString()) if (!tempDir.mkdir()) { @@ -210,7 +207,7 @@ abstract class SalesforceTask extends ForceTask { } } project.delete project.files(dirToDelete) - if(dirExcluded.exists()) { + if (dirExcluded.exists()) { project.copy { from tempDir.absolutePath into dirToExclude @@ -221,13 +218,12 @@ abstract class SalesforceTask extends ForceTask { /** * Deletes all temporary files excluding the log files */ - public void deleteTemporaryFiles(){ - if(project.enforce.deleteTemporaryFiles) { + public void deleteTemporaryFiles() { + if (project.enforce.deleteTemporaryFiles) { deleteDir(buildFolderPath, Paths.get(buildFolderPath, Constants.LOGS_FOLDER_NAME).toString()) } } - /** * Load credential, gets version api and execute the method run */ From e5dfe4f1d7937eba3aed2a838901e78a1d709177 Mon Sep 17 00:00:00 2001 From: Rodrigo Ruiz Date: Tue, 2 Jun 2015 16:46:28 -0400 Subject: [PATCH 16/50] removed console.log of index.html --- src/main/resources/index.html | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/resources/index.html b/src/main/resources/index.html index 027b2d7..4e96f46 100644 --- a/src/main/resources/index.html +++ b/src/main/resources/index.html @@ -108,7 +108,6 @@ \$scope.detailsByTest = function(id) { for (var i = 0; i < \$scope.filesClone.length ; i++) { var file = \$scope.filesClone[i]; - console.log(file); if (file.id === id) { var details = file.status == "Fail"?file.details.slice(0):[] return details; From a7bb523795b0053e079a5526b52ecb580967bec7 Mon Sep 17 00:00:00 2001 From: Rodrigo Ruiz Date: Tue, 2 Jun 2015 17:17:34 -0400 Subject: [PATCH 17/50] EnforceExtension plugin was reformatted --- .../gradle/plugins/enforce/EnforcePluginExtension.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/EnforcePluginExtension.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/EnforcePluginExtension.groovy index fa86110..9eb2418 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/EnforcePluginExtension.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/EnforcePluginExtension.groovy @@ -39,7 +39,7 @@ class EnforcePluginExtension { Map> interceptors - EnforcePluginExtension(){ + EnforcePluginExtension() { interceptors = [:] } From 26340b370142dc720ec1924869e8067c791b49a5 Mon Sep 17 00:00:00 2001 From: Alex Ventura Date: Wed, 3 Jun 2015 10:51:54 -0400 Subject: [PATCH 18/50] thrown an exception when deployResult has failed --- .../gradle/plugins/enforce/wsc/InspectorResults.groovy | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy index 6ade6c0..098f090 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy @@ -6,6 +6,7 @@ package org.fundacionjala.gradle.plugins.enforce.wsc import com.sforce.soap.metadata.DeployResult +import com.sforce.soap.metadata.DeployStatus import com.sforce.soap.metadata.MetadataConnection import com.sforce.soap.metadata.RetrieveResult import org.fundacionjala.gradle.plugins.enforce.utils.Constants @@ -48,6 +49,10 @@ class InspectorResults { } Thread.sleep(waitTimeMilliSecs) deployResult = metadataConnection.checkDeployStatus(asyncResultId, true) + if (deployResult.status == DeployStatus.Failed) { + String message = deployResult.errorMessage + '\n\n' + deployResult.stateDetail + throw new Exception(message) + } percent = getDeployPercentage(deployResult) writePercent(percent) if (percent == HUNDRED && deployResult.done) { From 3bdfdaa99376c604bbbb3267d0f25fa123c2dd27 Mon Sep 17 00:00:00 2001 From: Rodrigo Ruiz Date: Wed, 3 Jun 2015 11:50:53 -0400 Subject: [PATCH 19/50] Code review comments were applied --- .../tasks/salesforce/SalesforceTask.groovy | 29 +++++++++---------- .../tasks/salesforce/retrieve/Retrieve.groovy | 12 +++----- .../plugins/enforce/utils/Constants.groovy | 9 ++++++ 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy index 8ffc56f..5f60dcd 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy @@ -194,24 +194,21 @@ abstract class SalesforceTask extends ForceTask { * @param dirToExclude the directory to exclude */ public void deleteDir(String dirToDelete, String dirToExclude) { - File dirExcluded = new File(dirToExclude) - if (dirExcluded.exists()) { - String tempDirPath = System.getProperty(Constants.TEMP_DIR_PATH) - def tempDir = new File(Paths.get(tempDirPath, "${Constants.TEMP_FOLDER_NAME}${Long.toString(System.nanoTime())}").toString()) - if (!tempDir.mkdir()) { - throw new IOException("Could not create temp directory: ${tempDir.getAbsolutePath()}"); - } - project.copy { - from dirToExclude - into tempDir.absolutePath - } + String tempDirPath = System.getProperty(Constants.TEMP_DIR_PATH) + File tempDir = new File(Paths.get(tempDirPath, "${Constants.TEMP_FOLDER_NAME}${Long.toString(System.nanoTime())}").toString()) + + if (!tempDir.mkdir()) { + throw new IOException("${Constants.IO_MESSAGE_TEMP_DIR}: ${tempDir.getAbsolutePath()}"); + } + project.copy { + from dirToExclude + into tempDir.absolutePath } + project.delete project.files(dirToDelete) - if (dirExcluded.exists()) { - project.copy { - from tempDir.absolutePath - into dirToExclude - } + project.copy { + from tempDir.absolutePath + into dirToExclude } } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/retrieve/Retrieve.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/retrieve/Retrieve.groovy index 5ed2ff1..e7d03c6 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/retrieve/Retrieve.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/retrieve/Retrieve.groovy @@ -19,10 +19,6 @@ import java.nio.file.Paths */ class Retrieve extends Retrieval { private static final String GROUP_OF_TASK = "Retrieve" - private static final String DESCRIPTION_OF_TASK = 'This task recover specific files from an organization' - private static final String MESSAGE_WARNING = 'Warning: All files will be downloaded according to the package' - private static final String MESSAGE_CANCELED = 'Retrieve task was canceled!!' - private static final String QUESTION_TO_CONTINUE = 'Do you want to continue? (y/n) : ' private final String FILES_RETRIEVE = 'files' private final String DESTINATION_FOLDER = 'destination' private final String ALL_PARAMETER = 'all' @@ -43,7 +39,7 @@ class Retrieve extends Retrieval { * @param group is the group typeName the task */ Retrieve() { - super(DESCRIPTION_OF_TASK, GROUP_OF_TASK) + super(Constants.RETRIEVE_DESCRIPTION_OF_TASK, GROUP_OF_TASK) } @Override @@ -63,7 +59,7 @@ class Retrieve extends Retrieval { if (option == YES) { loadFromPackage() } else { - logger.warn(MESSAGE_CANCELED) + logger.warn(Constants.RETRIEVE_MESSAGE_CANCELED) System.exit(CODE_TO_EXIT) } } @@ -276,8 +272,8 @@ class Retrieve extends Retrieval { void showWarningMessage() { File[] arrayFiles = getFiles(new File(projectPath)) if (arrayFiles.size() > 0 && all == Constants.FALSE) { - logger.error(MESSAGE_WARNING) - option = System.console().readLine("${' '}${QUESTION_TO_CONTINUE}") + logger.error(Constants.RETRIEVE_MESSAGE_WARNING) + option = System.console().readLine("${' '}${Constants.RETRIEVE_QUESTION_TO_CONTINUE}") } else { option = YES } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy index 4f49fa5..4d71a50 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy @@ -58,6 +58,9 @@ public class Constants { public static final ArrayList FOLDERS_TO_TRUNCATE = ['classes', 'objects', 'triggers', 'pages', 'components', 'workflows'] + //I/O constants + public static final String IO_MESSAGE_TEMP_DIR = 'Could not create temp directory' + //UnDeploy task constants public static final String UN_DEPLOY_DESCRIPTION = 'This task removes all components in your organization according to local repository' public static final String START_MESSAGE_TRUNCATE = 'Starting undeploy...' @@ -84,4 +87,10 @@ public class Constants { public static final String DIR_UPDATE_FOLDER = "update" public static final String NOT_FILES_CHANGED = "There are not files changed" + //Retrieve task constants + public static final String RETRIEVE_DESCRIPTION_OF_TASK = 'This task recover specific files from an organization' + public static final String RETRIEVE_MESSAGE_WARNING = 'Warning: All files will be downloaded according to the package' + public static final String RETRIEVE_MESSAGE_CANCELED = 'Retrieve task was canceled!!' + public static final String RETRIEVE_QUESTION_TO_CONTINUE = 'Do you want to continue? (y/n) : ' + } From 1c0a5e2caa83890cdb723dee77d88cfa7487f635 Mon Sep 17 00:00:00 2001 From: Navor Nunez Date: Wed, 3 Jun 2015 13:57:33 -0400 Subject: [PATCH 20/50] Updated expected deploy statuses to display the progress bar. --- .../gradle/plugins/enforce/wsc/InspectorResults.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy index 51dddc0..23ef625 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy @@ -90,7 +90,7 @@ class InspectorResults { } public void writePercent(int percent, DeployResult deployResult) { - if (DeployStatus.InProgress == deployResult.status) { + if ((DeployStatus.InProgress == deployResult.status) || (DeployStatus.Succeeded == deployResult.status)) { StringBuilder progressBar = new StringBuilder("[") for (int i = Constants.ZERO; i < END_VAL_PROGRESS_BAR; i++) { if (i < (percent / 2)) { From 321788b94d1aba0c1c4f00bf57e3c0b5c1d7245a Mon Sep 17 00:00:00 2001 From: marco_cadima Date: Thu, 4 Jun 2015 17:08:02 -0400 Subject: [PATCH 21/50] Update task now take in account package xml file from project directory --- .../tasks/salesforce/deployment/Deploy.groovy | 5 +- .../salesforce/deployment/Deployment.groovy | 11 + .../salesforce/deployment/Undeploy.groovy | 2 +- .../tasks/salesforce/deployment/Update.groovy | 15 +- .../tasks/salesforce/deployment/Upload.groovy | 2 +- .../gradle/plugins/enforce/utils/Util.groovy | 10 + .../utils/salesforce/PackageCombiner.groovy | 180 +++++++++----- .../salesforce/deployment/UpdateTest.groovy | 8 + .../salesforce/deployment/UploadTest.groovy | 2 + .../plugins/enforce/utils/UtilTest.groovy | 7 + .../salesforce/PackageCombinerTest.groovy | 226 ++++++++++++++++++ 11 files changed, 398 insertions(+), 70 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deploy.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deploy.groovy index 4e09660..3a5a3cb 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deploy.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deploy.groovy @@ -74,6 +74,7 @@ class Deploy extends Deployment { filesByFolders = excludeFiles(filesByFolders) fileManager.copy(projectPath, filesByFolders, folderDeploy) writePackage(deployPackagePath, filesByFolders) + combinePackageToUpdate(deployPackagePath) deployToSalesForce() } } @@ -108,17 +109,18 @@ class Deploy extends Deployment { fileManager.copy(projectPath, filesToTruncate, folderDeploy) logger.debug('Generating package') writePackage(deployPackagePath, filesToTruncate) + combinePackage(deployPackagePath) truncateComponents() componentDeploy.startMessage = Constants.DEPLOYING_TRUNCATED_CODE componentDeploy.successMessage = Constants.DEPLOYING_TRUNCATED_CODE_SUCCESSFULLY logger.debug("Deploying to truncate components from: $folderDeploy") - combinePackage(deployPackagePath) executeDeploy(folderDeploy) createDeploymentDirectory(folderDeploy) } ArrayList filteredFiles = excludeFiles(fileManager.getValidElements(projectPath)) fileManager.copy(projectPath, filteredFiles, folderDeploy) writePackage(deployPackagePath, filteredFiles) + combinePackage(deployPackagePath) componentDeploy.startMessage = Constants.DEPLOYING_CODE componentDeploy.successMessage = Constants.DEPLOYING_CODE_SUCCESSFULLY deployToSalesForce() @@ -153,7 +155,6 @@ class Deploy extends Deployment { truncateComponents(folderDeploy) } logger.debug("Deploying all components from: $folderDeploy") - combinePackage(deployPackagePath) executeDeploy(folderDeploy) updateFileTracker() } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy index 71f7e9f..c146938 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy @@ -287,4 +287,15 @@ abstract class Deployment extends SalesforceTask { PackageCombiner.removeMembersFromPackage(buildPackagePath, getFilesExcludes(excludes)) } } + + /** + * Combines package from build folder and package from source directory + * @return + */ + def combinePackageToUpdate(String buildPackagePath) { + PackageCombiner.packageCombineToUpdate(projectPackagePath, buildPackagePath) + if (excludes) { + PackageCombiner.removeMembersFromPackage(buildPackagePath, getFilesExcludes(excludes)) + } + } } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Undeploy.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Undeploy.groovy index 32cb366..7d77c65 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Undeploy.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Undeploy.groovy @@ -104,9 +104,9 @@ class Undeploy extends Deployment { */ def deployTruncatedComponents() { writePackage(unDeployPackagePath, filesToTruncate) + combinePackage(unDeployPackagePath) componentDeploy.startMessage = Constants.START_MESSAGE_TRUNCATE componentDeploy.successMessage = Constants.SUCCESS_MESSAGE_TRUNCATE - combinePackage(unDeployPackagePath) executeDeploy(folderUnDeploy) } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Update.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Update.groovy index 337eef1..fd012ad 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Update.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Update.groovy @@ -8,6 +8,7 @@ package org.fundacionjala.gradle.plugins.enforce.tasks.salesforce.deployment import org.fundacionjala.gradle.plugins.enforce.filemonitor.ComponentStates import org.fundacionjala.gradle.plugins.enforce.utils.Constants import org.fundacionjala.gradle.plugins.enforce.utils.Util +import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.PackageCombiner import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.PackageGenerator import java.nio.file.Paths @@ -58,15 +59,14 @@ class Update extends Deployment { createPackage() copyFilesChanged() showFilesExcludes() - truncate(pathUpdate) - combinePackage(updatePackagePath) + truncate() executeDeploy(pathUpdate) packageGenerator.saveFileTrackerMap() } - def truncate(String pathToTruncate) { + def truncate() { interceptorsToExecute += interceptors - truncateComponents(pathToTruncate) + truncateComponents(pathUpdate) } /** @@ -78,14 +78,17 @@ class Update extends Deployment { filesToCopy.add(new File(Paths.get(projectPath, nameFile).toString())) } } - packageGenerator.buildPackage(Paths.get(pathUpdate, PACKAGE_NAME).toString()) + packageGenerator.buildPackage(updatePackagePath) + combinePackageToUpdate(updatePackagePath) } /** * Creates package to all files which has been deleted */ def createDestructive() { - packageGenerator.buildDestructive(Paths.get(pathUpdate, Constants.FILE_NAME_DESTRUCTIVE).toString()) + String destructivePath = Paths.get(pathUpdate, Constants.FILE_NAME_DESTRUCTIVE).toString() + packageGenerator.buildDestructive(destructivePath) + combinePackageToUpdate(destructivePath) } /** diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Upload.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Upload.groovy index 8ba8b0b..265536c 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Upload.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Upload.groovy @@ -58,7 +58,6 @@ class Upload extends Deployment { copyFilesToUpload() createPackage() truncate(pathUpload) - combinePackage(uploadPackagePath) executeDeploy(pathUpload) saveMapOfFilesChanged() } else { @@ -162,6 +161,7 @@ class Upload extends Deployment { public void createPackage() { if (!specificFilesToUpload.empty) { writePackage(Paths.get(pathUpload, PACKAGE_NAME).toString(), specificFilesToUpload) + combinePackageToUpdate(uploadPackagePath) } } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Util.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Util.groovy index 4a73091..f6bb61b 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Util.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Util.groovy @@ -249,4 +249,14 @@ class Util { public static String getFirstPath(String path) { return Paths.get(path).getName(ZERO_NUMBER_PATH) } + + /** + * Gets a object name from sub component member + * @param subComponentMember is a sub component member + * @return a object name + */ + public static String getObjectName(String subComponentMember) { + String objectName = subComponentMember.substring(0, subComponentMember.indexOf('.')) + return objectName + } } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombiner.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombiner.groovy index 6d68e41..6edacc6 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombiner.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombiner.groovy @@ -6,20 +6,12 @@ import org.fundacionjala.gradle.plugins.enforce.utils.Util class PackageCombiner { private static final ArrayList SUB_COMPONENTS = ['CustomField', 'FieldSet', 'ValidationRule', - 'CompactLayout', 'SharingReason', 'RecordType', 'WebLink', - 'SharingRecalculation', 'SearchLayout', 'ListView', - 'HistoryRetentionPolicy', 'BusinessProcess', 'ActionOverride'] - //The next sub components are part of custom objects: - //RecordType - //WebLink - //SharingRecalculation - //SearchLayout - //ListView - //HistoryRetentionPolicy - //BusinessProcess - //ActionOverride + 'CompactLayout', 'SharingReason', 'RecordType', + 'WebLink', 'SharingRecalculation', 'SearchLayout', + 'ListView', 'HistoryRetentionPolicy', 'BusinessProcess', + 'ActionOverride'] + private static final ArrayList COMPONENTS_WITH_SUB_FOLDERS = ['Document', 'Report', 'Dashboard'] private static final String CUSTOM_OBJECT = 'CustomObject' - private static final String ASTERISK = '*' /** * Combines package generated into build directory with package from project directory @@ -27,38 +19,13 @@ class PackageCombiner { * @param buildPackagePath is a path of package from build directory */ public static void packageCombine(String projectPackagePath, String buildPackagePath) { - if (new File(projectPackagePath).exists()) { + File packageFile = new File(projectPackagePath) + if (packageFile.exists()) { PackageBuilder buildPackage = mergePackage(projectPackagePath, buildPackagePath) - - ArrayList membersOfCustomField = new ArrayList() - ArrayList membersOfCustomObject = new ArrayList() - - buildPackage.metaPackage.types.each { PackageTypeMembers type -> - if (SUB_COMPONENTS.contains(type.name)) { - membersOfCustomField.addAll(type.members as ArrayList) - } - if (type.name == CUSTOM_OBJECT) { - membersOfCustomObject.addAll(type.members as ArrayList) - } - } - ArrayList membersToRemove = getMembersToDelete(membersOfCustomField, membersOfCustomObject) + ArrayList membersToRemove = getObjectMembersToDelete(buildPackage) buildPackage.removeMembers(CUSTOM_OBJECT, membersToRemove) - writePackageCombined(buildPackage, buildPackagePath) - } - } - - /** - * Gets a map with name and its members - * @param buildPackage is of type PackageBuilder - * @return a map - */ - private static Map> getMembersByNameType(PackageBuilder buildPackage) { - Map> membersByNameType = [:] - - buildPackage.metaPackage.types.each { PackageTypeMembers type -> - membersByNameType.put(type.name as String, type.members as ArrayList) + writePackage(buildPackage, buildPackagePath) } - return membersByNameType } /** @@ -90,14 +57,106 @@ class PackageCombiner { } } - Map> components = getComponentsToDelete(componentToDelete, packageBuilder) + Map> components = [:] + + if (componentToDelete.containsKey(CUSTOM_OBJECT)) { + components = getComponentsToDelete(componentToDelete, packageBuilder) + } else { + components = componentToDelete + } components.each { String componentType, ArrayList componentNames -> packageBuilder.removeMembers(componentType, componentNames) } + writePackage(packageBuilder, packagePath) + } - FileWriter fileWriter = new FileWriter(packagePath) - packageBuilder.write(fileWriter) + /** + * Combines package file from build directory with package from project directory + * @param projectPackagePath is the path of package from project directory + * @param buildPackagePath is the path of package from build directory + */ + public static void packageCombineToUpdate(String projectPackagePath, String buildPackagePath) { + PackageBuilder packageFromBuildFolder = getPackageBuilder(buildPackagePath) + PackageBuilder packageFromSourceFolder = getPackageBuilder(projectPackagePath) + Map > membersByNameOfPackageBuild = getMembersByNameType(packageFromBuildFolder) + ArrayList objectToDelete = [] + + getMembersByNameType(packageFromSourceFolder).each { String name, ArrayList members -> + if (COMPONENTS_WITH_SUB_FOLDERS.contains(name) && membersByNameOfPackageBuild.containsKey(name)) { + packageFromBuildFolder.removeMembers(name, membersByNameOfPackageBuild.get(name)) + packageFromBuildFolder.update(name, members) + } + + if (SUB_COMPONENTS.contains(name) && membersByNameOfPackageBuild.containsKey(CUSTOM_OBJECT)) { + members.each { String member -> + String objectName = Util.getObjectName(member) + if (membersByNameOfPackageBuild.get(CUSTOM_OBJECT).contains(objectName)) { + packageFromBuildFolder.update(name, [member]) + objectToDelete.push(objectName) + } + } + } + } + + packageFromBuildFolder.removeMembers(CUSTOM_OBJECT, objectToDelete) + writePackage(packageFromBuildFolder, buildPackagePath) + } + + /** + * Gets an instance of PackageBuilder class + * @param packagePath is package path + * @return an instance of PackageBuilder class + */ + private static PackageBuilder getPackageBuilder(String packagePath) { + PackageBuilder packageBuilder = new PackageBuilder() + FileReader packageBuilderReader = new FileReader(packagePath) + packageBuilder.read(packageBuilderReader) + return packageBuilder + } + + /** + * Gets members of SubComponents + * @param packageBuilder is of type PackageBuilder + * @return an ArrayList with members of subComponents + */ + private static ArrayList getMembersOfSubComponents(PackageBuilder packageBuilder) { + ArrayList membersOfSubComponent = new ArrayList() + packageBuilder.metaPackage.types.each { PackageTypeMembers type -> + if (SUB_COMPONENTS.contains(type.name)) { + membersOfSubComponent.addAll(type.members as ArrayList) + } + } + return membersOfSubComponent + } + + /** + * Gets an array list of members of objects component + * @param packageBuilder is type packageBuilder + * @return an ArrayList with members of objects + */ + private static ArrayList getMembersOfComponent(PackageBuilder packageBuilder, String componentType) { + ArrayList membersOfCustomObject = new ArrayList() + packageBuilder.metaPackage.types.each { PackageTypeMembers type -> + if (type.name == componentType) { + membersOfCustomObject.addAll(type.members as ArrayList) + } + } + return membersOfCustomObject + } + + /** + * Gets a map with name and its members + * @param packageBuilder is of type PackageBuilder + * @return a map + */ + private static Map> getMembersByNameType(PackageBuilder packageBuilder) { + Map> membersByNameType = [:] + + packageBuilder.metaPackage.types.each { PackageTypeMembers type -> + membersByNameType.put(type.name as String, type.members as ArrayList) + } + return membersByNameType } /** @@ -115,7 +174,7 @@ class PackageCombiner { componentsFromPackage.each { String name, ArrayList members -> if (SUB_COMPONENTS.contains(name)) { members.each { String member -> - String objectName = member.substring(0, member.indexOf('.')) + String objectName = Util.getObjectName(member) if (components.get(CUSTOM_OBJECT).contains(objectName)) { if (!components.containsKey(name)) { components.put(name, [member]) @@ -162,14 +221,14 @@ class PackageCombiner { * @return a PackageBuilder object merged */ private static PackageBuilder mergePackage(String projectPackagePath, String buildPackagePath) { - PackageBuilder projectPackage = new PackageBuilder() - PackageBuilder buildPackage = new PackageBuilder() - - projectPackage.read(new FileReader(projectPackagePath)) - buildPackage.read(new FileReader(buildPackagePath)) + PackageBuilder projectPackage = getPackageBuilder(projectPackagePath) + PackageBuilder buildPackage = getPackageBuilder(buildPackagePath) projectPackage.metaPackage.types.each { PackageTypeMembers type -> - if (!type.members.toList().contains(ASTERISK)) { + if (!type.members.toList().contains(Constants.WILDCARD)) { + buildPackage.metaPackage.types.each { PackageTypeMembers buildType -> + buildPackage.removeMembers(type.name as String, buildType.members as ArrayList) + } buildPackage.update(type.name as String, type.members as ArrayList) } } @@ -182,25 +241,26 @@ class PackageCombiner { * @param membersOfCustomObject is a list of members of custom object * @return an ArrayList with members that will delete */ - private static ArrayList getMembersToDelete(ArrayList membersOfCustomField, ArrayList membersOfCustomObject) { + private static ArrayList getObjectMembersToDelete(PackageBuilder packageBuilder) { + ArrayList membersOfCustomObject = getMembersOfComponent(packageBuilder, CUSTOM_OBJECT) ArrayList membersToRemove = new ArrayList() - membersOfCustomField.each { String customFieldMember -> - String objectName = customFieldMember.substring(0, customFieldMember.indexOf('.')) + getMembersOfSubComponents(packageBuilder).each { String customFieldMember -> + String objectName = Util.getObjectName(customFieldMember) if (membersOfCustomObject.contains(objectName)) { membersToRemove.add(objectName) } } - return membersToRemove + return membersToRemove.unique() } /** * Writes a package combined - * @param packageCombined is a package combined + * @param packageBuilder is a package combined * @param packageCombinedPath is path where packaged combined will be saved */ - private static void writePackageCombined(PackageBuilder packageCombined, String packageCombinedPath) { + private static void writePackage(PackageBuilder packageBuilder, String packageCombinedPath) { FileWriter fileWriter = new FileWriter(packageCombinedPath) - packageCombined.write(fileWriter) + packageBuilder.write(fileWriter) fileWriter.close() } -} +} \ No newline at end of file diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/UpdateTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/UpdateTest.groovy index 401ddbf..7b6f87b 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/UpdateTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/UpdateTest.groovy @@ -121,6 +121,8 @@ class UpdateTest extends Specification { updateInstance.packageGenerator.projectPath = Paths.get(SRC_PATH, 'src').toString() updateInstance.pathUpdate = Paths.get(SRC_PATH, 'build', 'update').toString() updateInstance.projectPath = Paths.get(SRC_PATH, 'src').toString() + updateInstance.projectPackagePath = Paths.get(SRC_PATH, 'src', 'package.xml').toString() + updateInstance.updatePackagePath = Paths.get(SRC_PATH, 'build', 'update', 'package.xml').toString() when: updateInstance.createPackage() then: @@ -133,6 +135,8 @@ class UpdateTest extends Specification { updateInstance.packageGenerator.projectPath = Paths.get(SRC_PATH, 'src').toString() updateInstance.pathUpdate = Paths.get(SRC_PATH, 'build', 'update').toString() updateInstance.projectPath = Paths.get(SRC_PATH, 'src').toString() + updateInstance.projectPackagePath = Paths.get(SRC_PATH, 'src', 'package.xml').toString() + updateInstance.updatePackagePath = Paths.get(SRC_PATH, 'build', 'update', 'package.xml').toString() when: updateInstance.createPackage() then: @@ -144,6 +148,8 @@ class UpdateTest extends Specification { updateInstance.packageGenerator.fileTrackerMap = [:] updateInstance.pathUpdate = Paths.get(SRC_PATH, 'build', 'update').toString() updateInstance.projectPath = Paths.get(SRC_PATH, 'src').toString() + updateInstance.projectPackagePath = Paths.get(SRC_PATH, 'src', 'package.xml').toString() + updateInstance.updatePackagePath = Paths.get(SRC_PATH, 'build', 'update', 'package.xml').toString() when: updateInstance.createPackage() then: @@ -156,6 +162,8 @@ class UpdateTest extends Specification { updateInstance.projectPath = Paths.get(SRC_PATH, 'src').toString() updateInstance.packageGenerator.projectPath = Paths.get(SRC_PATH, 'src').toString() updateInstance.pathUpdate = Paths.get(SRC_PATH, 'build', 'update').toString() + updateInstance.projectPackagePath = Paths.get(SRC_PATH, 'src', 'package.xml').toString() + updateInstance.updatePackagePath = Paths.get(SRC_PATH, 'build', 'update', 'destructiveChanges.xml').toString() updateInstance.credential = credential updateInstance.packageGenerator.credential = credential when: diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/UploadTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/UploadTest.groovy index edee8a2..599b0b7 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/UploadTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/UploadTest.groovy @@ -68,6 +68,8 @@ class UploadTest extends Specification { given: uploadInstance.pathUpload = Paths.get(SRC_PATH, 'build').toString() uploadInstance.projectPath = Paths.get(SRC_PATH, 'src').toString() + uploadInstance.projectPackagePath = Paths.get(SRC_PATH, 'src', 'package.xml').toString() + uploadInstance.uploadPackagePath = Paths.get(SRC_PATH, 'build', 'package.xml').toString() uploadInstance.specificFilesToUpload = [new File(Paths.get(SRC_PATH, "src", "classes", "Class1.cls").toString()), new File(Paths.get(SRC_PATH, "src", "classes", "Class1.cls-meta.xml").toString()), new File(Paths.get(SRC_PATH, "src", "objects", "Object1__c.object").toString()), diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/UtilTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/UtilTest.groovy index 61b6bd6..dc09593 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/UtilTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/UtilTest.groovy @@ -165,6 +165,13 @@ class UtilTest extends Specification { relativePath == Paths.get("classes", "class1").toString() } + def "Test should return object name from sub component member" () { + when: + def objectName = Util.getObjectName('Object5__c.MyCustomField') + then: + objectName == 'Object5__c' + } + def cleanupSpec() { new File(Paths.get(resourcesPath, 'triggers').toString()).deleteDir() new File(Paths.get(resourcesPath, 'relativeTest').toString()).deleteDir() diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombinerTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombinerTest.groovy index 2574a57..2ee5436 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombinerTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombinerTest.groovy @@ -111,6 +111,54 @@ class PackageCombinerTest extends Specification { xmlDiff.similar() } + def 'Test should combine two packages from project directory package and build directory package with documents'() { + given: + String projectPackagePath = Paths.get(SRC_PATH, 'projectPackage.xml') + String buildPackagePath = Paths.get(SRC_PATH, 'buildPackage.xml') + String projectPackageContent = ''' + + + myFolder + myFolder/myFirstFile.txt + myFolder/mySecondFile.txt + Document + + 32.0 + + ''' + String buildPackageContent =''' + + + myFolder/myFirstFile + myFolder/mySecondFile + Document + + 32.0 + ''' + File projectPackageFile = new File(projectPackagePath) + projectPackageFile.write(projectPackageContent) + File buildPackageFile = new File(buildPackagePath) + buildPackageFile.write(buildPackageContent) + String packageContentExpect = ''' + + + myFolder + myFolder/myFirstFile.txt + myFolder/mySecondFile.txt + Document + + 32.0 + + ''' + when: + PackageCombiner.packageCombine(projectPackagePath, buildPackagePath) + XMLUnit.ignoreWhitespace = true + def xmlDiff = new Diff(buildPackageFile.text, packageContentExpect) + then: + new File(Paths.get(SRC_PATH, 'buildPackage.xml').toString()).exists() + xmlDiff.similar() + } + def 'Test should remove components from package xml file'() { given: String packagePath = Paths.get(SRC_PATH, 'packageTest.xml') @@ -246,6 +294,184 @@ class PackageCombinerTest extends Specification { xmlDiff.similar() } + def 'Test should take in account only fields of objects '() { + given: + String projectPackagePath = Paths.get(SRC_PATH, 'projectPackage.xml') + String buildPackagePath = Paths.get(SRC_PATH, 'buildPackage.xml') + String projectPackageContent = ''' + + + Object1__c.MyCustomField1 + Object2__c.MyCustomField2 + Object3__c.MyCustomField3 + CustomField + + + Object1__c.MyFieldSet1 + Object2__c.MyFieldSet2 + Object3__c.MyFieldSet3 + FieldSet + + + Class1 + Class2 + Class3 + ApexClass + + + Object4__c + CustomObject + + 32.0 + + ''' + String buildPackageContent =''' + + + Object1__c + Object4__c + CustomObject + + + Class1 + ApexClass + + 32.0 + ''' + File projectPackageFile = new File(projectPackagePath) + projectPackageFile.write(projectPackageContent) + File buildPackageFile = new File(buildPackagePath) + buildPackageFile.write(buildPackageContent) + String packageContentExpect = ''' + + + Object4__c + CustomObject + + + Class1 + ApexClass + + + Object1__c.MyCustomField1 + CustomField + + + Object1__c.MyFieldSet1 + FieldSet + + 32.0 + + ''' + when: + PackageCombiner.packageCombineToUpdate(projectPackagePath, buildPackagePath) + XMLUnit.ignoreWhitespace = true + def xmlDiff = new Diff(buildPackageFile.text, packageContentExpect) + then: + new File(Paths.get(SRC_PATH, 'buildPackage.xml').toString()).exists() + xmlDiff.similar() + } + + def 'Test should take in account documents with their folders name as member into package xml file '() { + given: + String projectPackagePath = Paths.get(SRC_PATH, 'projectPackage.xml') + String buildPackagePath = Paths.get(SRC_PATH, 'buildPackage.xml') + String projectPackageContent = ''' + + + Object1__c.MyCustomField1 + Object2__c.MyCustomField2 + Object3__c.MyCustomField3 + CustomField + + + MyDocuments + MyDocuments/doc2.txt + MyDocuments/doc1.txt + Document + + + MyReports + MyReports/reportTest + Report + + + Object1__c.MyFieldSet1 + Object2__c.MyFieldSet2 + Object3__c.MyFieldSet3 + FieldSet + + + Class1 + Class2 + Class3 + ApexClass + + + Object4__c + CustomObject + + 32.0 + + ''' + String buildPackageContent =''' + + + Object1__c + Object4__c + CustomObject + + + MyDocuments/doc2.txt + MyDocuments/doc1.txt + Document + + + Class1 + ApexClass + + 32.0 + ''' + File projectPackageFile = new File(projectPackagePath) + projectPackageFile.write(projectPackageContent) + File buildPackageFile = new File(buildPackagePath) + buildPackageFile.write(buildPackageContent) + String packageContentExpect = ''' + + + Object4__c + CustomObject + + + Class1 + ApexClass + + + Object1__c.MyCustomField1 + CustomField + + + MyDocuments + MyDocuments/doc2.txt + MyDocuments/doc1.txt + Document + + + Object1__c.MyFieldSet1 + FieldSet + + 32.0 + + ''' + when: + PackageCombiner.packageCombineToUpdate(projectPackagePath, buildPackagePath) + XMLUnit.ignoreWhitespace = true + def xmlDiff = new Diff(buildPackageFile.text, packageContentExpect) + then: + new File(Paths.get(SRC_PATH, 'buildPackage.xml').toString()).exists() + xmlDiff.similar() + } + def cleanupSpec() { new File(Paths.get(SRC_PATH, 'projectPackage.xml').toString()).delete() new File(Paths.get(SRC_PATH, 'buildPackage.xml').toString()).delete() From 94ec63ef60eea7585a07b8474cba810bebf8882c Mon Sep 17 00:00:00 2001 From: Alex Ventura Date: Fri, 5 Jun 2015 10:23:24 -0400 Subject: [PATCH 22/50] fixed the codification in the paths when they had a space --- .../gradle/plugins/enforce/utils/Util.groovy | 2 +- .../tasks/salesforce/deployment/DeployTest.groovy | 1 + .../gradle/plugins/enforce/utils/UtilTest.groovy | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Util.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Util.groovy index 4a73091..eb04fff 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Util.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Util.groovy @@ -184,7 +184,7 @@ class Util { */ public static String getRelativePath(File file, String basePath, boolean normalizePath = true) { File root = new File(basePath) - String relativePath = root.toURI().relativize(file.toURI()).toString() + String relativePath = root.toPath().relativize(file.toPath()).toString() if (normalizePath) { return Paths.get(relativePath).toString() } diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeployTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeployTest.groovy index 9cb1e3d..f170b5e 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeployTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeployTest.groovy @@ -354,6 +354,7 @@ class DeployTest extends Specification { instanceDeploy.poll = 200 instanceDeploy.waitTime = 10 instanceDeploy.credential = credential + instanceDeploy.projectPackagePath = Paths.get(SRC_PATH, 'src', 'package.xml').toString() def deployFileZipPath = Paths.get(SRC_PATH,'build','deploy.zip').toString() def deployFolderPath = Paths.get(SRC_PATH,'build','deploy').toString() File deployFileZip = new File(deployFileZipPath) diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/UtilTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/UtilTest.groovy index 61b6bd6..077ea4b 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/UtilTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/UtilTest.groovy @@ -165,6 +165,16 @@ class UtilTest extends Specification { relativePath == Paths.get("classes", "class1").toString() } + def "Test should gets relative path when the path has a space"() { + given: + String basePath = Paths.get(resourcesPath, 'relativeTest') + File file = new File(Paths.get(basePath, "classes/class 1").toString()) + when: + def relativePath = Util.getRelativePath(file, basePath) + then: + relativePath == Paths.get("classes", "class 1").toString() + } + def cleanupSpec() { new File(Paths.get(resourcesPath, 'triggers').toString()).deleteDir() new File(Paths.get(resourcesPath, 'relativeTest').toString()).deleteDir() From 7502884ebe7c0e5dcaf17c586455772e3b255516 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 5 Jun 2015 08:32:08 -0700 Subject: [PATCH 23/50] fixed unit test failed in windows --- .../fundacionjala/gradle/plugins/enforce/utils/Constants.groovy | 1 + .../org/fundacionjala/gradle/plugins/enforce/utils/Util.groovy | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy index 4d71a50..b8c7b2a 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy @@ -37,6 +37,7 @@ public class Constants { public static final String POINT = "." public static final String WILDCARD = "*" public static final String SLASH = '/' + public static final String BACK_SLASH = '\\\\' public static final String OBJECT_EXTENSION = 'object' diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Util.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Util.groovy index 6e417c5..5f1477a 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Util.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Util.groovy @@ -188,7 +188,7 @@ class Util { if (normalizePath) { return Paths.get(relativePath).toString() } - return relativePath + return relativePath.replaceAll(Constants.BACK_SLASH, Constants.SLASH) } /** From 8bee74a88a7b770e670ac96eda36368fba69c207 Mon Sep 17 00:00:00 2001 From: Alex Ventura Date: Fri, 5 Jun 2015 12:08:20 -0400 Subject: [PATCH 24/50] deleted prints in the code --- build.gradle | 1 - .../gradle/plugins/enforce/wsc/InspectorResults.groovy | 1 - 2 files changed, 2 deletions(-) diff --git a/build.gradle b/build.gradle index cc475ea..a05bc8c 100644 --- a/build.gradle +++ b/build.gradle @@ -74,7 +74,6 @@ def major = "$System.env.VERSION_NUMBER_MAJOR" def minor = "$System.env.VERSION_NUMBER_MINOR" def patch = "$System.env.VERSION_NUMBER_PATCH" def newVersion = "$major.$minor.$patch" -println newVersion version = newVersion uploadArchives { diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy index 36e59cb..3732ebd 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy @@ -50,7 +50,6 @@ class InspectorResults { } deployResult = metadataConnection.checkDeployStatus(asyncResultId, true) if (deployResult.status == DeployStatus.Failed) { - println deployResult String message = deployResult.errorMessage + '\n\n' + deployResult.stateDetail throw new Exception(message) } From 5f96046e5bbc10ccff2ad88826399169aa4d9bbd Mon Sep 17 00:00:00 2001 From: Marcelo Oporto Fernandez Date: Fri, 5 Jun 2015 13:35:15 -0400 Subject: [PATCH 25/50] Update task delete --- .../tasks/salesforce/SalesforceTask.groovy | 3 + .../tasks/salesforce/deployment/Delete.groovy | 115 +++++------ .../salesforce/deployment/Deployment.groovy | 87 +++++++- .../plugins/enforce/utils/Constants.groovy | 6 + .../enforce/utils/ManagementFile.groovy | 27 ++- .../gradle/plugins/enforce/utils/Util.groovy | 18 ++ .../salesforce/deployment/DeleteTest.groovy | 194 ++++++++++++------ 7 files changed, 316 insertions(+), 134 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy index e5be57a..b339dc4 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy @@ -40,6 +40,7 @@ abstract class SalesforceTask extends ForceTask { public int waitTime public ArrayList arrayPaths public String projectPackagePath + public Map parameters /** * Sets description and group task @@ -56,6 +57,7 @@ abstract class SalesforceTask extends ForceTask { def pathHome = Paths.get(System.properties[DIR_USER].toString(), CREDENTIAL_NAME).toString() arrayPaths = [pathProject, pathHome] buildFolderPath = Paths.get(project.projectDir.path, BUILD_FOLDER_NAME).toString() + parameters = new HashMap() } /** @@ -155,6 +157,7 @@ abstract class SalesforceTask extends ForceTask { fileManager.createDirectory(buildFolderPath) logger.debug('Created directory at: ' + buildFolderPath) projectPackagePath = Paths.get(projectPath, PACKAGE_NAME) + parameters = project.properties.clone() runTask() } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy index 4d6c648..1425abb 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy @@ -5,7 +5,6 @@ package org.fundacionjala.gradle.plugins.enforce.tasks.salesforce.deployment -import org.fundacionjala.gradle.plugins.enforce.filemonitor.ComponentStates import org.fundacionjala.gradle.plugins.enforce.utils.Constants import org.fundacionjala.gradle.plugins.enforce.utils.Util import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.PackageGenerator @@ -18,13 +17,11 @@ import java.nio.file.Paths class Delete extends Deployment { private static final String DESCRIPTION_OF_TASK = "This task deploys just the files that were changed" private final String DIR_DELETE_FOLDER = "delete" - private static final String PARAMETER_FOLDERS= "folders" private final String FILE_NAME_DESTRUCTIVE = "destructiveChanges.xml" - public String pathUpdate - ArrayList filesToUpdate - String folders - ArrayList filesExcludes - PackageGenerator packageGenerator + private final String FILE_NAME_PACKAGE = "package.xml" + public String pathDetele + public String option + public ArrayList filesToDeleted /** * Sets description and group task @@ -33,10 +30,7 @@ class Delete extends Deployment { */ Delete() { super(DESCRIPTION_OF_TASK, Constants.DEPLOYMENT) - filesToUpdate = new ArrayList() - filesExcludes = new ArrayList() - packageGenerator = new PackageGenerator() - interceptorsToExecute = [org.fundacionjala.gradle.plugins.enforce.interceptor.Interceptor.REMOVE_DEPRECATE.id] + filesToDeleted = new ArrayList() } /** @@ -44,84 +38,73 @@ class Delete extends Deployment { */ @Override void runTask() { - pathUpdate = Paths.get(buildFolderPath, DIR_DELETE_FOLDER).toString() - createDeploymentDirectory(pathUpdate) - loadFilesChanged() - verifyParameter() - excludeFilesFromFilesChanged() - createDestructive() - createPackage() -// executeDeploy(pathUpdate) + pathDetele = Paths.get(buildFolderPath, DIR_DELETE_FOLDER).toString() + createDeploymentDirectory(pathDetele) + addAllFiles() + addFoldersToDeleteFiles() + addFilesToDelete() + excludeFilesToDelete() + showFilesToDelete() + + option = System.console().readLine(Constants.QUESTION_CONTINUE) + + + + if( option == 'y' ) { + createDestructive() + createPackage() +// executeDeploy(pathDetele) + } } - def truncate(String pathToTruncate) { - interceptorsToExecute += interceptors - truncateComponents(pathToTruncate) + def addAllFiles() { + filesToDeleted = addAllFilesInAFolder(filesToDeleted); + } + /** + * Add all files that are inside the folders + */ + def addFoldersToDeleteFiles() { + filesToDeleted = addFilesFromFolders(filesToDeleted) } /** - * Creates packages to all files which has been changed + * Add files to file's list */ - def createPackage() { - packageGenerator.buildPackage(Paths.get(pathUpdate, PACKAGE_NAME).toString()) + def addFilesToDelete() { + filesToDeleted = addFilesTo(filesToDeleted) } /** - * Creates package to all files which has been deleted + * Show files to delete */ - def createDestructive() { - ArrayList files = new ArrayList(); - packageGenerator.fileTrackerMap.each { nameFile, resultTracker -> - if (resultTracker.state == ComponentStates.DELETED) { - files.add(new File(Paths.get(projectPath, nameFile).toString())) - } + + def showFilesToDelete() { + println "\nFILES TO DELETE\n" + filesToDeleted.each { file-> + println file } - writePackage(Paths.get(pathUpdate, FILE_NAME_DESTRUCTIVE).toString(), files) + println filesToDeleted.size() + " files \n" } /** - * Loads all files which has been changed on filesChanged + * ExcludeFiles from filesExcludes map */ - def loadFilesChanged() { - packageGenerator.init(projectPath, credential) + def excludeFilesToDelete() { + filesToDeleted = excludeFiles(filesToDeleted) } /** - * Verifies if there is files changed in folders inserted by user + * Creates package to all files which has been deleted */ - def verifyParameter() { - println "|*| : "+project - println "|*| : "+Util.isValidProperty(project, PARAMETER_FOLDERS) - if (Util.isValidProperty(project, PARAMETER_FOLDERS)) { - folders = project.folders - } - println "|*| : "+folders - ArrayList validatedFiles - if (folders) { - ArrayList foldersName = folders.split(Constants.COMMA) - - ArrayList invalidFolders = Util.getInvalidFolders(foldersName) - validateFolders(foldersName) - if (!invalidFolders.empty) { - throw new Exception("${Constants.INVALID_FOLDER}: ${invalidFolders}") - } - validatedFiles = fileManager.getValidElements(projectPath, excludeFilesToMonitor) - packageGenerator.listFileToDelete(foldersName,validatedFiles) - } - - println "File to delete : "+packageGenerator.fileTrackerMap + def createDestructive() { + writePackage(Paths.get(pathDetele, FILE_NAME_DESTRUCTIVE).toString(), filesToDeleted) } /** - * ExcludeFiles from filesExcludes map + * Creates packages to all files which has been changed */ - private void excludeFilesFromFilesChanged() { - ArrayList filesFiltered = excludeFiles(packageGenerator.getFiles()) - filesFiltered.add(new File("classes/Class2.cls")) - filesExcludes = packageGenerator.excludeFiles(filesFiltered) - println "\nFile to exclude : "+filesFiltered - println "File to exclude : "+filesExcludes + def createPackage() { + writePackage(Paths.get(pathDetele, FILE_NAME_PACKAGE).toString(), []) } - } \ No newline at end of file diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy index 3621b96..8c69dc6 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy @@ -32,6 +32,7 @@ abstract class Deployment extends SalesforceTask { public final String SLASH = "/" public final String BACKSLASH = "\\\\" + /** * Sets description and group task * @param descriptionTask is description tasks @@ -216,6 +217,73 @@ abstract class Deployment extends SalesforceTask { return criterias } + /** + * Add files int a folder + * @param files list of files to the new files will be added + * @return files list of files with the new files added + */ + def addAllFilesInAFolder(ArrayList files) { + if (!Util.isValidProperty(parameters, Constants.PARAMETER_FOLDERS) && !Util.isValidProperty(parameters, Constants.PARAMETER_FILES)) { + files = files + fileManager.getAllFilesOf(projectPath) + } + return files + } + + /** + * Add files from folders + * @param files list of files to the new files will be added + * @return files list of files with the new files added + */ + def addFilesFromFolders(ArrayList files) { + String folderNames + if (Util.isValidProperty(parameters, Constants.PARAMETER_FOLDERS)) { + folderNames = parameters[Constants.PARAMETER_FOLDERS].toString() + } + if (folderNames) { + ArrayList foldersName = folderNames.split(Constants.COMMA) + ArrayList invalidFolders = Util.getInvalidFolders(foldersName) + validateFolders(foldersName) + if (!invalidFolders.empty) { + throw new Exception("${Constants.INVALID_FOLDER}: ${invalidFolders}") + } + files = fileManager.getFilesByFolders(projectPath, folderNames.split(Constants.COMMA) as ArrayList) + } + files.unique { a, b -> a <=> b } + return files + } + + /** + * Add files to + * @param files list of files to the new files will be added + * @return files list of files with the new files added + */ + public addFilesTo(ArrayList files) { + String fileNames + if (Util.isValidProperty(parameters, Constants.PARAMETER_FILES) && !Util.isEmptyProperty(parameters, Constants.PARAMETER_FILES)) { + fileNames = parameters[Constants.PARAMETER_FILES].toString() + } + ArrayList filesName = new ArrayList() + if (fileNames == null) { + return files + } + validateParameter(fileNames) + fileNames.split(Constants.COMMA).each {String fileName -> + def fileNameChanged = fileName.replaceAll(BACKSLASH, SLASH) + if (!fileNameChanged.contains(SLASH)) { + filesName.push("${fileName}${File.separator}${Constants.WILDCARD}${Constants.WILDCARD}") + return files + } + filesName.push(fileName) + filesName.push("${fileName}${Constants.META_XML}") + } + + FileTree fileTree = project.fileTree(dir:projectPath, includes: filesName) + fileTree.each {File file -> + files.push(file) + } + return files + } + /** * Excludes files * @param filesToFilter files that will be filter @@ -224,16 +292,19 @@ abstract class Deployment extends SalesforceTask { public excludeFiles(ArrayList filesToFilter) { if (filesToFilter == null) { logger.error("${Constants.NULL_PARAM_EXCEPTION} filesToFilter") + return filesToFilter } - ArrayList filesFiltered = filesToFilter.clone() as ArrayList - if (Util.isValidProperty(project, EXCLUDES) && !Util.isEmptyProperty(project, EXCLUDES)) { - excludes = project.excludes as String - } - if (excludes) { - validateParameter(excludes) - filesFiltered = excludeFilesByCriterion(filesFiltered, excludes) + else { + ArrayList filesFiltered = filesToFilter.clone() as ArrayList + if (Util.isValidProperty(parameters, Constants.PARAMETER_EXCLUDES) && !Util.isEmptyProperty(parameters, Constants.PARAMETER_EXCLUDES)) { + excludes = parameters[Constants.PARAMETER_EXCLUDES].toString() + } + if (excludes) { + validateParameter(excludes) + filesFiltered = excludeFilesByCriterion(filesFiltered, excludes) + } + return filesFiltered } - return filesFiltered } /** diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy index ca9811d..6731c79 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy @@ -37,6 +37,12 @@ public class Constants { public static final String OBJECT_EXTENSION = 'object' + + //Deployment task constants + public static final String PARAMETER_FOLDERS = 'folders' + public static final String PARAMETER_FILES = 'files' + public static final String PARAMETER_EXCLUDES = 'excludes' + //Deploy task constants public static final String DEPLOYING_TRUNCATED_CODE = 'Deploying truncated code' public static final String DEPLOYING_TRUNCATED_CODE_SUCCESSFULLY = 'Truncated code were successfully deployed' diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy index 19a2fd3..3dd4706 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy @@ -267,7 +267,6 @@ class ManagementFile { * @return files validated by folders */ public ArrayList getFilesByFolders(String sourcePath, ArrayList folders) { - ArrayList filesByFolder = new ArrayList() folders.each { folderName -> File folder = new File(Paths.get(sourcePath, folderName).toString()) @@ -278,6 +277,32 @@ class ManagementFile { return filesByFolder } + /** + * Gets array valid files by folders + * @param sourcePath is type String + * @return files validated by folders and subfolders + */ + public ArrayList getAllFilesOf(String sourcePath) { + ArrayList files = new ArrayList() + File file = new File(sourcePath) + if(file.isDirectory()) { + file.eachFile { auxFile -> + SalesforceValidator validator = SalesforceValidatorManager.getValidator(file.getName()) + if (validator.validateFileByFolder(file.getName(), auxFile)) { + File xmlFile = new File("${auxFile.getAbsolutePath().toString()}${METADATA_EXTENSION}") + if (xmlFile.exists()) { + files.push(xmlFile) + } + } + files = files + getAllFilesOf(auxFile.getAbsolutePath().toString()) + } + } + else { + files.push(file) + } + return files + } + /** * Gets array valid files by folder * @param folders is type ArrayList diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Util.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Util.groovy index 4a73091..e0e4cb7 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Util.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Util.groovy @@ -64,6 +64,15 @@ class Util { project.hasProperty(name) && !project.properties[name].toString().equals("") } + /** + * Verifies if the property exist and if it is not empty string + * @parameters to compare + * @param name the property typeName + */ + public static boolean isValidProperty(Map parameters, String name) { + parameters.containsKey(name) && !parameters[name].toString().equals("") + } + /** * Verify if the property is empty * @param name the property typeName @@ -71,6 +80,15 @@ class Util { public static isEmptyProperty(Project project, String name) { project.hasProperty(name) && project.properties[name].toString().equals('') } + + /** + * Verify if the property is empty + * @param name the property typeName + */ + public static isEmptyProperty(Map parameters, String name) { + parameters.hasProperty(name) && parameters[name].toString().equals('') + } + /** * Validates required parameters that should be entered via command line * @param project The project reference diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy index 737b480..c6aa7e5 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy @@ -9,6 +9,7 @@ import org.fundacionjala.gradle.plugins.enforce.EnforcePlugin import org.fundacionjala.gradle.plugins.enforce.filemonitor.ComponentMonitor import org.fundacionjala.gradle.plugins.enforce.filemonitor.ComponentSerializer import org.fundacionjala.gradle.plugins.enforce.metadata.DeployMetadata +import org.fundacionjala.gradle.plugins.enforce.utils.Constants import org.fundacionjala.gradle.plugins.enforce.utils.ManagementFile import org.fundacionjala.gradle.plugins.enforce.wsc.Credential import org.fundacionjala.gradle.plugins.enforce.wsc.LoginType @@ -19,6 +20,7 @@ import org.gradle.testfixtures.ProjectBuilder import spock.lang.Shared import spock.lang.Specification +import java.nio.file.Path import java.nio.file.Paths class DeleteTest extends Specification { @@ -31,6 +33,8 @@ class DeleteTest extends Specification { @Shared def SRC_PATH = Paths.get(System.getProperty("user.dir"), "src", "test", "groovy", "org", "fundacionjala", "gradle", "plugins","enforce","tasks", "salesforce", "resources").toString() + @Shared + def DIR_DELETE_FOLDER = 'delete' @Shared Credential credential @@ -55,6 +59,7 @@ class DeleteTest extends Specification { componentSerializer = new ComponentSerializer(fileTrackerPath) componentMonitor = new ComponentMonitor(SRC_PATH) + def class1 = new File(Paths.get(SRC_PATH, 'classes', 'class1.cls').toString()) def class1Cls = new File(Paths.get(SRC_PATH, 'src', 'classes', 'Class1.cls').toString()) def class1ClsXml = new File(Paths.get(SRC_PATH, 'src', 'classes', 'Class1.cls-meta.xml').toString()) @@ -63,6 +68,18 @@ class DeleteTest extends Specification { def trigger = new File(Paths.get(SRC_PATH, 'src', 'triggers', 'Trigger1.trigger').toString()) def triggerXml = new File(Paths.get(SRC_PATH, 'src', 'triggers', 'Trigger1.trigger-meta.xml').toString()) + + ArrayList files = new ArrayList() + + files.add(new File(Paths.get(SRC_PATH, 'src','classes', 'class1.cls').toString())) + files.add(new File(Paths.get(SRC_PATH, 'src','classes', '').toString())) + files.add(new File(Paths.get(SRC_PATH, 'src','classes', '').toString())) + files.add(new File(Paths.get(SRC_PATH, 'src','classes', '').toString())) + files.add(new File(Paths.get(SRC_PATH, 'src','classes', '').toString())) + files.add(new File(Paths.get(SRC_PATH, 'src','classes', '').toString())) + files.add(new File(Paths.get(SRC_PATH, 'src','classes', '').toString())) + + def mapMock = componentMonitor.getComponentsSignature([class1, class1Cls, class1ClsXml, object1__c, object1__c, account, trigger, triggerXml]) componentSerializer.save(mapMock) @@ -75,69 +92,128 @@ class DeleteTest extends Specification { credential.type = 'normal' } - def "Integration testing must create two files for the next test"() { + def "Integration testing must list all the files to delete"() { + given: + deleteInstance.buildFolderPath = Paths.get(SRC_PATH, 'build').toString() + deleteInstance.projectPath = Paths.get(SRC_PATH, 'src').toString() + deleteInstance.componentDeploy = new DeployMetadata() + deleteInstance.poll = 200 + deleteInstance.waitTime = 10 + deleteInstance.credential = credential + deleteInstance.project.enforce.deleteTemporaryFiles = true + + ArrayList filesExpected = new ArrayList(); + filesExpected.add(new File(Paths.get(SRC_PATH,'src','classes','Class1.cls').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src','classes','Class1.cls-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src','objects','Account.object').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src','objects','Object1__c.object').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src','package.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src','triggers','Trigger1.trigger').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src','triggers','Trigger1.trigger-meta.xml').toString())) + + when: + deleteInstance.pathDetele = Paths.get(deleteInstance.buildFolderPath, DIR_DELETE_FOLDER).toString() + deleteInstance.createDeploymentDirectory(deleteInstance.pathDetele) + deleteInstance.addAllFiles() + deleteInstance.addFoldersToDeleteFiles() + deleteInstance.addFilesToDelete() + deleteInstance.excludeFilesToDelete() + deleteInstance.createDestructive() + deleteInstance.createPackage() + + then: + filesExpected.sort{ it.getAbsolutePath() }.equals( deleteInstance.filesToDeleted.sort{ it.getAbsolutePath() }) + } + + def "Integration testing must list files filtered for folders to delete"() { + given: + deleteInstance.buildFolderPath = Paths.get(SRC_PATH, 'build').toString() + deleteInstance.projectPath = Paths.get(SRC_PATH, 'src').toString() + deleteInstance.componentDeploy = new DeployMetadata() + deleteInstance.poll = 200 + deleteInstance.waitTime = 10 + deleteInstance.credential = credential + deleteInstance.project.enforce.deleteTemporaryFiles = true + deleteInstance.parameters.put('folders','classes,triggers') + + ArrayList filesExpected = new ArrayList(); + filesExpected.add(new File(Paths.get(SRC_PATH,'src','classes','Class1.cls').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src','classes','Class1.cls-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src','triggers','Trigger1.trigger').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src','triggers','Trigger1.trigger-meta.xml').toString())) + + when: + deleteInstance.pathDetele = Paths.get(deleteInstance.buildFolderPath, DIR_DELETE_FOLDER).toString() + deleteInstance.createDeploymentDirectory(deleteInstance.pathDetele) + deleteInstance.addAllFiles() + deleteInstance.addFoldersToDeleteFiles() + deleteInstance.addFilesToDelete() + deleteInstance.excludeFilesToDelete() + deleteInstance.createDestructive() + deleteInstance.createPackage() + + then: + filesExpected.sort{ it.getAbsolutePath() }.equals( deleteInstance.filesToDeleted.sort{ it.getAbsolutePath() }) + } + + def "Integration testing must list files filtered for files to delete"() { given: - deleteInstance.packageGenerator.fileTrackerMap = [:] - deleteInstance.buildFolderPath = Paths.get(SRC_PATH, 'build').toString() - deleteInstance.projectPath = Paths.get(SRC_PATH, 'src').toString() - deleteInstance.componentDeploy = new DeployMetadata() - deleteInstance.poll = 200 - deleteInstance.waitTime = 10 - deleteInstance.credential = credential - deleteInstance.project.enforce.deleteTemporaryFiles = true - componentMonitor.srcProject = Paths.get(SRC_PATH,'src').toString() - componentSerializer.save(componentMonitor.getComponentsSignature([])) - - def newTemporalClassPath2 = Paths.get(SRC_PATH, 'src', 'classes', 'Class2.cls').toString() - def newTemporalXmlPath2 = Paths.get(SRC_PATH, 'src', 'classes', 'Class2.cls-meta.xml').toString() - def newTemporalClassPath3 = Paths.get(SRC_PATH, 'src', 'classes', 'Class3.cls').toString() - def newTemporalXmlPath3 = Paths.get(SRC_PATH, 'src', 'classes', 'Class3.cls-meta.xml').toString() - - FileWriter writerClass2 = new FileWriter(newTemporalClassPath2) - FileWriter writerXml2 = new FileWriter(newTemporalXmlPath2) - FileWriter writerClass3 = new FileWriter(newTemporalClassPath3) - FileWriter writerXml3 = new FileWriter(newTemporalXmlPath3) - - def contentTemporalClass2 = "public with sharing class Class2 {public Class2(Integer a, Integer b){ }}" - def contentTemporalClass3 = "public with sharing class Class2 {public Class3(Integer a, Integer b){ }}" - def contentTemporalXml2 = "${""}${""}${"24.0Active"}" - def contentTemporalXml3 = "${""}${""}${"24.0Active"}" - - writerClass2.write(contentTemporalClass2) - writerClass3.write(contentTemporalClass3) - writerXml2.write(contentTemporalXml2) - writerXml3.write(contentTemporalXml3) - - writerClass2.close() - writerClass3.close() - writerXml2.close() - writerXml3.close() - - File fileClass2 = new File(newTemporalClassPath2) - File fileClass3 = new File(newTemporalClassPath3) - File fileXML2 = new File(newTemporalXmlPath2) - File fileXML3 = new File(newTemporalXmlPath3) - - ToolingAPI toolingAPI - ApexAPI apexAPI - String jsonByClasses - String jsonCoverageLines - String jsonByTriggers - deleteInstance.folders = "classes" - String QUERY_CLASSES = "SELECT Name FROM ApexPage" - toolingAPI = new ToolingAPI(credential) - apexAPI = new ApexAPI(credential) - jsonByClasses = toolingAPI.httpAPIClient.executeQuery(QUERY_CLASSES) - - println "Js : "+jsonByClasses + deleteInstance.buildFolderPath = Paths.get(SRC_PATH, 'build').toString() + deleteInstance.projectPath = Paths.get(SRC_PATH, 'src').toString() + deleteInstance.componentDeploy = new DeployMetadata() + deleteInstance.poll = 200 + deleteInstance.waitTime = 10 + deleteInstance.credential = credential + deleteInstance.project.enforce.deleteTemporaryFiles = true + deleteInstance.parameters.put('files','classes/Class1.cls') + + ArrayList filesExpected = new ArrayList(); + filesExpected.add(new File(Paths.get(SRC_PATH,'src','classes','Class1.cls').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src','classes','Class1.cls-meta.xml').toString())) when: - deleteInstance.runTask() + deleteInstance.pathDetele = Paths.get(deleteInstance.buildFolderPath, DIR_DELETE_FOLDER).toString() + deleteInstance.createDeploymentDirectory(deleteInstance.pathDetele) + deleteInstance.addAllFiles() + deleteInstance.addFoldersToDeleteFiles() + deleteInstance.addFilesToDelete() + deleteInstance.excludeFilesToDelete() + deleteInstance.createDestructive() + deleteInstance.createPackage() + + then: + filesExpected.sort{ it.getAbsolutePath() }.equals( deleteInstance.filesToDeleted.sort{ it.getAbsolutePath() }) + } + + def "Integration testing must list all the files less exclude to delete"() { + given: + deleteInstance.buildFolderPath = Paths.get(SRC_PATH, 'build').toString() + deleteInstance.projectPath = Paths.get(SRC_PATH, 'src').toString() + deleteInstance.componentDeploy = new DeployMetadata() + deleteInstance.poll = 200 + deleteInstance.waitTime = 10 + deleteInstance.credential = credential + deleteInstance.project.enforce.deleteTemporaryFiles = true + + deleteInstance.parameters.put('excludes','classes/Class1.cls,triggers/Trigger1.trigger') + + ArrayList filesExpected = new ArrayList(); + filesExpected.add(new File(Paths.get(SRC_PATH,'src','objects','Account.object').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src','objects','Object1__c.object').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src','package.xml').toString())) + + when: + deleteInstance.pathDetele = Paths.get(deleteInstance.buildFolderPath, DIR_DELETE_FOLDER).toString() + deleteInstance.createDeploymentDirectory(deleteInstance.pathDetele) + deleteInstance.addAllFiles() + deleteInstance.addFoldersToDeleteFiles() + deleteInstance.addFilesToDelete() + deleteInstance.excludeFilesToDelete() + deleteInstance.createDestructive() + deleteInstance.createPackage() + then: - fileClass2.exists() - fileClass3.exists() - fileXML2.exists() - fileXML3.exists() + filesExpected.sort{ it.getAbsolutePath() }.equals( deleteInstance.filesToDeleted.sort{ it.getAbsolutePath() }) } def cleanupSpec() { From 079db661152d0cf05c09dac69f5e3d674225470b Mon Sep 17 00:00:00 2001 From: Marcelo Oporto Fernandez Date: Fri, 5 Jun 2015 13:55:06 -0400 Subject: [PATCH 26/50] Comments was removed --- .../tasks/salesforce/deployment/Delete.groovy | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy index 1425abb..861bd2a 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy @@ -6,9 +6,6 @@ package org.fundacionjala.gradle.plugins.enforce.tasks.salesforce.deployment import org.fundacionjala.gradle.plugins.enforce.utils.Constants -import org.fundacionjala.gradle.plugins.enforce.utils.Util -import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.PackageGenerator - import java.nio.file.Paths /** @@ -20,7 +17,6 @@ class Delete extends Deployment { private final String FILE_NAME_DESTRUCTIVE = "destructiveChanges.xml" private final String FILE_NAME_PACKAGE = "package.xml" public String pathDetele - public String option public ArrayList filesToDeleted /** @@ -46,14 +42,10 @@ class Delete extends Deployment { excludeFilesToDelete() showFilesToDelete() - option = System.console().readLine(Constants.QUESTION_CONTINUE) - - - - if( option == 'y' ) { + if( System.console().readLine(Constants.QUESTION_CONTINUE) == 'y' ) { createDestructive() createPackage() -// executeDeploy(pathDetele) + executeDeploy(pathDetele) } } @@ -77,7 +69,6 @@ class Delete extends Deployment { /** * Show files to delete */ - def showFilesToDelete() { println "\nFILES TO DELETE\n" filesToDeleted.each { file-> From 606bead1939882285f0aec9447d04b63e7752781 Mon Sep 17 00:00:00 2001 From: Marcelo Oporto Fernandez Date: Fri, 5 Jun 2015 16:36:16 -0400 Subject: [PATCH 27/50] Fixed observations --- .../tasks/salesforce/SalesforceTask.groovy | 1 + .../tasks/salesforce/deployment/Delete.groovy | 41 +++++------ .../salesforce/deployment/Deployment.groovy | 56 ++++++--------- .../plugins/enforce/utils/Constants.groovy | 4 ++ .../enforce/utils/ManagementFile.groovy | 16 ++--- .../salesforce/deployment/DeleteTest.groovy | 70 +++---------------- 6 files changed, 62 insertions(+), 126 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy index 6a4017b..d2c560c 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy @@ -29,6 +29,7 @@ abstract class SalesforceTask extends ForceTask { private final String SAVE_PACKAGE_ERROR = "path package not defined, you need prepare package first" private final String UPDATE_PACKAGE_ERROR = "you need to prepare package first" public final String PACKAGE_NAME = "package.xml" + public final String PACKAGE_NAME_DESTRUCTIVE = "destructiveChanges.xml" private final String DIR_USER = "user.home" private final String BUILD_FOLDER_NAME = "build" private CredentialManager credentialManagement diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy index 861bd2a..f8842ef 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy @@ -12,11 +12,7 @@ import java.nio.file.Paths * Updates an org using metadata API */ class Delete extends Deployment { - private static final String DESCRIPTION_OF_TASK = "This task deploys just the files that were changed" - private final String DIR_DELETE_FOLDER = "delete" - private final String FILE_NAME_DESTRUCTIVE = "destructiveChanges.xml" - private final String FILE_NAME_PACKAGE = "package.xml" - public String pathDetele + public String pathDelete public ArrayList filesToDeleted /** @@ -25,7 +21,7 @@ class Delete extends Deployment { * @param group is the group typeName the task */ Delete() { - super(DESCRIPTION_OF_TASK, Constants.DEPLOYMENT) + super(Constants.DESCRIPTION_DELETE_TASK, Constants.DEPLOYMENT) filesToDeleted = new ArrayList() } @@ -34,68 +30,67 @@ class Delete extends Deployment { */ @Override void runTask() { - pathDetele = Paths.get(buildFolderPath, DIR_DELETE_FOLDER).toString() - createDeploymentDirectory(pathDetele) + pathDelete = Paths.get(buildFolderPath, Constants.DIR_DELETE_FOLDER).toString() + createDeploymentDirectory(pathDelete) addAllFiles() addFoldersToDeleteFiles() addFilesToDelete() excludeFilesToDelete() showFilesToDelete() - if( System.console().readLine(Constants.QUESTION_CONTINUE) == 'y' ) { + if( System.console().readLine(Constants.QUESTION_CONTINUE) == Constants.YES_OPTION ) { createDestructive() createPackage() - executeDeploy(pathDetele) + executeDeploy(pathDelete) } } def addAllFiles() { - filesToDeleted = addAllFilesInAFolder(filesToDeleted); + filesToDeleted = addAllFilesInAFolder(filesToDeleted) } /** - * Add all files that are inside the folders + * Adds all files that are inside the folders */ def addFoldersToDeleteFiles() { filesToDeleted = addFilesFromFolders(filesToDeleted) } /** - * Add files to file's list + * Adds files to file's list */ def addFilesToDelete() { filesToDeleted = addFilesTo(filesToDeleted) } /** - * Show files to delete + * Shows files to delete */ def showFilesToDelete() { - println "\nFILES TO DELETE\n" + logger.quiet("\nFILES TO DELETE\n") filesToDeleted.each { file-> - println file + println "->"+file } - println filesToDeleted.size() + " files \n" + logger.quiet(filesToDeleted.size() + " files \n") } /** - * ExcludeFiles from filesExcludes map + * Excludes Files from filesExcludes map */ def excludeFilesToDelete() { filesToDeleted = excludeFiles(filesToDeleted) } /** - * Creates package to all files which has been deleted + * Creates packages to all files which has been deleted */ def createDestructive() { - writePackage(Paths.get(pathDetele, FILE_NAME_DESTRUCTIVE).toString(), filesToDeleted) + writePackage(Paths.get(pathDelete, PACKAGE_NAME_DESTRUCTIVE).toString(), filesToDeleted) } /** - * Creates packages to all files which has been changed + * Create a package empty */ def createPackage() { - writePackage(Paths.get(pathDetele, FILE_NAME_PACKAGE).toString(), []) + writePackage(Paths.get(pathDelete, PACKAGE_NAME).toString(), []) } - } \ No newline at end of file diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy index b7918d8..92eec77 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy @@ -21,18 +21,16 @@ import java.nio.file.Paths * Represent base class for needs deploy code in salesforce */ abstract class Deployment extends SalesforceTask { - private final String NAME_TASK_ZIP = "createZip" - DeployMetadata componentDeploy - InterceptorManager componentManager - List interceptorsToExecute = [] - List interceptors = [] + public DeployMetadata componentDeploy + public InterceptorManager componentManager + public List interceptorsToExecute = [] + public List interceptors = [] public final String EXCLUDES = 'excludes' public String excludes public final int FILE_NAME_POSITION = 1 public final String SLASH = "/" public final String BACKSLASH = "\\\\" - /** * Sets description and group task * @param descriptionTask is description tasks @@ -184,43 +182,38 @@ abstract class Deployment extends SalesforceTask { } /** - * Add files int a folder + * Adds all files inside a folder and subfolders * @param files list of files to the new files will be added * @return files list of files with the new files added */ def addAllFilesInAFolder(ArrayList files) { if (!Util.isValidProperty(parameters, Constants.PARAMETER_FOLDERS) && !Util.isValidProperty(parameters, Constants.PARAMETER_FILES)) { - files = files + fileManager.getAllFilesOf(projectPath) + files.addAll(fileManager.getAllFilesOf(projectPath)) } return files } /** - * Add files from folders + * Adds files from folders * @param files list of files to the new files will be added * @return files list of files with the new files added */ def addFilesFromFolders(ArrayList files) { - String folderNames + String folders if (Util.isValidProperty(parameters, Constants.PARAMETER_FOLDERS)) { - folderNames = parameters[Constants.PARAMETER_FOLDERS].toString() + folders = parameters[Constants.PARAMETER_FOLDERS].toString() } - if (folderNames) { - ArrayList foldersName = folderNames.split(Constants.COMMA) - ArrayList invalidFolders = Util.getInvalidFolders(foldersName) + if (folders) { + ArrayList foldersName = folders.split(Constants.COMMA) validateFolders(foldersName) - if (!invalidFolders.empty) { - throw new Exception("${Constants.INVALID_FOLDER}: ${invalidFolders}") - } - files = fileManager.getFilesByFolders(projectPath, folderNames.split(Constants.COMMA) as ArrayList) + files = fileManager.getFilesByFolders(projectPath, foldersName as ArrayList) } - files.unique { a, b -> a <=> b } + files.unique() return files } /** - * Add files to - * @param files list of files to the new files will be added + * Adds files to ArrayList according to the parameters passed * @return files list of files with the new files added */ public addFilesTo(ArrayList files) { @@ -236,7 +229,6 @@ abstract class Deployment extends SalesforceTask { fileNames.split(Constants.COMMA).each {String fileName -> def fileNameChanged = fileName.replaceAll(BACKSLASH, SLASH) if (!fileNameChanged.contains(SLASH)) { - filesName.push("${fileName}${File.separator}${Constants.WILDCARD}${Constants.WILDCARD}") return files } filesName.push(fileName) @@ -258,19 +250,17 @@ abstract class Deployment extends SalesforceTask { public excludeFiles(ArrayList filesToFilter) { if (filesToFilter == null) { logger.error("${Constants.NULL_PARAM_EXCEPTION} filesToFilter") - return filesToFilter } - else { - ArrayList filesFiltered = filesToFilter.clone() as ArrayList - if (Util.isValidProperty(parameters, Constants.PARAMETER_EXCLUDES) && !Util.isEmptyProperty(parameters, Constants.PARAMETER_EXCLUDES)) { - excludes = parameters[Constants.PARAMETER_EXCLUDES].toString() - } - if (excludes) { - validateParameter(excludes) - filesFiltered = excludeFilesByCriterion(filesFiltered, excludes) - } - return filesFiltered + + ArrayList filesFiltered = filesToFilter.clone() as ArrayList + if (Util.isValidProperty(parameters, Constants.PARAMETER_EXCLUDES) && !Util.isEmptyProperty(parameters, Constants.PARAMETER_EXCLUDES)) { + excludes = parameters[Constants.PARAMETER_EXCLUDES].toString() + } + if (excludes) { + validateParameter(excludes) + filesFiltered = excludeFilesByCriterion(filesFiltered, excludes) } + return filesFiltered } /** diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy index 95521e1..5e6b51e 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy @@ -99,4 +99,8 @@ public class Constants { public static final String RETRIEVE_MESSAGE_CANCELED = 'Retrieve task was canceled!!' public static final String RETRIEVE_QUESTION_TO_CONTINUE = 'Do you want to continue? (y/n) : ' + //Delete task constants + public static final String DESCRIPTION_DELETE_TASK = "This task deploys just the files that were changed" + public static final String DIR_DELETE_FOLDER = "delete" + } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy index f2c5c5a..6335b16 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy @@ -284,21 +284,21 @@ class ManagementFile { */ public ArrayList getAllFilesOf(String sourcePath) { ArrayList files = new ArrayList() - File file = new File(sourcePath) - if(file.isDirectory()) { - file.eachFile { auxFile -> - SalesforceValidator validator = SalesforceValidatorManager.getValidator(file.getName()) - if (validator.validateFileByFolder(file.getName(), auxFile)) { - File xmlFile = new File("${auxFile.getAbsolutePath().toString()}${METADATA_EXTENSION}") + File folder = new File(sourcePath) + if(folder.isDirectory()) { + folder.eachFile { file -> + SalesforceValidator validator = SalesforceValidatorManager.getValidator(folder.getName()) + if (validator.validateFileByFolder(folder.getName(), file)) { + File xmlFile = new File("${file.getAbsolutePath().toString()}${METADATA_EXTENSION}") if (xmlFile.exists()) { files.push(xmlFile) } } - files = files + getAllFilesOf(auxFile.getAbsolutePath().toString()) + files.addAll(getAllFilesOf(file.getAbsolutePath().toString())) } } else { - files.push(file) + files.push(folder) } return files } diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy index c6aa7e5..c4e65ce 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy @@ -12,15 +12,10 @@ import org.fundacionjala.gradle.plugins.enforce.metadata.DeployMetadata import org.fundacionjala.gradle.plugins.enforce.utils.Constants import org.fundacionjala.gradle.plugins.enforce.utils.ManagementFile import org.fundacionjala.gradle.plugins.enforce.wsc.Credential -import org.fundacionjala.gradle.plugins.enforce.wsc.LoginType -import org.fundacionjala.gradle.plugins.enforce.wsc.rest.ToolingAPI -import org.fundacionjala.gradle.plugins.enforce.wsc.soap.ApexAPI import org.gradle.api.Project import org.gradle.testfixtures.ProjectBuilder import spock.lang.Shared import spock.lang.Specification - -import java.nio.file.Path import java.nio.file.Paths class DeleteTest extends Specification { @@ -55,41 +50,6 @@ class DeleteTest extends Specification { deleteInstance.createDeploymentDirectory(Paths.get(SRC_PATH, 'build').toString()) deleteInstance.createDeploymentDirectory(Paths.get(SRC_PATH, 'build', 'delete').toString()) deleteInstance.projectPath = SRC_PATH - def fileTrackerPath = Paths.get(SRC_PATH,'.fileTracker.data').toString() - componentSerializer = new ComponentSerializer(fileTrackerPath) - componentMonitor = new ComponentMonitor(SRC_PATH) - - - def class1 = new File(Paths.get(SRC_PATH, 'classes', 'class1.cls').toString()) - def class1Cls = new File(Paths.get(SRC_PATH, 'src', 'classes', 'Class1.cls').toString()) - def class1ClsXml = new File(Paths.get(SRC_PATH, 'src', 'classes', 'Class1.cls-meta.xml').toString()) - def object1__c = new File(Paths.get(SRC_PATH, 'src', 'objects', 'Object1__c.object').toString()) - def account = new File(Paths.get(SRC_PATH, 'src', 'objects', 'Account.object').toString()) - def trigger = new File(Paths.get(SRC_PATH, 'src', 'triggers', 'Trigger1.trigger').toString()) - def triggerXml = new File(Paths.get(SRC_PATH, 'src', 'triggers', 'Trigger1.trigger-meta.xml').toString()) - - - ArrayList files = new ArrayList() - - files.add(new File(Paths.get(SRC_PATH, 'src','classes', 'class1.cls').toString())) - files.add(new File(Paths.get(SRC_PATH, 'src','classes', '').toString())) - files.add(new File(Paths.get(SRC_PATH, 'src','classes', '').toString())) - files.add(new File(Paths.get(SRC_PATH, 'src','classes', '').toString())) - files.add(new File(Paths.get(SRC_PATH, 'src','classes', '').toString())) - files.add(new File(Paths.get(SRC_PATH, 'src','classes', '').toString())) - files.add(new File(Paths.get(SRC_PATH, 'src','classes', '').toString())) - - - def mapMock = componentMonitor.getComponentsSignature([class1, class1Cls, class1ClsXml, object1__c, object1__c, account, trigger, triggerXml]) - componentSerializer.save(mapMock) - - credential = new Credential() - credential.id = 'id' - credential.username = 'salesforce2014.test@gmail.com' - credential.password = '123qwe2014' - credential.token = 'UO1Jx5vDQl97xCKkwXBH8tg3T' - credential.loginFormat = LoginType.DEV.value() - credential.type = 'normal' } def "Integration testing must list all the files to delete"() { @@ -97,9 +57,6 @@ class DeleteTest extends Specification { deleteInstance.buildFolderPath = Paths.get(SRC_PATH, 'build').toString() deleteInstance.projectPath = Paths.get(SRC_PATH, 'src').toString() deleteInstance.componentDeploy = new DeployMetadata() - deleteInstance.poll = 200 - deleteInstance.waitTime = 10 - deleteInstance.credential = credential deleteInstance.project.enforce.deleteTemporaryFiles = true ArrayList filesExpected = new ArrayList(); @@ -112,8 +69,8 @@ class DeleteTest extends Specification { filesExpected.add(new File(Paths.get(SRC_PATH,'src','triggers','Trigger1.trigger-meta.xml').toString())) when: - deleteInstance.pathDetele = Paths.get(deleteInstance.buildFolderPath, DIR_DELETE_FOLDER).toString() - deleteInstance.createDeploymentDirectory(deleteInstance.pathDetele) + deleteInstance.pathDelete = Paths.get(deleteInstance.buildFolderPath, Constants.DIR_DELETE_FOLDER).toString() + deleteInstance.createDeploymentDirectory(deleteInstance.pathDelete) deleteInstance.addAllFiles() deleteInstance.addFoldersToDeleteFiles() deleteInstance.addFilesToDelete() @@ -130,9 +87,6 @@ class DeleteTest extends Specification { deleteInstance.buildFolderPath = Paths.get(SRC_PATH, 'build').toString() deleteInstance.projectPath = Paths.get(SRC_PATH, 'src').toString() deleteInstance.componentDeploy = new DeployMetadata() - deleteInstance.poll = 200 - deleteInstance.waitTime = 10 - deleteInstance.credential = credential deleteInstance.project.enforce.deleteTemporaryFiles = true deleteInstance.parameters.put('folders','classes,triggers') @@ -143,8 +97,8 @@ class DeleteTest extends Specification { filesExpected.add(new File(Paths.get(SRC_PATH,'src','triggers','Trigger1.trigger-meta.xml').toString())) when: - deleteInstance.pathDetele = Paths.get(deleteInstance.buildFolderPath, DIR_DELETE_FOLDER).toString() - deleteInstance.createDeploymentDirectory(deleteInstance.pathDetele) + deleteInstance.pathDelete = Paths.get(deleteInstance.buildFolderPath, DIR_DELETE_FOLDER).toString() + deleteInstance.createDeploymentDirectory(deleteInstance.pathDelete) deleteInstance.addAllFiles() deleteInstance.addFoldersToDeleteFiles() deleteInstance.addFilesToDelete() @@ -161,9 +115,6 @@ class DeleteTest extends Specification { deleteInstance.buildFolderPath = Paths.get(SRC_PATH, 'build').toString() deleteInstance.projectPath = Paths.get(SRC_PATH, 'src').toString() deleteInstance.componentDeploy = new DeployMetadata() - deleteInstance.poll = 200 - deleteInstance.waitTime = 10 - deleteInstance.credential = credential deleteInstance.project.enforce.deleteTemporaryFiles = true deleteInstance.parameters.put('files','classes/Class1.cls') @@ -172,8 +123,8 @@ class DeleteTest extends Specification { filesExpected.add(new File(Paths.get(SRC_PATH,'src','classes','Class1.cls-meta.xml').toString())) when: - deleteInstance.pathDetele = Paths.get(deleteInstance.buildFolderPath, DIR_DELETE_FOLDER).toString() - deleteInstance.createDeploymentDirectory(deleteInstance.pathDetele) + deleteInstance.pathDelete = Paths.get(deleteInstance.buildFolderPath, DIR_DELETE_FOLDER).toString() + deleteInstance.createDeploymentDirectory(deleteInstance.pathDelete) deleteInstance.addAllFiles() deleteInstance.addFoldersToDeleteFiles() deleteInstance.addFilesToDelete() @@ -203,8 +154,8 @@ class DeleteTest extends Specification { filesExpected.add(new File(Paths.get(SRC_PATH,'src','package.xml').toString())) when: - deleteInstance.pathDetele = Paths.get(deleteInstance.buildFolderPath, DIR_DELETE_FOLDER).toString() - deleteInstance.createDeploymentDirectory(deleteInstance.pathDetele) + deleteInstance.pathDelete = Paths.get(deleteInstance.buildFolderPath, Constants.DIR_DELETE_FOLDER).toString() + deleteInstance.createDeploymentDirectory(deleteInstance.pathDelete) deleteInstance.addAllFiles() deleteInstance.addFoldersToDeleteFiles() deleteInstance.addFilesToDelete() @@ -218,11 +169,6 @@ class DeleteTest extends Specification { def cleanupSpec() { new File(Paths.get(SRC_PATH, 'build').toString()).deleteDir() - new File(Paths.get(SRC_PATH, 'classes', 'Class2.cls').toString()).delete() - new File(Paths.get(SRC_PATH, 'src', 'classes', 'Class2.cls').toString()).delete() - new File(Paths.get(SRC_PATH, 'src', 'classes', 'Class2.cls-meta.xml').toString()).delete() - new File(Paths.get(SRC_PATH, 'src', 'classes', 'Class3.cls').toString()).delete() - new File(Paths.get(SRC_PATH, 'src', 'classes', 'Class3.cls-meta.xml').toString()).delete() new File(Paths.get(SRC_PATH, 'src', '.fileTracker.data').toString()).delete() } } \ No newline at end of file From cd1206be44c649af3d5297be37e4d630f25d0eea Mon Sep 17 00:00:00 2001 From: Marcelo Oporto Fernandez Date: Fri, 5 Jun 2015 17:25:22 -0400 Subject: [PATCH 28/50] Fixed new observations --- .../tasks/salesforce/deployment/Delete.groovy | 12 ++++++++---- .../tasks/salesforce/deployment/DeleteTest.groovy | 8 ++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy index f8842ef..5b2cf42 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy @@ -9,7 +9,7 @@ import org.fundacionjala.gradle.plugins.enforce.utils.Constants import java.nio.file.Paths /** - * Updates an org using metadata API + * Deletes files into an org using metadata API */ class Delete extends Deployment { public String pathDelete @@ -40,14 +40,18 @@ class Delete extends Deployment { if( System.console().readLine(Constants.QUESTION_CONTINUE) == Constants.YES_OPTION ) { createDestructive() - createPackage() + createPackageEmpty() executeDeploy(pathDelete) } } + /** + * Adds all files into an org + */ def addAllFiles() { filesToDeleted = addAllFilesInAFolder(filesToDeleted) } + /** * Adds all files that are inside the folders */ @@ -68,7 +72,7 @@ class Delete extends Deployment { def showFilesToDelete() { logger.quiet("\nFILES TO DELETE\n") filesToDeleted.each { file-> - println "->"+file + logger.quiet(file.getAbsolutePath()) } logger.quiet(filesToDeleted.size() + " files \n") } @@ -90,7 +94,7 @@ class Delete extends Deployment { /** * Create a package empty */ - def createPackage() { + def createPackageEmpty() { writePackage(Paths.get(pathDelete, PACKAGE_NAME).toString(), []) } } \ No newline at end of file diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy index c4e65ce..cb29146 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy @@ -76,7 +76,7 @@ class DeleteTest extends Specification { deleteInstance.addFilesToDelete() deleteInstance.excludeFilesToDelete() deleteInstance.createDestructive() - deleteInstance.createPackage() + deleteInstance.createPackageEmpty() then: filesExpected.sort{ it.getAbsolutePath() }.equals( deleteInstance.filesToDeleted.sort{ it.getAbsolutePath() }) @@ -104,7 +104,7 @@ class DeleteTest extends Specification { deleteInstance.addFilesToDelete() deleteInstance.excludeFilesToDelete() deleteInstance.createDestructive() - deleteInstance.createPackage() + deleteInstance.createPackageEmpty() then: filesExpected.sort{ it.getAbsolutePath() }.equals( deleteInstance.filesToDeleted.sort{ it.getAbsolutePath() }) @@ -130,7 +130,7 @@ class DeleteTest extends Specification { deleteInstance.addFilesToDelete() deleteInstance.excludeFilesToDelete() deleteInstance.createDestructive() - deleteInstance.createPackage() + deleteInstance.createPackageEmpty() then: filesExpected.sort{ it.getAbsolutePath() }.equals( deleteInstance.filesToDeleted.sort{ it.getAbsolutePath() }) @@ -161,7 +161,7 @@ class DeleteTest extends Specification { deleteInstance.addFilesToDelete() deleteInstance.excludeFilesToDelete() deleteInstance.createDestructive() - deleteInstance.createPackage() + deleteInstance.createPackageEmpty() then: filesExpected.sort{ it.getAbsolutePath() }.equals( deleteInstance.filesToDeleted.sort{ it.getAbsolutePath() }) From 8b64d17b737fec3e910246c71dd8bbddb0eba4a7 Mon Sep 17 00:00:00 2001 From: Marcelo Oporto Fernandez Date: Fri, 5 Jun 2015 17:35:11 -0400 Subject: [PATCH 29/50] Fixed new observations --- .../enforce/tasks/salesforce/deployment/DeleteTest.groovy | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy index cb29146..4c6ec20 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy @@ -169,6 +169,5 @@ class DeleteTest extends Specification { def cleanupSpec() { new File(Paths.get(SRC_PATH, 'build').toString()).deleteDir() - new File(Paths.get(SRC_PATH, 'src', '.fileTracker.data').toString()).delete() } } \ No newline at end of file From e11d6b5276cd297007f38c8ab7748617a47b33e7 Mon Sep 17 00:00:00 2001 From: Alex Ventura Date: Fri, 5 Jun 2015 17:40:48 -0400 Subject: [PATCH 30/50] fixed when the exception was throwing a null message --- .../gradle/plugins/enforce/wsc/InspectorResults.groovy | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy index 3732ebd..d88522e 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy @@ -50,8 +50,10 @@ class InspectorResults { } deployResult = metadataConnection.checkDeployStatus(asyncResultId, true) if (deployResult.status == DeployStatus.Failed) { - String message = deployResult.errorMessage + '\n\n' + deployResult.stateDetail - throw new Exception(message) + if (deployResult.stateDetail) { + String message = deployResult.errorMessage + '\n\n' + deployResult.stateDetail + throw new Exception(message) + } } if (percent != HUNDRED) { percent = getDeployPercentage(deployResult) From 23ff596ef88086980d0363a9343029e64e1a8381 Mon Sep 17 00:00:00 2001 From: Alex Ventura Date: Fri, 5 Jun 2015 18:05:57 -0400 Subject: [PATCH 31/50] improve the code in the inspectorResults file --- .../gradle/plugins/enforce/wsc/InspectorResults.groovy | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy index d88522e..ffbc25b 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy @@ -51,8 +51,10 @@ class InspectorResults { deployResult = metadataConnection.checkDeployStatus(asyncResultId, true) if (deployResult.status == DeployStatus.Failed) { if (deployResult.stateDetail) { - String message = deployResult.errorMessage + '\n\n' + deployResult.stateDetail - throw new Exception(message) + StringBuilder message = new StringBuilder(deployResult.errorMessage) + message.append('\n\n') + message.append(deployResult.stateDetail) + throw new Exception(message.toString()) } } if (percent != HUNDRED) { From 9cad4b815f556a7d8eeab940fcf1c3c0aa9a1532 Mon Sep 17 00:00:00 2001 From: Marcelo Oporto Fernandez Date: Fri, 5 Jun 2015 18:41:01 -0400 Subject: [PATCH 32/50] Fixed observations, update delete test --- .../tasks/salesforce/deployment/DeleteTest.groovy | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy index 4c6ec20..1195a50 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy @@ -79,7 +79,7 @@ class DeleteTest extends Specification { deleteInstance.createPackageEmpty() then: - filesExpected.sort{ it.getAbsolutePath() }.equals( deleteInstance.filesToDeleted.sort{ it.getAbsolutePath() }) + filesExpected.sort().equals( deleteInstance.filesToDeleted.sort()) } def "Integration testing must list files filtered for folders to delete"() { @@ -107,7 +107,7 @@ class DeleteTest extends Specification { deleteInstance.createPackageEmpty() then: - filesExpected.sort{ it.getAbsolutePath() }.equals( deleteInstance.filesToDeleted.sort{ it.getAbsolutePath() }) + filesExpected.sort().equals( deleteInstance.filesToDeleted.sort()) } def "Integration testing must list files filtered for files to delete"() { @@ -133,7 +133,7 @@ class DeleteTest extends Specification { deleteInstance.createPackageEmpty() then: - filesExpected.sort{ it.getAbsolutePath() }.equals( deleteInstance.filesToDeleted.sort{ it.getAbsolutePath() }) + filesExpected.sort().equals( deleteInstance.filesToDeleted.sort()) } def "Integration testing must list all the files less exclude to delete"() { @@ -164,10 +164,11 @@ class DeleteTest extends Specification { deleteInstance.createPackageEmpty() then: - filesExpected.sort{ it.getAbsolutePath() }.equals( deleteInstance.filesToDeleted.sort{ it.getAbsolutePath() }) + filesExpected.sort().equals( deleteInstance.filesToDeleted.sort()) } def cleanupSpec() { new File(Paths.get(SRC_PATH, 'build').toString()).deleteDir() + new File(Paths.get(SRC_PATH, 'src', '.fileTracker.data').toString()).delete() } } \ No newline at end of file From 24d6d7533239c29d6ea31a2cfee6deca3f4abed4 Mon Sep 17 00:00:00 2001 From: Marcelo Oporto Fernandez Date: Fri, 5 Jun 2015 18:45:10 -0400 Subject: [PATCH 33/50] Fixed observations, update deleteTest --- .../enforce/tasks/salesforce/deployment/DeleteTest.groovy | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy index 1195a50..c8c5af4 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy @@ -116,11 +116,13 @@ class DeleteTest extends Specification { deleteInstance.projectPath = Paths.get(SRC_PATH, 'src').toString() deleteInstance.componentDeploy = new DeployMetadata() deleteInstance.project.enforce.deleteTemporaryFiles = true - deleteInstance.parameters.put('files','classes/Class1.cls') + deleteInstance.parameters.put('files','classes/Class1.cls,triggers/Trigger1.trigger') ArrayList filesExpected = new ArrayList(); filesExpected.add(new File(Paths.get(SRC_PATH,'src','classes','Class1.cls').toString())) filesExpected.add(new File(Paths.get(SRC_PATH,'src','classes','Class1.cls-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src','triggers','Trigger1.trigger').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src','triggers','Trigger1.trigger-meta.xml').toString())) when: deleteInstance.pathDelete = Paths.get(deleteInstance.buildFolderPath, DIR_DELETE_FOLDER).toString() From 2db930dc1052f3e3d66dc738b06400611bf0e134 Mon Sep 17 00:00:00 2001 From: Marcelo Oporto Fernandez Date: Fri, 5 Jun 2015 23:07:34 -0400 Subject: [PATCH 34/50] Updates deleteTest, update all test cases and add three new test cases --- .../salesforce/deployment/DeleteTest.groovy | 203 ++++++++++++++---- 1 file changed, 160 insertions(+), 43 deletions(-) diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy index c8c5af4..6d6994e 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy @@ -50,23 +50,66 @@ class DeleteTest extends Specification { deleteInstance.createDeploymentDirectory(Paths.get(SRC_PATH, 'build').toString()) deleteInstance.createDeploymentDirectory(Paths.get(SRC_PATH, 'build', 'delete').toString()) deleteInstance.projectPath = SRC_PATH + deleteInstance.buildFolderPath = Paths.get(SRC_PATH, 'build').toString() + deleteInstance.projectPath = Paths.get(SRC_PATH, 'src_delete').toString() + deleteInstance.componentDeploy = new DeployMetadata() + deleteInstance.project.enforce.deleteTemporaryFiles = true + + ArrayList files = new ArrayList() + files.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class1.cls').toString())) + files.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class1.cls-meta.xml').toString())) + files.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class2.cls').toString())) + files.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class2.cls-meta.xml').toString())) + files.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class3.cls').toString())) + files.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class3.cls-meta.xml').toString())) + files.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger1.trigger').toString())) + files.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger1.trigger-meta.xml').toString())) + files.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger2.trigger').toString())) + files.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger2.trigger-meta.xml').toString())) + files.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger3.trigger').toString())) + files.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger3.trigger-meta.xml').toString())) + files.add(new File(Paths.get(SRC_PATH,'src_delete','objects','Object1__c.object').toString())) + files.add(new File(Paths.get(SRC_PATH,'src_delete','objects','Object2__c.object').toString())) + files.add(new File(Paths.get(SRC_PATH,'src_delete','objects','Object3__c.object').toString())) + files.add(new File(Paths.get(SRC_PATH,'src_delete','objects','Object4__c.object').toString())) + files.add(new File(Paths.get(SRC_PATH,'src_delete','objects','Object5__c.object').toString())) + + ArrayList folders = new ArrayList() + folders.add(new File(Paths.get(SRC_PATH,'src_delete').toString())) + folders.add(new File(Paths.get(SRC_PATH,'src_delete','classes').toString())) + folders.add(new File(Paths.get(SRC_PATH,'src_delete','triggers').toString())) + folders.add(new File(Paths.get(SRC_PATH,'src_delete','objects').toString())) + folders.add(new File(Paths.get(SRC_PATH,'src_delete','test').toString())) + + folders.each { folder-> + new File(folder.getAbsolutePath()).mkdir() + } + + files.each { folder-> + new File(folder.getAbsolutePath()).createNewFile() + } } def "Integration testing must list all the files to delete"() { given: - deleteInstance.buildFolderPath = Paths.get(SRC_PATH, 'build').toString() - deleteInstance.projectPath = Paths.get(SRC_PATH, 'src').toString() - deleteInstance.componentDeploy = new DeployMetadata() - deleteInstance.project.enforce.deleteTemporaryFiles = true - ArrayList filesExpected = new ArrayList(); - filesExpected.add(new File(Paths.get(SRC_PATH,'src','classes','Class1.cls').toString())) - filesExpected.add(new File(Paths.get(SRC_PATH,'src','classes','Class1.cls-meta.xml').toString())) - filesExpected.add(new File(Paths.get(SRC_PATH,'src','objects','Account.object').toString())) - filesExpected.add(new File(Paths.get(SRC_PATH,'src','objects','Object1__c.object').toString())) - filesExpected.add(new File(Paths.get(SRC_PATH,'src','package.xml').toString())) - filesExpected.add(new File(Paths.get(SRC_PATH,'src','triggers','Trigger1.trigger').toString())) - filesExpected.add(new File(Paths.get(SRC_PATH,'src','triggers','Trigger1.trigger-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class1.cls').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class1.cls-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class2.cls').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class2.cls-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class3.cls').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class3.cls-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger1.trigger').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger1.trigger-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger2.trigger').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger2.trigger-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger3.trigger').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger3.trigger-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','objects','Object1__c.object').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','objects','Object2__c.object').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','objects','Object3__c.object').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','objects','Object4__c.object').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','objects','Object5__c.object').toString())) when: deleteInstance.pathDelete = Paths.get(deleteInstance.buildFolderPath, Constants.DIR_DELETE_FOLDER).toString() @@ -79,22 +122,26 @@ class DeleteTest extends Specification { deleteInstance.createPackageEmpty() then: - filesExpected.sort().equals( deleteInstance.filesToDeleted.sort()) + filesExpected.sort().equals(deleteInstance.filesToDeleted.sort()) } def "Integration testing must list files filtered for folders to delete"() { given: - deleteInstance.buildFolderPath = Paths.get(SRC_PATH, 'build').toString() - deleteInstance.projectPath = Paths.get(SRC_PATH, 'src').toString() - deleteInstance.componentDeploy = new DeployMetadata() - deleteInstance.project.enforce.deleteTemporaryFiles = true deleteInstance.parameters.put('folders','classes,triggers') ArrayList filesExpected = new ArrayList(); - filesExpected.add(new File(Paths.get(SRC_PATH,'src','classes','Class1.cls').toString())) - filesExpected.add(new File(Paths.get(SRC_PATH,'src','classes','Class1.cls-meta.xml').toString())) - filesExpected.add(new File(Paths.get(SRC_PATH,'src','triggers','Trigger1.trigger').toString())) - filesExpected.add(new File(Paths.get(SRC_PATH,'src','triggers','Trigger1.trigger-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class1.cls').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class1.cls-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class2.cls').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class2.cls-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class3.cls').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class3.cls-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger1.trigger').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger1.trigger-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger2.trigger').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger2.trigger-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger3.trigger').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger3.trigger-meta.xml').toString())) when: deleteInstance.pathDelete = Paths.get(deleteInstance.buildFolderPath, DIR_DELETE_FOLDER).toString() @@ -107,22 +154,18 @@ class DeleteTest extends Specification { deleteInstance.createPackageEmpty() then: - filesExpected.sort().equals( deleteInstance.filesToDeleted.sort()) + filesExpected.sort().equals(deleteInstance.filesToDeleted.sort()) } def "Integration testing must list files filtered for files to delete"() { given: - deleteInstance.buildFolderPath = Paths.get(SRC_PATH, 'build').toString() - deleteInstance.projectPath = Paths.get(SRC_PATH, 'src').toString() - deleteInstance.componentDeploy = new DeployMetadata() - deleteInstance.project.enforce.deleteTemporaryFiles = true deleteInstance.parameters.put('files','classes/Class1.cls,triggers/Trigger1.trigger') ArrayList filesExpected = new ArrayList(); - filesExpected.add(new File(Paths.get(SRC_PATH,'src','classes','Class1.cls').toString())) - filesExpected.add(new File(Paths.get(SRC_PATH,'src','classes','Class1.cls-meta.xml').toString())) - filesExpected.add(new File(Paths.get(SRC_PATH,'src','triggers','Trigger1.trigger').toString())) - filesExpected.add(new File(Paths.get(SRC_PATH,'src','triggers','Trigger1.trigger-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class1.cls').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class1.cls-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger1.trigger').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger1.trigger-meta.xml').toString())) when: deleteInstance.pathDelete = Paths.get(deleteInstance.buildFolderPath, DIR_DELETE_FOLDER).toString() @@ -135,25 +178,98 @@ class DeleteTest extends Specification { deleteInstance.createPackageEmpty() then: - filesExpected.sort().equals( deleteInstance.filesToDeleted.sort()) + filesExpected.sort().equals(deleteInstance.filesToDeleted.sort()) } def "Integration testing must list all the files less exclude to delete"() { given: - deleteInstance.buildFolderPath = Paths.get(SRC_PATH, 'build').toString() - deleteInstance.projectPath = Paths.get(SRC_PATH, 'src').toString() - deleteInstance.componentDeploy = new DeployMetadata() - deleteInstance.poll = 200 - deleteInstance.waitTime = 10 - deleteInstance.credential = credential - deleteInstance.project.enforce.deleteTemporaryFiles = true + deleteInstance.parameters.put('excludes','classes/Class1.cls,triggers/*.trigger') - deleteInstance.parameters.put('excludes','classes/Class1.cls,triggers/Trigger1.trigger') + ArrayList filesExpected = new ArrayList(); + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class2.cls').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class2.cls-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class3.cls').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class3.cls-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','objects','Object1__c.object').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','objects','Object2__c.object').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','objects','Object3__c.object').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','objects','Object4__c.object').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','objects','Object5__c.object').toString())) + + when: + deleteInstance.pathDelete = Paths.get(deleteInstance.buildFolderPath, Constants.DIR_DELETE_FOLDER).toString() + deleteInstance.createDeploymentDirectory(deleteInstance.pathDelete) + deleteInstance.addAllFiles() + deleteInstance.addFoldersToDeleteFiles() + deleteInstance.addFilesToDelete() + deleteInstance.excludeFilesToDelete() + deleteInstance.createDestructive() + deleteInstance.createPackageEmpty() + + then: + filesExpected.sort().equals( deleteInstance.filesToDeleted.sort()) + } + + def "Integration testing must list all the files less exclude all objects and classes"() { + given: + deleteInstance.parameters.put('folders','classes,triggers,objects') + deleteInstance.parameters.put('excludes','classes/*.cls,objects/**') + + ArrayList filesExpected = new ArrayList(); + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger1.trigger').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger1.trigger-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger2.trigger').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger2.trigger-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger3.trigger').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger3.trigger-meta.xml').toString())) + + when: + deleteInstance.pathDelete = Paths.get(deleteInstance.buildFolderPath, Constants.DIR_DELETE_FOLDER).toString() + deleteInstance.createDeploymentDirectory(deleteInstance.pathDelete) + deleteInstance.addAllFiles() + deleteInstance.addFoldersToDeleteFiles() + deleteInstance.addFilesToDelete() + deleteInstance.excludeFilesToDelete() + deleteInstance.createDestructive() + deleteInstance.createPackageEmpty() + + then: + filesExpected.sort().equals( deleteInstance.filesToDeleted.sort()) + } + + def "Integration testing must list all the files less exclude all files that contain the number 1 or 2"() { + given: + deleteInstance.parameters.put('folders','classes,triggers,objects') + deleteInstance.parameters.put('excludes','*/*1*.*,*/*2*.*') + + ArrayList filesExpected = new ArrayList(); + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class3.cls').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class3.cls-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger3.trigger').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','triggers','Trigger3.trigger-meta.xml').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','objects','Object3__c.object').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','objects','Object4__c.object').toString())) + filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','objects','Object5__c.object').toString())) + + when: + deleteInstance.pathDelete = Paths.get(deleteInstance.buildFolderPath, Constants.DIR_DELETE_FOLDER).toString() + deleteInstance.createDeploymentDirectory(deleteInstance.pathDelete) + deleteInstance.addAllFiles() + deleteInstance.addFoldersToDeleteFiles() + deleteInstance.addFilesToDelete() + deleteInstance.excludeFilesToDelete() + deleteInstance.createDestructive() + deleteInstance.createPackageEmpty() + + then: + filesExpected.sort().equals( deleteInstance.filesToDeleted.sort()) + } + + def "Integration testing must list all the files less exclude all files"() { + given: + deleteInstance.parameters.put('excludes','*/**.*') ArrayList filesExpected = new ArrayList(); - filesExpected.add(new File(Paths.get(SRC_PATH,'src','objects','Account.object').toString())) - filesExpected.add(new File(Paths.get(SRC_PATH,'src','objects','Object1__c.object').toString())) - filesExpected.add(new File(Paths.get(SRC_PATH,'src','package.xml').toString())) when: deleteInstance.pathDelete = Paths.get(deleteInstance.buildFolderPath, Constants.DIR_DELETE_FOLDER).toString() @@ -171,6 +287,7 @@ class DeleteTest extends Specification { def cleanupSpec() { new File(Paths.get(SRC_PATH, 'build').toString()).deleteDir() - new File(Paths.get(SRC_PATH, 'src', '.fileTracker.data').toString()).delete() + new File(Paths.get(SRC_PATH,'src_delete').toString()).deleteDir() + new File(Paths.get(SRC_PATH, 'src_delete', '.fileTracker.data').toString()).delete() } } \ No newline at end of file From c7c4638835fd8aaaf57b03ba82a820963e5fef26 Mon Sep 17 00:00:00 2001 From: Marcelo Oporto Fernandez Date: Fri, 5 Jun 2015 23:11:56 -0400 Subject: [PATCH 35/50] Change variable's name and modify one expect value --- .../tasks/salesforce/deployment/DeleteTest.groovy | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy index 6d6994e..23fcb1d 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy @@ -85,8 +85,8 @@ class DeleteTest extends Specification { new File(folder.getAbsolutePath()).mkdir() } - files.each { folder-> - new File(folder.getAbsolutePath()).createNewFile() + files.each { file-> + new File(file.getAbsolutePath()).createNewFile() } } @@ -268,9 +268,6 @@ class DeleteTest extends Specification { def "Integration testing must list all the files less exclude all files"() { given: deleteInstance.parameters.put('excludes','*/**.*') - - ArrayList filesExpected = new ArrayList(); - when: deleteInstance.pathDelete = Paths.get(deleteInstance.buildFolderPath, Constants.DIR_DELETE_FOLDER).toString() deleteInstance.createDeploymentDirectory(deleteInstance.pathDelete) @@ -282,7 +279,7 @@ class DeleteTest extends Specification { deleteInstance.createPackageEmpty() then: - filesExpected.sort().equals( deleteInstance.filesToDeleted.sort()) + deleteInstance.filesToDeleted.isEmpty() } def cleanupSpec() { From 049108c155d20c84a98d06452cdbb58ac187227a Mon Sep 17 00:00:00 2001 From: marco_cadima Date: Mon, 8 Jun 2015 11:50:27 -0400 Subject: [PATCH 36/50] Bug :"Update task doesn't copy xml file of folder into build directory" was fixed --- .../plugins/enforce/tasks/salesforce/deployment/Update.groovy | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Update.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Update.groovy index fd012ad..f186d2f 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Update.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Update.groovy @@ -124,9 +124,13 @@ class Update extends Deployment { def copyFilesChanged() { filesToCopy.each { file -> File xmlFile = fileManager.getValidateXmlFile(file) + File xmlFolder = fileManager.getValidateXmlFile(file.getParentFile()) if (xmlFile) { filesToUpdate.push(xmlFile) } + if (xmlFolder) { + filesToUpdate.push(xmlFolder) + } filesToUpdate.push(file) } fileManager.copy(projectPath, filesToUpdate, pathUpdate) From 52b561d442266b11c320a36fd490ded6be4dbc91 Mon Sep 17 00:00:00 2001 From: Marcelo Oporto Fernandez Date: Mon, 8 Jun 2015 14:24:00 -0400 Subject: [PATCH 37/50] Delete task now support documents --- .../tasks/salesforce/deployment/Delete.groovy | 18 +++++++++---- .../salesforce/deployment/Deployment.groovy | 10 ++++++- .../enforce/utils/ManagementFile.groovy | 26 ------------------- .../salesforce/deployment/DeleteTest.groovy | 25 ++++++++++++++++++ 4 files changed, 47 insertions(+), 32 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy index 5b2cf42..3bb634e 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy @@ -6,6 +6,8 @@ package org.fundacionjala.gradle.plugins.enforce.tasks.salesforce.deployment import org.fundacionjala.gradle.plugins.enforce.utils.Constants +import org.fundacionjala.gradle.plugins.enforce.utils.Util + import java.nio.file.Paths /** @@ -70,11 +72,15 @@ class Delete extends Deployment { * Shows files to delete */ def showFilesToDelete() { - logger.quiet("\nFILES TO DELETE\n") - filesToDeleted.each { file-> - logger.quiet(file.getAbsolutePath()) + logger.quiet("\nCOMPONENTS TO DELETE\n") + def numComponentes = 0; + filesToDeleted.each { File file -> + if (!file.getName().endsWith("xml")) { + logger.quiet(Util.getRelativePath(file, projectPath)) + numComponentes++ + } } - logger.quiet(filesToDeleted.size() + " files \n") + logger.quiet(filesToDeleted.size() + " componentes \n") } /** @@ -88,7 +94,9 @@ class Delete extends Deployment { * Creates packages to all files which has been deleted */ def createDestructive() { - writePackage(Paths.get(pathDelete, PACKAGE_NAME_DESTRUCTIVE).toString(), filesToDeleted) + String destructivePath = Paths.get(pathDelete, PACKAGE_NAME_DESTRUCTIVE).toString() + writePackage(destructivePath, filesToDeleted) + combinePackageToUpdate(destructivePath) } /** diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy index 92eec77..fcee9fb 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy @@ -187,8 +187,16 @@ abstract class Deployment extends SalesforceTask { * @return files list of files with the new files added */ def addAllFilesInAFolder(ArrayList files) { + + if (!Util.isValidProperty(parameters, Constants.PARAMETER_FOLDERS) && !Util.isValidProperty(parameters, Constants.PARAMETER_FILES)) { - files.addAll(fileManager.getAllFilesOf(projectPath)) + // files.addAll(fileManager.getAllFilesOf(projectPath)) + ArrayList sourceFiles = fileManager.getValidElements(projectPath) + sourceFiles.remove(new File(Paths.get(projectPath, Constants.PACKAGE_FILE_NAME).toString())) + files.addAll(sourceFiles) + println (new File(Paths.get(projectPath, Constants.PACKAGE_FILE_NAME).toString())) + + } return files } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy index 6335b16..2196d0b 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/ManagementFile.groovy @@ -277,32 +277,6 @@ class ManagementFile { return filesByFolder } - /** - * Gets array valid files by folders - * @param sourcePath is type String - * @return files validated by folders and subfolders - */ - public ArrayList getAllFilesOf(String sourcePath) { - ArrayList files = new ArrayList() - File folder = new File(sourcePath) - if(folder.isDirectory()) { - folder.eachFile { file -> - SalesforceValidator validator = SalesforceValidatorManager.getValidator(folder.getName()) - if (validator.validateFileByFolder(folder.getName(), file)) { - File xmlFile = new File("${file.getAbsolutePath().toString()}${METADATA_EXTENSION}") - if (xmlFile.exists()) { - files.push(xmlFile) - } - } - files.addAll(getAllFilesOf(file.getAbsolutePath().toString())) - } - } - else { - files.push(folder) - } - return files - } - /** * Gets array valid files by folder * @param folders is type ArrayList diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy index 23fcb1d..e89d139 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy @@ -11,6 +11,7 @@ import org.fundacionjala.gradle.plugins.enforce.filemonitor.ComponentSerializer import org.fundacionjala.gradle.plugins.enforce.metadata.DeployMetadata import org.fundacionjala.gradle.plugins.enforce.utils.Constants import org.fundacionjala.gradle.plugins.enforce.utils.ManagementFile +import org.fundacionjala.gradle.plugins.enforce.utils.Util import org.fundacionjala.gradle.plugins.enforce.wsc.Credential import org.gradle.api.Project import org.gradle.testfixtures.ProjectBuilder @@ -54,6 +55,7 @@ class DeleteTest extends Specification { deleteInstance.projectPath = Paths.get(SRC_PATH, 'src_delete').toString() deleteInstance.componentDeploy = new DeployMetadata() deleteInstance.project.enforce.deleteTemporaryFiles = true + deleteInstance.projectPackagePath = Paths.get(SRC_PATH,'src_delete', 'package.xml').toString() ArrayList files = new ArrayList() files.add(new File(Paths.get(SRC_PATH,'src_delete','classes','Class1.cls').toString())) @@ -88,6 +90,27 @@ class DeleteTest extends Specification { files.each { file-> new File(file.getAbsolutePath()).createNewFile() } + + String packageXmlPath = deleteInstance.projectPackagePath + String packageXmlContent =''' + + + * + ApexClass + + + * + ApexTrigger + + + * + CustomObject + + 32.0 + + ''' + File filePackageXml = new File(packageXmlPath) + filePackageXml.write(packageXmlContent) } def "Integration testing must list all the files to delete"() { @@ -251,6 +274,8 @@ class DeleteTest extends Specification { filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','objects','Object4__c.object').toString())) filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','objects','Object5__c.object').toString())) + + when: deleteInstance.pathDelete = Paths.get(deleteInstance.buildFolderPath, Constants.DIR_DELETE_FOLDER).toString() deleteInstance.createDeploymentDirectory(deleteInstance.pathDelete) From 47d93a06e6e0b255346f1d45b70d4d392b722f74 Mon Sep 17 00:00:00 2001 From: Alex Ventura Date: Tue, 9 Jun 2015 18:20:20 -0400 Subject: [PATCH 38/50] implemented suggestion when the task throw a exception Processing only for documents,dashboard,reports --- .../suggestions/SuggestionManager.groovy | 27 +++++++++++++++++++ .../enforce/wsc/InspectorResults.groovy | 8 ++++-- .../suggestions/SuggestionManagerTest.groovy | 27 +++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/suggestions/SuggestionManager.groovy create mode 100644 src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/suggestions/SuggestionManagerTest.groovy diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/suggestions/SuggestionManager.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/suggestions/SuggestionManager.groovy new file mode 100644 index 0000000..b9e744c --- /dev/null +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/suggestions/SuggestionManager.groovy @@ -0,0 +1,27 @@ +package org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.suggestions + +import org.fundacionjala.gradle.plugins.enforce.utils.Constants +import org.fundacionjala.gradle.plugins.enforce.utils.ManagementFile + +import java.nio.file.Paths + +/** + * Created by alex_ventura on 09-06-15. + */ +public class SuggestionManager { + public static String PROCESSING = 'Processing' + public static String processStateDetail(String stateDetail) { + StringBuilder result = new StringBuilder() + if (stateDetail.startsWith(PROCESSING)) { + String filePath = stateDetail.replaceFirst(PROCESSING, "").trim() + String parentPath = Paths.get(filePath).getName(0) + if (parentPath != filePath) { + String folder = parentPath + result.append("Make sure the $folder") + result.append(' folder has xml file and it is defined in the package.xml') + } + } + + return result.toString(); + } +} diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy index ffbc25b..747f701 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy @@ -11,6 +11,7 @@ import com.sforce.soap.metadata.MetadataConnection import com.sforce.soap.metadata.RetrieveResult import org.fundacionjala.gradle.plugins.enforce.utils.Constants import org.fundacionjala.gradle.plugins.enforce.utils.Util +import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.suggestions.SuggestionManager import java.nio.charset.Charset @@ -51,9 +52,12 @@ class InspectorResults { deployResult = metadataConnection.checkDeployStatus(asyncResultId, true) if (deployResult.status == DeployStatus.Failed) { if (deployResult.stateDetail) { - StringBuilder message = new StringBuilder(deployResult.errorMessage) - message.append('\n\n') + StringBuilder message = new StringBuilder() + message.append('\n') message.append(deployResult.stateDetail) + message.append("\n\nSuggestions:") + message.append("\n") + message.append(SuggestionManager.processStateDetail(deployResult.stateDetail)) throw new Exception(message.toString()) } } diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/suggestions/SuggestionManagerTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/suggestions/SuggestionManagerTest.groovy new file mode 100644 index 0000000..e738681 --- /dev/null +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/suggestions/SuggestionManagerTest.groovy @@ -0,0 +1,27 @@ +package org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.suggestions + +import spock.lang.Specification + +class SuggestionManagerTest extends Specification { + + + def "Should returns a suggestion when the error is Processing DocumentTest/documenttest.docx"() { + given: + String stateDetail = 'Processing DocumentTest/documenttest.docx' + String expected = 'Make sure the DocumentTest folder has xml file and it is defined in the package.xml' + when: + String sugesstion = SuggestionManager.processStateDetail(stateDetail) + then: + expected == sugesstion + } + + def "Should returns a suggestion when the error is Processing ReportTest/reporttest.docx"() { + given: + String stateDetail = 'Processing ReportTest/reporttest.docx' + String expected = 'Make sure the ReportTest folder has xml file and it is defined in the package.xml' + when: + String sugesstion = SuggestionManager.processStateDetail(stateDetail) + then: + expected == sugesstion + } +} From b82cb5f807a1d70296c04da6250e89494c138643 Mon Sep 17 00:00:00 2001 From: Alex Ventura Date: Tue, 9 Jun 2015 18:46:41 -0400 Subject: [PATCH 39/50] changed the suggestion in the reports documents failed --- .../component/suggestions/SuggestionManager.groovy | 6 +++--- .../gradle/plugins/enforce/wsc/InspectorResults.groovy | 1 - .../component/suggestions/SuggestionManagerTest.groovy | 10 +++++----- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/suggestions/SuggestionManager.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/suggestions/SuggestionManager.groovy index b9e744c..7b20da4 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/suggestions/SuggestionManager.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/suggestions/SuggestionManager.groovy @@ -9,7 +9,7 @@ import java.nio.file.Paths * Created by alex_ventura on 09-06-15. */ public class SuggestionManager { - public static String PROCESSING = 'Processing' + public static final String PROCESSING = 'Processing' public static String processStateDetail(String stateDetail) { StringBuilder result = new StringBuilder() if (stateDetail.startsWith(PROCESSING)) { @@ -17,8 +17,8 @@ public class SuggestionManager { String parentPath = Paths.get(filePath).getName(0) if (parentPath != filePath) { String folder = parentPath - result.append("Make sure the $folder") - result.append(' folder has xml file and it is defined in the package.xml') + result.append("Salesforce has reported an unexpected error:\n A common cause is about $folder") + result.append(' folder doesn´t have a respective XML file or it is not defined in the package.xml') } } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy index 747f701..c7a2420 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy @@ -55,7 +55,6 @@ class InspectorResults { StringBuilder message = new StringBuilder() message.append('\n') message.append(deployResult.stateDetail) - message.append("\n\nSuggestions:") message.append("\n") message.append(SuggestionManager.processStateDetail(deployResult.stateDetail)) throw new Exception(message.toString()) diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/suggestions/SuggestionManagerTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/suggestions/SuggestionManagerTest.groovy index e738681..5251541 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/suggestions/SuggestionManagerTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/suggestions/SuggestionManagerTest.groovy @@ -8,7 +8,7 @@ class SuggestionManagerTest extends Specification { def "Should returns a suggestion when the error is Processing DocumentTest/documenttest.docx"() { given: String stateDetail = 'Processing DocumentTest/documenttest.docx' - String expected = 'Make sure the DocumentTest folder has xml file and it is defined in the package.xml' + String expected = 'Salesforce has reported an unexpected error:\n A common cause is about DocumentTest folder doesn´t have a respective XML file or it is not defined in the package.xml' when: String sugesstion = SuggestionManager.processStateDetail(stateDetail) then: @@ -17,11 +17,11 @@ class SuggestionManagerTest extends Specification { def "Should returns a suggestion when the error is Processing ReportTest/reporttest.docx"() { given: - String stateDetail = 'Processing ReportTest/reporttest.docx' - String expected = 'Make sure the ReportTest folder has xml file and it is defined in the package.xml' + String stateDetail = 'Processing ReportTest/reporttest.docx' + String expected = 'Salesforce has reported an unexpected error:\n A common cause is about ReportTest folder doesn´t have a respective XML file or it is not defined in the package.xml' when: - String sugesstion = SuggestionManager.processStateDetail(stateDetail) + String sugesstion = SuggestionManager.processStateDetail(stateDetail) then: - expected == sugesstion + expected == sugesstion } } From 0f38c4cc617f8fb2c9c1b0137d012bb0b1d9bb52 Mon Sep 17 00:00:00 2001 From: Alex Ventura Date: Tue, 9 Jun 2015 19:15:13 -0400 Subject: [PATCH 40/50] added documentations in the SuggestionManager --- .../component/suggestions/SuggestionManager.groovy | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/suggestions/SuggestionManager.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/suggestions/SuggestionManager.groovy index 7b20da4..58b1373 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/suggestions/SuggestionManager.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/suggestions/SuggestionManager.groovy @@ -1,12 +1,11 @@ package org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.suggestions import org.fundacionjala.gradle.plugins.enforce.utils.Constants -import org.fundacionjala.gradle.plugins.enforce.utils.ManagementFile import java.nio.file.Paths /** - * Created by alex_ventura on 09-06-15. + * Manager to generate suggestion when the task failed */ public class SuggestionManager { public static final String PROCESSING = 'Processing' @@ -14,7 +13,7 @@ public class SuggestionManager { StringBuilder result = new StringBuilder() if (stateDetail.startsWith(PROCESSING)) { String filePath = stateDetail.replaceFirst(PROCESSING, "").trim() - String parentPath = Paths.get(filePath).getName(0) + String parentPath = Paths.get(filePath).getName(Constants.ZERO) if (parentPath != filePath) { String folder = parentPath result.append("Salesforce has reported an unexpected error:\n A common cause is about $folder") From 0e3858ea9723da48eb1fdf90086aeb122baadadb Mon Sep 17 00:00:00 2001 From: Marcelo Oporto Fernandez Date: Tue, 9 Jun 2015 19:34:21 -0400 Subject: [PATCH 41/50] Fixed observations pre build construction --- .../tasks/salesforce/deployment/Delete.groovy | 47 +++++++++++++++++-- .../plugins/enforce/utils/Constants.groovy | 7 ++- .../enforce/wsc/InspectorResults.groovy | 2 +- .../salesforce/deployment/DeleteTest.groovy | 2 - 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy index 3bb634e..dbfd3dd 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy @@ -33,6 +33,8 @@ class Delete extends Deployment { @Override void runTask() { pathDelete = Paths.get(buildFolderPath, Constants.DIR_DELETE_FOLDER).toString() + componentDeploy.startMessage = Constants.START_DELETE_TASK + componentDeploy.successMessage = Constants.SUCCESSFULLY_DELETE_TASK createDeploymentDirectory(pathDelete) addAllFiles() addFoldersToDeleteFiles() @@ -40,11 +42,14 @@ class Delete extends Deployment { excludeFilesToDelete() showFilesToDelete() - if( System.console().readLine(Constants.QUESTION_CONTINUE) == Constants.YES_OPTION ) { + if( System.console().readLine("\n"+Constants.QUESTION_CONTINUE_DELETE) == Constants.YES_OPTION ) { createDestructive() createPackageEmpty() executeDeploy(pathDelete) } + else { + logger.quiet(Constants.PROCCES_DELETE_CANCELLED) + } } /** @@ -72,15 +77,49 @@ class Delete extends Deployment { * Shows files to delete */ def showFilesToDelete() { - logger.quiet("\nCOMPONENTS TO DELETE\n") def numComponentes = 0; + def limit = 15; + def nameFolder = "" + ArrayList showFiles = new ArrayList(); filesToDeleted.each { File file -> if (!file.getName().endsWith("xml")) { - logger.quiet(Util.getRelativePath(file, projectPath)) numComponentes++ + showFiles.add(file) + } + } + showFiles.sort{it.getAbsolutePath()} + + logger.quiet("*********************************************") + logger.quiet(" Components to delete ") + logger.quiet("*********************************************") + if(numComponentes == 0) { + logger.quiet("There are not files deleted") + } + else if(numComponentes > limit) { + def numFiles = 0; + def fatherName; + nameFolder = showFiles[0].getParentFile().getName() + showFiles.each { File file -> + fatherName = file.getParentFile().getName() + if(!fatherName.equals(nameFolder)) { + logger.quiet("[ " + numFiles + " ] " + nameFolder) + nameFolder = fatherName + numFiles = 0; + } + numFiles++; + } + logger.quiet("[ " + numFiles + " ] " + fatherName) + logger.quiet(numComponentes+" components") + } + else + { + showFiles.each { File file -> + logger.quiet( Util.getRelativePath(file, projectPath)) } + logger.quiet(numComponentes+" components") } - logger.quiet(filesToDeleted.size() + " componentes \n") + logger.quiet("*********************************************") + } /** diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy index 2054626..a2b8d9a 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy @@ -82,7 +82,8 @@ public class Constants { //Upload task constants public static final String UPLOAD_DESCRIPTION = "This task uploads all specific files or folders as user wants" public static final String ALL_FILES_UPLOAD = "All files will be uploaded from: " - public static final String QUESTION_CONTINUE = " Do you want to continue? (y/n) :" + public static final String QUESTION_CONTINUE = "Do you want to continue? (y/n) :" + public static final String QUESTION_CONTINUE_DELETE = "Do you want delete this files into your organization? (y/n) :" public static final String UPLOAD_CANCELED ='Upload all files was canceled!!' public static final String DIR_UPLOAD_FOLDER = "upload" public static final String FILES_TO_UPLOAD = "files" @@ -101,7 +102,9 @@ public class Constants { public static final String RETRIEVE_QUESTION_TO_CONTINUE = 'Do you want to continue? (y/n) : ' //Delete task constants + public static final String START_DELETE_TASK = 'Start process to deleted' + public static final String SUCCESSFULLY_DELETE_TASK = 'The files were successfully deleted' public static final String DESCRIPTION_DELETE_TASK = "This task deploys just the files that were changed" public static final String DIR_DELETE_FOLDER = "delete" - + public static final String PROCCES_DELETE_CANCELLED = "The delete process was canceled" } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy index ffbc25b..7bba7fa 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/InspectorResults.groovy @@ -110,7 +110,7 @@ class InspectorResults { progressBar.append("] ${deployResult.numberComponentsDeployed}/${deployResult.numberComponentsTotal}(${percent}%)"); outputStream.write("\r${progressBar.toString()}".getBytes(Charset.forName("UTF-8"))) } else { - outputStream.write(Util.getBytes("\r\nDeploy Status: ${deployResult.status}...", "UTF-8")) + outputStream.write(Util.getBytes("\r\nProcess status: ${deployResult.status}...", "UTF-8")) } outputStream.flush() } diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy index e89d139..3f79997 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/DeleteTest.groovy @@ -274,8 +274,6 @@ class DeleteTest extends Specification { filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','objects','Object4__c.object').toString())) filesExpected.add(new File(Paths.get(SRC_PATH,'src_delete','objects','Object5__c.object').toString())) - - when: deleteInstance.pathDelete = Paths.get(deleteInstance.buildFolderPath, Constants.DIR_DELETE_FOLDER).toString() deleteInstance.createDeploymentDirectory(deleteInstance.pathDelete) From 912a1db34d7acea196e6902a6f61a994d314ef06 Mon Sep 17 00:00:00 2001 From: Marcelo Oporto Fernandez Date: Tue, 9 Jun 2015 19:38:06 -0400 Subject: [PATCH 42/50] Fixed observations pre build construction --- .../enforce/tasks/salesforce/deployment/Deployment.groovy | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy index fcee9fb..e294382 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy @@ -187,16 +187,10 @@ abstract class Deployment extends SalesforceTask { * @return files list of files with the new files added */ def addAllFilesInAFolder(ArrayList files) { - - if (!Util.isValidProperty(parameters, Constants.PARAMETER_FOLDERS) && !Util.isValidProperty(parameters, Constants.PARAMETER_FILES)) { - // files.addAll(fileManager.getAllFilesOf(projectPath)) ArrayList sourceFiles = fileManager.getValidElements(projectPath) sourceFiles.remove(new File(Paths.get(projectPath, Constants.PACKAGE_FILE_NAME).toString())) files.addAll(sourceFiles) - println (new File(Paths.get(projectPath, Constants.PACKAGE_FILE_NAME).toString())) - - } return files } From 736afb162ba9a6a12e68fce17dcab2dc919fd0c6 Mon Sep 17 00:00:00 2001 From: Marcelo Oporto Fernandez Date: Tue, 9 Jun 2015 20:19:37 -0400 Subject: [PATCH 43/50] Fixed observations in precode review --- .../tasks/salesforce/deployment/Delete.groovy | 31 +++++-------------- .../plugins/enforce/utils/Constants.groovy | 1 + 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy index dbfd3dd..cecffad 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy @@ -77,38 +77,24 @@ class Delete extends Deployment { * Shows files to delete */ def showFilesToDelete() { - def numComponentes = 0; def limit = 15; - def nameFolder = "" - ArrayList showFiles = new ArrayList(); - filesToDeleted.each { File file -> - if (!file.getName().endsWith("xml")) { - numComponentes++ - showFiles.add(file) - } + ArrayList showFiles = filesToDeleted.findAll { File file -> + !file.getName().endsWith("xml") } - showFiles.sort{it.getAbsolutePath()} + def numComponentes = showFiles.size() logger.quiet("*********************************************") logger.quiet(" Components to delete ") logger.quiet("*********************************************") if(numComponentes == 0) { - logger.quiet("There are not files deleted") + logger.quiet(Constants.NOT_FILES_DELETED) } else if(numComponentes > limit) { - def numFiles = 0; - def fatherName; - nameFolder = showFiles[0].getParentFile().getName() - showFiles.each { File file -> - fatherName = file.getParentFile().getName() - if(!fatherName.equals(nameFolder)) { - logger.quiet("[ " + numFiles + " ] " + nameFolder) - nameFolder = fatherName - numFiles = 0; - } - numFiles++; + showFiles.groupBy { File file -> + file.getParentFile().getName() + }.each { group, files -> + logger.quiet("[ " + files.size() + " ] " + group) } - logger.quiet("[ " + numFiles + " ] " + fatherName) logger.quiet(numComponentes+" components") } else @@ -119,7 +105,6 @@ class Delete extends Deployment { logger.quiet(numComponentes+" components") } logger.quiet("*********************************************") - } /** diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy index a2b8d9a..f719101 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy @@ -107,4 +107,5 @@ public class Constants { public static final String DESCRIPTION_DELETE_TASK = "This task deploys just the files that were changed" public static final String DIR_DELETE_FOLDER = "delete" public static final String PROCCES_DELETE_CANCELLED = "The delete process was canceled" + public static final String NOT_FILES_DELETED = "There are not files to delete" } From 72814dfc93d3472ce139e374b755b95f35ca7180 Mon Sep 17 00:00:00 2001 From: Marcelo Oporto Fernandez Date: Tue, 9 Jun 2015 20:24:37 -0400 Subject: [PATCH 44/50] Fixed observations in second precode review --- .../enforce/tasks/salesforce/deployment/Delete.groovy | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy index cecffad..fabb30a 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy @@ -77,7 +77,7 @@ class Delete extends Deployment { * Shows files to delete */ def showFilesToDelete() { - def limit = 15; + def limit = 15 ArrayList showFiles = filesToDeleted.findAll { File file -> !file.getName().endsWith("xml") } @@ -97,8 +97,7 @@ class Delete extends Deployment { } logger.quiet(numComponentes+" components") } - else - { + else { showFiles.each { File file -> logger.quiet( Util.getRelativePath(file, projectPath)) } From 9c5f3f8388dbb3bc7129f6ff500c5819fde710ff Mon Sep 17 00:00:00 2001 From: Rodrigo Ruiz Date: Tue, 9 Jun 2015 22:01:42 -0400 Subject: [PATCH 45/50] Observations were applied to delete temporary files --- .../tasks/salesforce/SalesforceTask.groovy | 42 +++++++++++++------ .../salesforce/unittest/RunTestTask.groovy | 1 + .../plugins/enforce/utils/Constants.groovy | 1 + 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy index d2c560c..1dd21a2 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy @@ -192,26 +192,41 @@ abstract class SalesforceTask extends ForceTask { } /** - * Deletes a directory excluding another specific directory - * @param dirToDelete the directory to delete - * @param dirToExclude the directory to exclude + * Deletes a directory excluding others directories + * @param directoryToDelete + * @param directoriesToExclude */ - public void deleteDir(String dirToDelete, String dirToExclude) { + public void deleteDir(String directoryToDelete, ArrayList directoriesToExclude){ String tempDirPath = System.getProperty(Constants.TEMP_DIR_PATH) File tempDir = new File(Paths.get(tempDirPath, "${Constants.TEMP_FOLDER_NAME}${Long.toString(System.nanoTime())}").toString()) if (!tempDir.mkdir()) { throw new IOException("${Constants.IO_MESSAGE_TEMP_DIR}: ${tempDir.getAbsolutePath()}"); } - project.copy { - from dirToExclude - into tempDir.absolutePath + if(directoriesToExclude && directoriesToExclude.size() > 0){ + directoriesToExclude.each { directory -> + if(new File(directory).exists()) { + project.copy { + from directory + into "${tempDir.absolutePath}${File.separator}${Paths.get(directory).fileName.toString()}" + } + } + } } - - project.delete project.files(dirToDelete) - project.copy { - from tempDir.absolutePath - into dirToExclude + project.delete project.file(directoryToDelete) + File logDirectory = new File("$directoryToDelete${File.separator}${Constants.LOGS_FOLDER_NAME}") + if (!logDirectory.mkdirs()) { + throw new IOException("${Constants.IO_MESSAGE_TEMP_DIR}: ${tempDir.getAbsolutePath()}"); + } + if(directoriesToExclude && directoriesToExclude.size() > 0){ + directoriesToExclude.each { directory -> + if(new File("${tempDir.absolutePath}${File.separator}${Paths.get(directory).fileName.toString()}").exists()) { + project.copy { + from "${tempDir.absolutePath}${File.separator}${Paths.get(directory).fileName.toString()}" + into "$directoryToDelete${File.separator}${Paths.get(directory).fileName.toString()}" + } + } + } } } @@ -220,7 +235,8 @@ abstract class SalesforceTask extends ForceTask { */ public void deleteTemporaryFiles() { if (project.enforce.deleteTemporaryFiles) { - deleteDir(buildFolderPath, Paths.get(buildFolderPath, Constants.LOGS_FOLDER_NAME).toString()) + deleteDir(buildFolderPath, [Paths.get(buildFolderPath, Constants.LOGS_FOLDER_NAME).toString(), + Paths.get(buildFolderPath, Constants.REPORT_FOLDER_NAME).toString()]) } } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/unittest/RunTestTask.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/unittest/RunTestTask.groovy index 604a795..d8c2f60 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/unittest/RunTestTask.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/unittest/RunTestTask.groovy @@ -156,6 +156,7 @@ class RunTestTask extends SalesforceTask { } writeJenkinsPluginJson() generateUnitTestReportXml() + deleteTemporaryFiles() } /** diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy index 2054626..58b112b 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Constants.groovy @@ -30,6 +30,7 @@ public class Constants { public static final String TEMP_DIR_PATH = "java.io.tmpdir" public static final String TEMP_FOLDER_NAME = "temp_enforce" public static final String LOGS_FOLDER_NAME = "logs" + public static final String REPORT_FOLDER_NAME = "report" public static final int ZERO = 0 From 47a041bf2be3f79d8ef2fe6a4e9b44ce0d19813f Mon Sep 17 00:00:00 2001 From: Rodrigo Ruiz Date: Wed, 10 Jun 2015 09:56:58 -0400 Subject: [PATCH 46/50] Code observations were applied --- .../enforce/tasks/salesforce/SalesforceTask.groovy | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy index 1dd21a2..0460683 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy @@ -196,14 +196,14 @@ abstract class SalesforceTask extends ForceTask { * @param directoryToDelete * @param directoriesToExclude */ - public void deleteDir(String directoryToDelete, ArrayList directoriesToExclude){ + public void deleteDirectory(String directoryToDelete, ArrayList directoriesToExclude){ String tempDirPath = System.getProperty(Constants.TEMP_DIR_PATH) File tempDir = new File(Paths.get(tempDirPath, "${Constants.TEMP_FOLDER_NAME}${Long.toString(System.nanoTime())}").toString()) if (!tempDir.mkdir()) { throw new IOException("${Constants.IO_MESSAGE_TEMP_DIR}: ${tempDir.getAbsolutePath()}"); } - if(directoriesToExclude && directoriesToExclude.size() > 0){ + if(directoriesToExclude && directoriesToExclude.size() > Constants.ZERO){ directoriesToExclude.each { directory -> if(new File(directory).exists()) { project.copy { @@ -218,7 +218,7 @@ abstract class SalesforceTask extends ForceTask { if (!logDirectory.mkdirs()) { throw new IOException("${Constants.IO_MESSAGE_TEMP_DIR}: ${tempDir.getAbsolutePath()}"); } - if(directoriesToExclude && directoriesToExclude.size() > 0){ + if(directoriesToExclude && directoriesToExclude.size() > Constants.ZERO){ directoriesToExclude.each { directory -> if(new File("${tempDir.absolutePath}${File.separator}${Paths.get(directory).fileName.toString()}").exists()) { project.copy { @@ -235,7 +235,7 @@ abstract class SalesforceTask extends ForceTask { */ public void deleteTemporaryFiles() { if (project.enforce.deleteTemporaryFiles) { - deleteDir(buildFolderPath, [Paths.get(buildFolderPath, Constants.LOGS_FOLDER_NAME).toString(), + deleteDirectory(buildFolderPath, [Paths.get(buildFolderPath, Constants.LOGS_FOLDER_NAME).toString(), Paths.get(buildFolderPath, Constants.REPORT_FOLDER_NAME).toString()]) } } From ab602e58bb5063b693ab3103c35268faf685be8b Mon Sep 17 00:00:00 2001 From: Rodrigo Ruiz Date: Wed, 10 Jun 2015 09:59:55 -0400 Subject: [PATCH 47/50] added more comments --- .../plugins/enforce/tasks/salesforce/SalesforceTask.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy index 0460683..a9f2b27 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/SalesforceTask.groovy @@ -193,8 +193,8 @@ abstract class SalesforceTask extends ForceTask { /** * Deletes a directory excluding others directories - * @param directoryToDelete - * @param directoriesToExclude + * @param directoryToDelete the directory to delete + * @param directoriesToExclude the directories to exclude from directory will be deleted */ public void deleteDirectory(String directoryToDelete, ArrayList directoriesToExclude){ String tempDirPath = System.getProperty(Constants.TEMP_DIR_PATH) From f00b9250be55a4af5631807b056a8be15aec61ca Mon Sep 17 00:00:00 2001 From: marco_cadima Date: Wed, 10 Jun 2015 11:03:24 -0400 Subject: [PATCH 48/50] Bug is --- build.gradle | 14 ++++++-- .../utils/salesforce/PackageCombiner.groovy | 1 + .../salesforce/PackageCombinerTest.groovy | 33 +++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index a05bc8c..6aaf69c 100644 --- a/build.gradle +++ b/build.gradle @@ -74,15 +74,25 @@ def major = "$System.env.VERSION_NUMBER_MAJOR" def minor = "$System.env.VERSION_NUMBER_MINOR" def patch = "$System.env.VERSION_NUMBER_PATCH" def newVersion = "$major.$minor.$patch" -version = newVersion +version = '1.0.4.b7' uploadArchives { repositories { mavenDeployer { - repository url: "file://${System.properties['user.home']}/.m2/repository" + repository(url: "http://10.31.2.240:8081/artifactory/salesforce") { + authentication(userName: "mcadima", password: "mcadima") + } } } } +/* +uploadArchives { + repositories { + mavenDeployer { + repository url: "file://${System.properties['user.home']}/.m2/repository" + } + } +}*/ task sourcesJar(type: Jar, dependsOn: classes) { classifier = 'sources' diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombiner.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombiner.groovy index 6edacc6..13b90fc 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombiner.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombiner.groovy @@ -54,6 +54,7 @@ class PackageCombiner { String parentName = Util.getFirstPath(componentName) if (parentName != componentName) { componentToDelete.get(componentType).push(parentName) + componentToDelete.get(componentType).push(Util.getFileName(componentName)) } } diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombinerTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombinerTest.groovy index 2ee5436..42095c1 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombinerTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/PackageCombinerTest.groovy @@ -225,6 +225,39 @@ class PackageCombinerTest extends Specification { xmlDiff.similar() } + def "Test should remove documents that doesn't have extension at package xml file"() { + given: + String packagePath = Paths.get(SRC_PATH, 'packageTestDocument.xml') + String packageContent = ''' + + + MyDocuments + MyDocuments/doc2 + MyDocuments/doc1 + Document + + 32.0 + + ''' + File packageFile = new File(packagePath) + packageFile.write(packageContent) + String packageExpect = ''' + + + MyDocuments/doc1 + Document + + 32.0 + + ''' + when: + PackageCombiner.removeMembersFromPackage(packagePath, ['documents/MyDocuments/doc2.txt']) + XMLUnit.ignoreWhitespace = true + def xmlDiff = new Diff(packageFile.text, packageExpect) + then: + xmlDiff.similar() + } + def 'Test should remove reports component from package xml file'() { given: String packagePath = Paths.get(SRC_PATH, 'packageTestReport.xml') From 8377db7424e9470217ad30c45e8c5928ed0f0347 Mon Sep 17 00:00:00 2001 From: marco_cadima Date: Wed, 10 Jun 2015 11:10:52 -0400 Subject: [PATCH 49/50] Now documents components can be with their extension or without their extension into package xml from project directory --- build.gradle | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index 6aaf69c..97086a5 100644 --- a/build.gradle +++ b/build.gradle @@ -74,25 +74,15 @@ def major = "$System.env.VERSION_NUMBER_MAJOR" def minor = "$System.env.VERSION_NUMBER_MINOR" def patch = "$System.env.VERSION_NUMBER_PATCH" def newVersion = "$major.$minor.$patch" -version = '1.0.4.b7' +version = newVersion -uploadArchives { - repositories { - mavenDeployer { - repository(url: "http://10.31.2.240:8081/artifactory/salesforce") { - authentication(userName: "mcadima", password: "mcadima") - } - } - } -} -/* uploadArchives { repositories { mavenDeployer { repository url: "file://${System.properties['user.home']}/.m2/repository" } } -}*/ +} task sourcesJar(type: Jar, dependsOn: classes) { classifier = 'sources' @@ -134,4 +124,4 @@ bintray { labels = ['sfdc', 'integration ', 'continuous', 'jenkins', 'gradle'] publicDownloadNumbers = true } -} +} \ No newline at end of file From 18ec4a279bf362a5ebc9590b426d1d471771698d Mon Sep 17 00:00:00 2001 From: Marcelo Oporto Fernandez Date: Wed, 10 Jun 2015 17:32:17 -0400 Subject: [PATCH 50/50] Fixed files validations --- .../enforce/tasks/salesforce/deployment/Delete.groovy | 1 - .../enforce/tasks/salesforce/deployment/Deployment.groovy | 8 ++++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy index fabb30a..bed9be0 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Delete.groovy @@ -95,7 +95,6 @@ class Delete extends Deployment { }.each { group, files -> logger.quiet("[ " + files.size() + " ] " + group) } - logger.quiet(numComponentes+" components") } else { showFiles.each { File file -> diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy index e294382..2d84655 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/deployment/Deployment.groovy @@ -12,6 +12,8 @@ import org.fundacionjala.gradle.plugins.enforce.utils.Constants import org.fundacionjala.gradle.plugins.enforce.utils.Util import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.MetadataComponents import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.PackageCombiner +import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.SalesforceValidator +import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.SalesforceValidatorManager import org.gradle.api.file.FileTree import org.gradle.api.tasks.bundling.Zip @@ -325,8 +327,10 @@ abstract class Deployment extends SalesforceTask { ArrayList notExistFiles = new ArrayList() String errorMessage = '' filesName.each { String fileName -> - def extension = Util.getFileExtension(new File(Paths.get(projectPath, fileName).toString())) - if (!MetadataComponents.validExtension(extension)) { + File file = new File(Paths.get(projectPath, fileName).toString()) + String parentName = Util.getFirstPath(fileName).toString() + SalesforceValidator validator = SalesforceValidatorManager.getValidator(parentName) + if (!validator.validateFileByFolder(parentName, file)) { invalidFiles.push(fileName) } if (!new File(Paths.get(projectPath, fileName).toString()).exists()) {