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 0952cdb..e7045b7 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 @@ -8,15 +8,19 @@ package org.fundacionjala.gradle.plugins.enforce.interceptor import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.MetadataComponents +import groovy.util.logging.Slf4j /** * This class manages all components created from source path */ +@Slf4j class InterceptorManager { Map interceptors List truncatedDirectories = ['classes', 'objects', 'triggers', 'pages', 'components', 'workflows', 'tabs'] List interceptorsToExecute + + /** * Creates a new interceptor management from source path * @param sourcePath the source directory path @@ -102,7 +106,8 @@ class InterceptorManager { * Executes the truncate method of all the component interceptors */ public void executeTruncate() { - this.interceptors.values().each { interceptor -> + this.interceptors.each {String component, MetadataInterceptor interceptor -> + log.debug "----------------------" + component + "----------------------" interceptor.executeInterceptors() } } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/MetadataInterceptor.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/MetadataInterceptor.groovy index bd43f61..b56867b 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/MetadataInterceptor.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/MetadataInterceptor.groovy @@ -4,10 +4,11 @@ */ package org.fundacionjala.gradle.plugins.enforce.interceptor - +import groovy.util.logging.Slf4j /** * This class provides a skeletal implementation of the interceptor for all metadata types supported */ +@Slf4j abstract class MetadataInterceptor { List interceptorsToExecute List files @@ -59,6 +60,7 @@ abstract class MetadataInterceptor { if (interceptorsToExecute.contains(interceptorName) || (!interceptorsToExecute.contains(interceptorName) && interceptorName.isNumber() && interceptorName.toInteger() == interceptor.hashCode())) { + log.debug "$interceptorName --> $file.name" executeInterceptor(interceptor, file) } } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/commands/Component.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/commands/Component.groovy index cd6fbbb..fb78178 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/commands/Component.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/commands/Component.groovy @@ -11,12 +11,10 @@ import java.util.regex.Matcher * Implements the truncated algorithm to truncate the component content */ class Component { - public static final String EMPTY_COMPONENT = '' - private final String COMPONENT_REGEX = /(.*([^\n]*?\n+?)*?.*)<\/apex:component>/ - private final String ATTRIBUTE_REGEX = // - private final String ATTRIBUTE_BY_DEFAULT = "" + private final String ATTRIBUTE_REGEX = // + private final String ATTRIBUTE_BY_DEFAULT = "" private final String NAME_ATTRIBUTE = "name" - private final int INDEX_COMPONENT = 1 + private final String COMPONENT_BY_DEFAULT = "%s\n" private final int INDEX_ATTRIBUTE = 0 /** @@ -27,29 +25,22 @@ class Component { return } String component = file.text - Matcher componentMatcher = component =~ COMPONENT_REGEX - String content = "" - String newContent = "" + String newAttributes = "" String attribute = "" String attributeName = "" int indexName int indexIniName int indexEndName - componentMatcher.each { componentIt -> - content = componentIt[INDEX_COMPONENT] - if (content) { - Matcher attributeMatcher = component =~ ATTRIBUTE_REGEX - attributeMatcher.each { attributeIt -> - attribute = attributeIt[INDEX_ATTRIBUTE] - indexName = attribute.indexOf(NAME_ATTRIBUTE) - indexIniName = attribute.indexOf("\"", indexName) - indexEndName = attribute.indexOf("\"", indexIniName + 1) - attributeName = attribute.substring(indexIniName, indexEndName + 1) - newContent += "\n${String.format(ATTRIBUTE_BY_DEFAULT, attributeName)}" - } - component = component.replace(content, "${newContent}\n") - } + Matcher attributeMatcher = component =~ ATTRIBUTE_REGEX + attributeMatcher.each { attributeIt -> + attribute = attributeIt[INDEX_ATTRIBUTE] + indexName = attribute.indexOf(NAME_ATTRIBUTE) + indexIniName = attribute.indexOf("\"", indexName) + indexEndName = attribute.indexOf("\"", indexIniName + 1) + attributeName = attribute.substring(indexIniName, indexEndName + 1) + newAttributes += "\n${String.format(ATTRIBUTE_BY_DEFAULT, attributeName)}" } - file.text = component + + file.text = String.format(COMPONENT_BY_DEFAULT, newAttributes) } } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/ClassInterceptor.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/ClassInterceptor.groovy index 9f870ed..f8d59db 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/ClassInterceptor.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/ClassInterceptor.groovy @@ -11,10 +11,11 @@ import org.fundacionjala.gradle.plugins.enforce.interceptor.commands.Class import org.fundacionjala.gradle.plugins.enforce.interceptor.commands.ClassAnnotation import org.fundacionjala.gradle.plugins.enforce.utils.ManagementFile import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.MetadataComponents - +import groovy.util.logging.Slf4j /** * Implements methods to manage interceptors and load the classes to truncate */ +@Slf4j class ClassInterceptor extends MetadataInterceptor { private final String DEPRECATE_ANNOTATION = '@deprecated' diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/ComponentInterceptor.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/ComponentInterceptor.groovy index 14ce71f..ca76e9b 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/ComponentInterceptor.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/ComponentInterceptor.groovy @@ -10,10 +10,11 @@ import org.fundacionjala.gradle.plugins.enforce.interceptor.MetadataInterceptor import org.fundacionjala.gradle.plugins.enforce.interceptor.commands.Component import org.fundacionjala.gradle.plugins.enforce.utils.ManagementFile import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.MetadataComponents - +import groovy.util.logging.Slf4j /** * Implements methods to manage interceptors and load the components to truncate */ +@Slf4j class ComponentInterceptor extends MetadataInterceptor { /** diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/ObjectInterceptor.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/ObjectInterceptor.groovy index 5edf7aa..731bef7 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/ObjectInterceptor.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/ObjectInterceptor.groovy @@ -10,10 +10,11 @@ import org.fundacionjala.gradle.plugins.enforce.interceptor.MetadataInterceptor import org.fundacionjala.gradle.plugins.enforce.interceptor.commands.* import org.fundacionjala.gradle.plugins.enforce.utils.ManagementFile import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.MetadataComponents - +import groovy.util.logging.Slf4j /** * Implements methods to manage interceptors and load the objects to truncate */ +@Slf4j class ObjectInterceptor extends MetadataInterceptor { /** diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/PageInterceptor.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/PageInterceptor.groovy index a6fe519..42839d6 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/PageInterceptor.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/PageInterceptor.groovy @@ -10,10 +10,11 @@ import org.fundacionjala.gradle.plugins.enforce.interceptor.MetadataInterceptor import org.fundacionjala.gradle.plugins.enforce.interceptor.commands.Page import org.fundacionjala.gradle.plugins.enforce.utils.ManagementFile import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.MetadataComponents - +import groovy.util.logging.Slf4j /** * Implements methods to manage interceptors and load the pages to truncate */ +@Slf4j class PageInterceptor extends MetadataInterceptor { /** diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/TabInterceptor.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/TabInterceptor.groovy index 4d940ec..6deda9a 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/TabInterceptor.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/TabInterceptor.groovy @@ -10,10 +10,11 @@ import org.fundacionjala.gradle.plugins.enforce.interceptor.MetadataInterceptor import org.fundacionjala.gradle.plugins.enforce.interceptor.commands.Tab import org.fundacionjala.gradle.plugins.enforce.utils.ManagementFile import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.MetadataComponents - +import groovy.util.logging.Slf4j /** * Implements methods to manage interceptors and load the tabs to truncate */ +@Slf4j class TabInterceptor extends MetadataInterceptor { /** diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/TriggerInterceptor.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/TriggerInterceptor.groovy index 24f5d85..28c7367 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/TriggerInterceptor.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/TriggerInterceptor.groovy @@ -10,10 +10,11 @@ import org.fundacionjala.gradle.plugins.enforce.interceptor.MetadataInterceptor import org.fundacionjala.gradle.plugins.enforce.interceptor.commands.Trigger import org.fundacionjala.gradle.plugins.enforce.utils.ManagementFile import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.MetadataComponents - +import groovy.util.logging.Slf4j /** * Implements methods to manage interceptors and load the triggers to truncate */ +@Slf4j class TriggerInterceptor extends MetadataInterceptor { /** diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/WorkflowInterceptor.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/WorkflowInterceptor.groovy index 8f0d5af..e2068dd 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/WorkflowInterceptor.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/interceptors/WorkflowInterceptor.groovy @@ -10,10 +10,11 @@ import org.fundacionjala.gradle.plugins.enforce.interceptor.MetadataInterceptor import org.fundacionjala.gradle.plugins.enforce.interceptor.commands.Workflow import org.fundacionjala.gradle.plugins.enforce.utils.ManagementFile import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.MetadataComponents - +import groovy.util.logging.Slf4j /** * Implements methods to manage interceptors and load the workflows to truncate */ +@Slf4j class WorkflowInterceptor extends MetadataInterceptor { /** 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 6965701..2a3ec74 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 @@ -56,8 +56,8 @@ class Deploy extends Deployment { void runTask() { folderDeploy = Paths.get(buildFolderPath, FOLDER_DEPLOY).toString() packagePathDeploy = Paths.get(folderDeploy, PACKAGE_NAME).toString() + logger.debug('Creating folder Deploy at: ' + folderDeploy) createDeploymentDirectory(folderDeploy) - logger.debug('Created folder Deploy at: ' + folderDeploy) if (Util.isValidProperty(project, FOLDERS_DEPLOY)) { deployByFolder() } else { @@ -98,26 +98,24 @@ class Deploy extends Deployment { def deployTruncateFiles() { checkStatusTruncate() displayFolderNoDeploy() - logger.debug('Displayed message') if (codeTruncateOn) { ArrayList filesToTruncate = excludeFiles(fileManager.getFilesByFolders(projectPath, FOLDERS_TO_TRUNCATE)) Files.copy(Paths.get(projectPath, PACKAGE_NAME), Paths.get(packagePathDeploy), StandardCopyOption.REPLACE_EXISTING) + logger.debug('Copying files to deploy') fileManager.copy(filesToTruncate, folderDeploy) - logger.debug('All files copied to deploy...') + logger.debug('Generating package') writePackage(packagePathDeploy, filesToTruncate) - logger.debug('Created package...') truncateComponents() componentDeploy.startMessage = DEPLOYING_TRUNCATED_CODE componentDeploy.successMessage = DEPLOYING_TRUNCATED_CODE_SUCCESSFULLY + logger.debug("Deploying to truncate components from: $folderDeploy") executeDeploy(folderDeploy) createDeploymentDirectory(folderDeploy) - logger.debug('Truncated components...') } fileManager.copy(excludeFiles(fileManager.getValidElements(projectPath)), folderDeploy) componentDeploy.startMessage = DEPLOYING_CODE componentDeploy.successMessage = DEPLOYING_CODE_SUCCESSFULLY deployToSalesForce() - logger.debug('Deployed components...') } /** @@ -145,8 +143,10 @@ class Deploy extends Deployment { if (deprecateTruncateOn) { interceptorsToExecute = [Interceptor.REMOVE_DEPRECATE.id] interceptorsToExecute += interceptors + logger.debug("Truncating components from: $folderDeploy") truncateComponents(folderDeploy) } + logger.debug("Deploying all components from: $folderDeploy") executeDeploy(folderDeploy) updateFileTracker() } @@ -177,7 +177,9 @@ class Deploy extends Deployment { */ def updateFileTracker() { ComponentMonitor componentMonitor = new ComponentMonitor(projectPath) + logger.debug('Getting components signatures') Map initMapSave = componentMonitor.getComponentsSignature(fileManager.getValidElements(projectPath, excludeFilesToMonitor)) + logger.debug('Saving initial file tracker') componentMonitor.componentSerializer.save(initMapSave) } @@ -191,6 +193,7 @@ class Deploy extends Deployment { Interceptor.TRUNCATE_PAGES.id, Interceptor.TRUNCATE_TRIGGERS.id, Interceptor.TRUNCATE_WORKFLOWS.id, Interceptor.TRUNCATE_COMPONENTS.id] interceptorsToExecute += interceptors + logger.debug("Truncating components at: $srcPath") truncateComponents(srcPath) } } 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 781791c..5286e02 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 @@ -54,8 +54,10 @@ abstract class Deployment extends SalesforceTask { */ def executeDeploy(String sourcePath) { String fileName = new File(sourcePath).getName() + logger.debug("Crating zip file at: $buildFolderPath/$fileName") String pathZipToDeploy = createZip(sourcePath, buildFolderPath, fileName) componentDeploy.setPath(pathZipToDeploy) + logger.debug('Deploying components') componentDeploy.deploy(poll, waitTime, credential) } @@ -64,10 +66,14 @@ abstract class Deployment extends SalesforceTask { * @param dirToTruncate the directory path to truncate */ def truncateComponents(String dirToTruncate) { + logger.debug('Loading files to truncate') componentManager.loadFiles(dirToTruncate) + logger.debug('Adding interceptors') componentManager.addInterceptors(interceptorsToExecute) componentManager.addInterceptorsRegistered(project.property(Constants.FORCE_EXTENSION).interceptors as Map) + logger.debug('Validating interceptors') componentManager.validateInterceptors() + logger.debug('Executing truncate process') componentManager.executeTruncate() } diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/commands/ComponentTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/commands/ComponentTest.groovy index 62f5dd7..7d1858c 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/commands/ComponentTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/commands/ComponentTest.groovy @@ -41,20 +41,20 @@ class ComponentTest extends Specification { when: componentContent.execute(file) then: - file.text == expectedContent + file.text.replaceAll("\\s*","") == expectedContent.replaceAll("\\s*","") } def "Should truncate a component with attributes"() { given: - def expectedContent = ''' - - - - + def expectedContent = ''' + + + ''' File file = new File("${TRUNCATED_PATH}/NewComponentContent.component") when: componentContent.execute(file) then: + true file.text.replaceAll("\\s*","") == expectedContent.replaceAll("\\s*","") } def cleanupSpec() { diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/resources/components/ComponentContent.component b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/resources/components/ComponentContent.component index ba21dc2..ba208d9 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/resources/components/ComponentContent.component +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/interceptor/resources/components/ComponentContent.component @@ -1,6 +1,4 @@

Congratulations

-This is your new Component -
\ No newline at end of file