Skip to content

Commit

Permalink
Merge pull request #116 from fundacionjala/develop
Browse files Browse the repository at this point in the history
New release v1.0.4
  • Loading branch information
Rodrigo Ruiz committed Jun 10, 2015
2 parents 98d4648 + f11ccb3 commit e18a4dc
Show file tree
Hide file tree
Showing 43 changed files with 1,657 additions and 304 deletions.
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -125,4 +124,4 @@ bintray {
labels = ['sfdc', 'integration ', 'continuous', 'jenkins', 'gradle']
publicDownloadNumbers = true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -49,6 +50,7 @@ class EnforcePlugin implements Plugin<Project> {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class EnforcePluginExtension {

Map<String, Map<String, Closure>> interceptors

EnforcePluginExtension(){
EnforcePluginExtension() {
interceptors = [:]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ 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.bundling.Zip

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"
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
Expand All @@ -39,6 +42,8 @@ abstract class SalesforceTask extends ForceTask {
public int poll
public int waitTime
public ArrayList<String> arrayPaths
public String projectPackagePath
public Map parameters

/**
* Sets description and group task
Expand All @@ -55,6 +60,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()
}

/**
Expand Down Expand Up @@ -101,7 +107,7 @@ abstract class SalesforceTask extends ForceTask {
*/
void writePackage(String packagePath, ArrayList<File> 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)
Expand All @@ -118,13 +124,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)
Expand All @@ -134,13 +140,105 @@ abstract class SalesforceTask extends ForceTask {
/**
* Updates the package prepared
*/
void updatePackage(String nameOfType,ArrayList<String> members, String pathPackage) {
void updatePackage(String nameOfType, ArrayList<String> members, String pathPackage) {
if (packageBuilder == null && !this.packageLoaded) {
throw new DeployException(UPDATE_PACKAGE_ERROR, [])
}
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 others directories
* @param directoryToDelete the directory to delete
* @param directoriesToExclude the directories to exclude from directory will be deleted
*/
public void deleteDirectory(String directoryToDelete, ArrayList<String> 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() > Constants.ZERO){
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.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() > Constants.ZERO){
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()}"
}
}
}
}
}

/**
* Deletes all temporary files excluding the log files
*/
public void deleteTemporaryFiles() {
if (project.enforce.deleteTemporaryFiles) {
deleteDirectory(buildFolderPath, [Paths.get(buildFolderPath, Constants.LOGS_FOLDER_NAME).toString(),
Paths.get(buildFolderPath, Constants.REPORT_FOLDER_NAME).toString()])
}
}

/**
* Load credential, gets version api and execute the method run
Expand All @@ -153,6 +251,8 @@ 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)
parameters = project.properties.clone()
runTask()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* 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.utils.Constants
import org.fundacionjala.gradle.plugins.enforce.utils.Util

import java.nio.file.Paths

/**
* Deletes files into an org using metadata API
*/
class Delete extends Deployment {
public String pathDelete
public ArrayList<File> filesToDeleted

/**
* Sets description and group task
* @param description is description tasks
* @param group is the group typeName the task
*/
Delete() {
super(Constants.DESCRIPTION_DELETE_TASK, Constants.DEPLOYMENT)
filesToDeleted = new ArrayList<File>()
}

/**
* Executes the task
*/
@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()
addFilesToDelete()
excludeFilesToDelete()
showFilesToDelete()

if( System.console().readLine("\n"+Constants.QUESTION_CONTINUE_DELETE) == Constants.YES_OPTION ) {
createDestructive()
createPackageEmpty()
executeDeploy(pathDelete)
}
else {
logger.quiet(Constants.PROCCES_DELETE_CANCELLED)
}
}

/**
* Adds all files into an org
*/
def addAllFiles() {
filesToDeleted = addAllFilesInAFolder(filesToDeleted)
}

/**
* Adds all files that are inside the folders
*/
def addFoldersToDeleteFiles() {
filesToDeleted = addFilesFromFolders(filesToDeleted)
}

/**
* Adds files to file's list
*/
def addFilesToDelete() {
filesToDeleted = addFilesTo(filesToDeleted)
}

/**
* Shows files to delete
*/
def showFilesToDelete() {
def limit = 15
ArrayList<File> showFiles = filesToDeleted.findAll { File file ->
!file.getName().endsWith("xml")
}
def numComponentes = showFiles.size()

logger.quiet("*********************************************")
logger.quiet(" Components to delete ")
logger.quiet("*********************************************")
if(numComponentes == 0) {
logger.quiet(Constants.NOT_FILES_DELETED)
}
else if(numComponentes > limit) {
showFiles.groupBy { File file ->
file.getParentFile().getName()
}.each { group, files ->
logger.quiet("[ " + files.size() + " ] " + group)
}
}
else {
showFiles.each { File file ->
logger.quiet( Util.getRelativePath(file, projectPath))
}
logger.quiet(numComponentes+" components")
}
logger.quiet("*********************************************")
}

/**
* Excludes Files from filesExcludes map
*/
def excludeFilesToDelete() {
filesToDeleted = excludeFiles(filesToDeleted)
}

/**
* Creates packages to all files which has been deleted
*/
def createDestructive() {
String destructivePath = Paths.get(pathDelete, PACKAGE_NAME_DESTRUCTIVE).toString()
writePackage(destructivePath, filesToDeleted)
combinePackageToUpdate(destructivePath)
}

/**
* Create a package empty
*/
def createPackageEmpty() {
writePackage(Paths.get(pathDelete, PACKAGE_NAME).toString(), [])
}
}
Loading

0 comments on commit e18a4dc

Please sign in to comment.