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 a817cce..effaa8d 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/EnforcePluginExtension.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/EnforcePluginExtension.groovy @@ -35,7 +35,7 @@ class EnforcePluginExtension { */ ArrayList deleteSubComponents = ['*'] - ArrayList standardObjects = [] + ArrayList standardComponents = [] String tool = "" 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 eeb9039..ac1536b 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 @@ -111,17 +111,6 @@ abstract class Deployment extends SalesforceTask { fileManager.createNewDirectory(pathDirectory) } - /** - * Combines package that was updated from build folder and package from source directory - * @param buildPackagePath is path of package that is into build directory - */ - public void combinePackage(String buildPackagePath) { - PackageCombiner.packageCombine(projectPackagePath, buildPackagePath) - if (excludes) { - removeFilesExcluded(buildPackagePath) - } - } - /** * Combines package from build folder and package from source directory * @param buildPackagePath is path of package that is into build directory 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 bfd732b..ab73aab 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 @@ -53,7 +53,7 @@ class Undeploy extends Deployment { @Override void runTask() { truncate() - addNewStandardObjects() + addNewStandardComponents() unDeploy() } @@ -67,7 +67,7 @@ class Undeploy extends Deployment { copyFilesToTaskDirectory(filesToTruncate) addInterceptor() writePackage(taskPackagePath, filesToTruncate) - combinePackage(taskPackagePath) + combinePackageToUpdate(taskPackagePath) executeDeploy(taskFolderPath, START_MESSAGE_TRUNCATE, SUCCESS_MESSAGE_TRUNCATE) } @@ -93,7 +93,7 @@ class Undeploy extends Deployment { public void unDeploy() { createDeploymentDirectory(taskFolderPath) deployToDeleteComponents() - combinePackage(taskDestructivePath) + combinePackageToUpdate(taskDestructivePath) executeDeploy(taskFolderPath, START_MESSAGE_UNDEPLOY, SUCCESS_MESSAGE_DELETE) } @@ -159,10 +159,10 @@ class Undeploy extends Deployment { /** * Adds new standard objects from user property */ - public void addNewStandardObjects() { + public void addNewStandardComponents() { if (Util.isValidProperty(project, Constants.FORCE_EXTENSION) && - project[Constants.FORCE_EXTENSION].standardObjects) { - standardComponents += project[Constants.FORCE_EXTENSION].standardObjects + project[Constants.FORCE_EXTENSION].standardComponents) { + standardComponents += project[Constants.FORCE_EXTENSION].standardComponents } } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/OrgValidator.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/OrgValidator.groovy index 9d9e50a..88836a8 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/OrgValidator.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/OrgValidator.groovy @@ -2,8 +2,8 @@ package org.fundacionjala.gradle.plugins.enforce.utils.salesforce 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.validators.files.BasicOrgComponentsValidator -import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.files.DefaultOrgComponentsValidator +import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.org.BasicOrgComponentsValidator +import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.org.DefaultOrgComponentsValidator import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.files.SalesforceValidator import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.org.BasicOrgSubcomponentsValidator import org.fundacionjala.gradle.plugins.enforce.wsc.Credential @@ -38,7 +38,7 @@ class OrgValidator { * @param filesToValidate ia a list of files that need to validate * @param projectPath our repository */ - public static Map> validateFiles(Credential credential,ArrayList filesToValidate, String projectPath) { + public static Map> validateFiles(Credential credential, ArrayList filesToValidate, String projectPath) { Map> mapFiles = filesToValidate.groupBy { Util.getFirstPath(Util.getRelativePath(it,projectPath)) } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/org/BasicOrgComponentsValidator.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/org/BasicOrgComponentsValidator.groovy index 1cd668f..d871add 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/org/BasicOrgComponentsValidator.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/org/BasicOrgComponentsValidator.groovy @@ -1,4 +1,4 @@ -package org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.files +package org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.org import groovy.json.JsonSlurper import org.fundacionjala.gradle.plugins.enforce.utils.Constants @@ -24,12 +24,10 @@ public class BasicOrgComponentsValidator implements OrgInterfaceValidator{ */ @Override public Map> validateFiles(Credential credential, ArrayList filesToVerify, String folderComponent, String projectPath) { - Map> mapFiles = [:] mapFiles.put(Constants.VALID_FILE, new ArrayList()) mapFiles.put(Constants.FILES_NOT_FOUND, new ArrayList()) mapFiles.put(Constants.FILE_WITHOUT_VALIDATOR, new ArrayList()) - ArrayList orgFiles = getFilesIntoOrg(credential, folderComponent, projectPath) filesToVerify.findAll{ File file -> @@ -52,22 +50,25 @@ public class BasicOrgComponentsValidator implements OrgInterfaceValidator{ * @param path orn repository */ public ArrayList getFilesIntoOrg(Credential credential, String folderComponent, String projectPath) { - ToolingAPI toolingAPI = new ToolingAPI(credential) QueryBuilder queryBuilder = new QueryBuilder() JsonSlurper jsonSlurper = new JsonSlurper() + MetadataComponents component = MetadataComponents.getComponent(folderComponent) ArrayList orgFiles = [] - def typeComponent = MetadataComponents.getComponent(folderComponent).getTypeName() - def extensionComponent = MetadataComponents.getComponent(folderComponent).getExtension() - def sqlString = queryBuilder.createQueryFromBasicComponent(typeComponent) - def resultSet = toolingAPI.httpAPIClient.executeQuery(sqlString) - def jsonResulSet = jsonSlurper.parseText(resultSet as String) + if(component != null) { + String typeComponent = component.getTypeName() + String extensionComponent = component.getExtension() + String sqlString = queryBuilder.createQueryFromBasicComponent(typeComponent) + String resultSet = toolingAPI.httpAPIClient.executeQuery(sqlString) + def jsonResulSet = jsonSlurper.parseText(resultSet as String) - for(def i = 0; i < jsonResulSet.records.size(); i++) { - def nameFile = "${jsonResulSet.records[i]['Name']}.${extensionComponent}" - orgFiles.add(new File(Paths.get(projectPath,folderComponent, nameFile ).toString())) + for(def i = 0; i < jsonResulSet.records.size(); i++) { + def nameFile = "${jsonResulSet.records[i]['Name']}.${extensionComponent}" + orgFiles.add(new File(Paths.get(projectPath,folderComponent, nameFile ).toString())) + } } + return orgFiles } } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/org/BasicOrgSubcomponentsValidator.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/org/BasicOrgSubcomponentsValidator.groovy index 21e5e5a..53c835b 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/org/BasicOrgSubcomponentsValidator.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/org/BasicOrgSubcomponentsValidator.groovy @@ -67,24 +67,29 @@ public class BasicOrgSubcomponentsValidator implements OrgInterfaceValidator{ /** * Validates the subcomponents defined in Salesforce organization * @param credential contains the data needed to connect with the API sales force - * @param filesToValidate is a list of files that need to validate - * @param typeSubcomponent is a subcomponent type that we need validate + * @param fileToValidate is a list of files that need to validate + * @param subcomponentType is a subcomponent type that we need validate * @return a boolean value that indicate if a subComponent exist in Salesforce organization */ - public boolean existFileInOrg(Credential credential, File filesToValidate, String typeSubcomponent) { + public boolean existFileInOrg(Credential credential, File fileToValidate, String subcomponentType) { ToolingAPI toolingAPI = new ToolingAPI(credential) - def typeComponent = MetadataComponents.getComponent(typeSubcomponent).getTypeName() - def extensionComponent = MetadataComponents.getComponent(typeSubcomponent).getExtension() + def existSubcomponent = false + def component = MetadataComponents.getComponent(subcomponentType) + + if(component != null) { + def typeComponent = component.getTypeName() + def extensionComponent = component.getExtension() - def sqlString = queryBuilder.createQueryGetSubomponent(typeComponent, filesToValidate) - def resultSet = toolingAPI.httpAPIClient.executeQuery(sqlString) - def jsonResulSet = jsonSlurper.parseText(resultSet as String) - for(def i = 0; i < jsonResulSet.records.size(); i++) { - String fullName = "${jsonResulSet.records[i]['FullName']}.${extensionComponent}" - if(fullName.equals(filesToValidate.getName())) { - return true + def sqlString = queryBuilder.createQueryGetSubomponent(typeComponent, fileToValidate) + def resultSet = toolingAPI.httpAPIClient.executeQuery(sqlString) + def jsonResulSet = jsonSlurper.parseText(resultSet as String) + for(def i = 0; i < jsonResulSet.records.size(); i++) { + String fullName = "${jsonResulSet.records[i]['FullName']}.${extensionComponent}" + if(fullName.equals(fileToValidate.getName())) { + existSubcomponent = true + } } } - return false + return existSubcomponent } } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/org/DefaultOrgComponentsValidator.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/org/DefaultOrgComponentsValidator.groovy index 5f14651..1cebfd0 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/org/DefaultOrgComponentsValidator.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/component/validators/org/DefaultOrgComponentsValidator.groovy @@ -1,18 +1,17 @@ -package org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.files +package org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.org import org.fundacionjala.gradle.plugins.enforce.utils.Constants -import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.org.OrgInterfaceValidator import org.fundacionjala.gradle.plugins.enforce.wsc.Credential /** * This class defines a default validate for some salesforce component */ -public class DefaultOrgComponentsValidator implements OrgInterfaceValidator{ +public class DefaultOrgComponentsValidator implements OrgInterfaceValidator { @Override - public Map> validateFiles(Credential credential, ArrayList filesToVerify, String folderComponent, String projectPath) { + public Map> validateFiles(Credential credential, ArrayList filesToVerify, String folderComponent, String projectPath) { - Map> mapFiles = [:] + Map> mapFiles = [:] mapFiles.put(Constants.VALID_FILE, new ArrayList()) mapFiles.put(Constants.FILES_NOT_FOUND, new ArrayList()) mapFiles.put(Constants.FILE_WITHOUT_VALIDATOR, new ArrayList()) 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 90bc8b2..3496f65 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 @@ -54,7 +54,7 @@ class UndeployTest extends Specification { project.apply(plugin: EnforcePlugin) project.enforce { srcPath = "${File.separator}home${File.separator}user${File.separator}project${File.separator}one" - standardObjects = ["Q2w_Test__c.object"] + standardComponents = ["Q2w_Test__c.object"] tool = "metadata" poll = 200 waitTime = 10 @@ -113,7 +113,7 @@ class UndeployTest extends Specification { def "Test should get the standard objects assigned"() { expect: - project.extensions.findByName('enforce').standardObjects == ["Q2w_Test__c.object"] + project.extensions.findByName('enforce').standardComponents == ["Q2w_Test__c.object"] } def "Test should get the tool assigned"() { @@ -160,8 +160,8 @@ class UndeployTest extends Specification { undeployInstance.copyFilesToTaskDirectory(undeployInstance.filesToTruncate) undeployInstance.addInterceptor() undeployInstance.writePackage(undeployInstance.taskPackagePath, undeployInstance.filesToTruncate) - undeployInstance.combinePackage(undeployInstance.taskPackagePath) - undeployInstance.addNewStandardObjects() + undeployInstance.combinePackageToUpdate(undeployInstance.taskPackagePath) + undeployInstance.addNewStandardComponents() undeployInstance.createDeploymentDirectory(undeployInstance.taskFolderPath) undeployInstance.deployToDeleteComponents() def destructiveXmlContent = new File(Paths.get(SRC_PATH, 'build', 'undeploy', 'destructiveChanges.xml').toString()).text diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/unittest/RunTestTaskTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/unittest/RunTestTaskTest.groovy index 499c3ef..478441c 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/unittest/RunTestTaskTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/tasks/salesforce/unittest/RunTestTaskTest.groovy @@ -26,7 +26,7 @@ class RunTestTaskTest extends Specification { project.apply(plugin: EnforcePlugin) project.enforce { srcPath = "${File.separator}home${File.separator}user${File.separator}project${File.separator}one" - standardObjects = ["Q2w_Test__c.object"] + standardComponents = ["Q2w_Test__c.object"] tool = "metadata" poll = 200 waitTime = 10 @@ -50,7 +50,7 @@ class RunTestTaskTest extends Specification { def "Should get the standard objects assigned"() { expect: - project.extensions.findByName('enforce').standardObjects == ["Q2w_Test__c.object"] + project.extensions.findByName('enforce').standardComponents == ["Q2w_Test__c.object"] } def "Should get the tool assigned"() { @@ -62,7 +62,7 @@ class RunTestTaskTest extends Specification { given: project.enforce { srcPath = SRC_PATH - standardObjects = ["Q2w_Test__c.object"] + standardComponents = ["Q2w_Test__c.object"] tool = "metadata" poll = 200 waitTime = 10 @@ -82,7 +82,7 @@ class RunTestTaskTest extends Specification { given: project.enforce { srcPath = SRC_PATH - standardObjects = ["Q2w_Test__c.object"] + standardComponents = ["Q2w_Test__c.object"] tool = "metadata" poll = 200 waitTime = 10 diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/OrgValidatorTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/OrgValidatorTest.groovy index 321b65e..8df3c12 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/OrgValidatorTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/utils/salesforce/OrgValidatorTest.groovy @@ -26,6 +26,9 @@ class OrgValidatorTest extends Specification { ArrayList validTriggerFiles ArrayList invalidTriggerFiles ArrayList unvalidatedDocumentFiles + ArrayList invalidNonexistentFiles + ArrayList validPagesFiles + ArrayList invalidPagesFiles @Shared Map> mapExpected @@ -46,7 +49,10 @@ class OrgValidatorTest extends Specification { invalidClassFiles = [] validTriggerFiles = [] invalidTriggerFiles = [] + validPagesFiles = [] + invalidPagesFiles = [] unvalidatedDocumentFiles = [] + invalidNonexistentFiles = [] mapExpected = [:] @@ -72,9 +78,21 @@ class OrgValidatorTest extends Specification { invalidTriggerFiles.add(new File(Paths.get(SRC_PATH,'triggers','triggerFall2.trigger').toString())) invalidTriggerFiles.add(new File(Paths.get(SRC_PATH,'triggers','triggerFall3.trigger').toString())) + validPagesFiles.add(new File(Paths.get(SRC_PATH,'pages','Page1.page').toString())) + validPagesFiles.add(new File(Paths.get(SRC_PATH,'pages','Page2.page').toString())) + validPagesFiles.add(new File(Paths.get(SRC_PATH,'pages','Page3.page').toString())) + + invalidPagesFiles.add(new File(Paths.get(SRC_PATH,'pages','PageFall1.page').toString())) + invalidPagesFiles.add(new File(Paths.get(SRC_PATH,'pages','PageFall2.page').toString())) + invalidPagesFiles.add(new File(Paths.get(SRC_PATH,'pages','PageFall3.page').toString())) + unvalidatedDocumentFiles.add(new File(Paths.get(SRC_PATH,'documents','myDocuments','doc.txt').toString())) unvalidatedDocumentFiles.add(new File(Paths.get(SRC_PATH,'documents','myDocuments','doc2.txt').toString())) + invalidNonexistentFiles.add(new File(Paths.get(SRC_PATH,'othercomponent','doc1.txt').toString())) + invalidNonexistentFiles.add(new File(Paths.get(SRC_PATH,'othercomponent','doc2.txt').toString())) + invalidNonexistentFiles.add(new File(Paths.get(SRC_PATH,'othercomponent','doc3.txt').toString())) + mapExpected.put(Constants.VALID_FILE, new ArrayList()) mapExpected.put(Constants.FILES_NOT_FOUND, new ArrayList()) mapExpected.put(Constants.FILE_WITHOUT_VALIDATOR, new ArrayList()) @@ -166,4 +184,51 @@ class OrgValidatorTest extends Specification { mapResponse[Constants.FILES_NOT_FOUND].sort() == mapExpected[Constants.FILES_NOT_FOUND].sort() mapResponse[Constants.FILE_WITHOUT_VALIDATOR].sort() == mapExpected[Constants.FILE_WITHOUT_VALIDATOR].sort() } + + def "Test should returns a map that contains all valid, invalid and noneexistent files" () { + given: + mapExpected[Constants.VALID_FILE].addAll(validClassFiles) + mapExpected[Constants.VALID_FILE].addAll(validTriggerFiles) + mapExpected[Constants.FILE_WITHOUT_VALIDATOR].addAll(invalidNonexistentFiles) + + + allFiles.addAll(validClassFiles) + allFiles.addAll(validTriggerFiles) + allFiles.addAll(invalidNonexistentFiles) + + when: + Map> mapResponse = OrgValidator.validateFiles(credential, allFiles, SRC_PATH) + showMaps(true,mapExpected,mapResponse) + + then: + mapResponse[Constants.VALID_FILE].sort() == mapExpected[Constants.VALID_FILE].sort() + mapResponse[Constants.FILES_NOT_FOUND].sort() == mapExpected[Constants.FILES_NOT_FOUND].sort() + mapResponse[Constants.FILE_WITHOUT_VALIDATOR].sort() == mapExpected[Constants.FILE_WITHOUT_VALIDATOR].sort() + } + + def "Test should returns a map that contains all valid xistent files" () { + given: + mapExpected[Constants.VALID_FILE].addAll(validClassFiles) + mapExpected[Constants.VALID_FILE].addAll(validTriggerFiles) + mapExpected[Constants.VALID_FILE].addAll(validPagesFiles) + mapExpected[Constants.FILES_NOT_FOUND].addAll(invalidClassFiles) + mapExpected[Constants.FILES_NOT_FOUND].addAll(invalidTriggerFiles) + mapExpected[Constants.FILES_NOT_FOUND].addAll(invalidPagesFiles) + + allFiles.addAll(validClassFiles) + allFiles.addAll(validTriggerFiles) + allFiles.addAll(validPagesFiles) + allFiles.addAll(invalidClassFiles) + allFiles.addAll(invalidTriggerFiles) + allFiles.addAll(invalidPagesFiles) + + when: + Map> mapResponse = OrgValidator.validateFiles(credential, allFiles, SRC_PATH) + showMaps(true,mapExpected,mapResponse) + + then: + mapResponse[Constants.VALID_FILE].sort() == mapExpected[Constants.VALID_FILE].sort() + mapResponse[Constants.FILES_NOT_FOUND].sort() == mapExpected[Constants.FILES_NOT_FOUND].sort() + mapResponse[Constants.FILE_WITHOUT_VALIDATOR].sort() == mapExpected[Constants.FILE_WITHOUT_VALIDATOR].sort() + } } \ No newline at end of file