Skip to content

Commit

Permalink
Merge pull request #61 from marcocdlv/develop
Browse files Browse the repository at this point in the history
Undeploy task bug was fixed
  • Loading branch information
Rodrigo Ruiz committed May 16, 2015
2 parents 44d8df3 + 48036e1 commit 078d357
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,24 @@ class Util {
fileName.replaceFirst(PATTERN_FILE_EXT, '')
}

/**
* Gets a developer name of full name
* @param fullName is a tag of custom field
* @return developerName of custom field
*/
public static String getDeveloperName(String fullName){
return fullName.substring(fullName.indexOf('.') + 1, fullName.length() - 7)
}

/**
* Gets a developerName of member
* @param member is member tag of package xml file
* @return developerName of custom field
*/
public static String getDeveloperNameByMember(String member) {
return member.substring(member.indexOf('.') + 1, member.length() - 3)
}

/**
* Verifies if the property exist and if it is not empty string
* @param name the property typeName
Expand Down Expand Up @@ -164,7 +178,7 @@ class Util {
public static ArrayList<String> getInvalidFolders(ArrayList<String> foldersName) {
ArrayList<String> invalidFolders = new ArrayList<String>()
foldersName.each { String folderName ->
if (!MetadataComponents.validFolder(folderName)) {
if (!MetadataComponents.validFolder(folderName) || folderName.contains('.')) {
invalidFolders.push(folderName)
}
}
Expand All @@ -180,8 +194,10 @@ class Util {
ArrayList<String> emptyFolders = new ArrayList<String>()
foldersName.each { String folderName ->
File file = new File(Paths.get(projectPath, folderName).toString())
if (file.exists() && file.list().length == 0) {
emptyFolders.push(folderName)
if (file.isDirectory()) {
if (file.exists() && file.list().length == 0 ) {
emptyFolders.push(folderName)
}
}
}
return emptyFolders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ public enum MetadataComponents {
return COMPONENT.get(name.toUpperCase());
}

/**
* Gets a MetadataComponent by folder
* @param folder is a component folder
* @return a MetadataComponent
*/
public static MetadataComponents getComponentByFolder(String folder) {

MetadataComponents metadataComponent
Expand All @@ -124,6 +129,28 @@ public enum MetadataComponents {
return metadataComponent
}

/**
* Gets a MetadataComponent by name
* @param name is component name
* @return a MetadataComponent object
*/
public static MetadataComponents getComponentByName(String name) {

MetadataComponents metadataComponent
for (MetadataComponents component : values()) {
if (component.getTypeName() == name) {
metadataComponent = component
break
}
}
return metadataComponent
}

/**
* Gets a extension of component by folder
* @param folder is a component folder
* @return a extension of component
*/
public static String getExtensionByFolder(String folder) {

String extensionByFolder
Expand All @@ -136,6 +163,11 @@ public enum MetadataComponents {
return extensionByFolder
}

/**
* Gets a extension of component by name
* @param name is component name
* @return a extension o component
*/
public static String getExtensionByName(String name) {

String extensionByName
Expand All @@ -148,6 +180,11 @@ public enum MetadataComponents {
return extensionByName
}

/**
* Gets a directory of component by name
* @param name is a component name
* @return a directory of component
*/
public static String getDirectoryByName(String name) {

String directory
Expand All @@ -160,6 +197,11 @@ public enum MetadataComponents {
return directory
}

/**
* Validates a component extension
* @param extension is a component extension
* @return true if extension is valid
*/
public static boolean validExtension(String extension) {
for (MetadataComponents input : values()) {
if (input.getExtension() == extension) {
Expand All @@ -169,6 +211,11 @@ public enum MetadataComponents {
return false
}

/**
* Validates a component folder
* @param folderName is a component folder
* @return true if folder is valid
*/
public static boolean validFolder(String folderName) {
for (MetadataComponents input : values()) {
if (input.name() == folderName.toUpperCase()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class HttpAPIClient {
* @return the result from server in JSON format
*/
public String executeQuery(String soql) {

String resultQuery = ""
HTTPBuilder http = new HTTPBuilder(getEndPoint(host))
http.request( GET, JSON ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.fundacionjala.gradle.plugins.enforce.wsc.rest

import com.sforce.soap.metadata.PackageTypeMembers
import groovy.util.logging.Log
import org.fundacionjala.gradle.plugins.enforce.utils.Constants
import org.fundacionjala.gradle.plugins.enforce.utils.Util
Expand All @@ -25,6 +26,7 @@ class QueryBuilder {
public static final ArrayList<String> defaultComponents = ['ApexClass', 'ApexComponent', 'ApexPage', 'ApexTrigger', 'StaticResource',
'Profile', 'EmailTemplate', 'CustomField', 'CompactLayout', 'RecordType','ValidationRule']

public static final ArrayList<String> defaultSubComponents = ['CustomField', 'CompactLayout', 'RecordType','ValidationRule']
/**
* Gets queries of components from package xml file
* @param packagePath is type String
Expand All @@ -35,9 +37,18 @@ class QueryBuilder {
throw new Exception("${THERE_IS_NOT_PACKAGE}${packagePath}")
}
ArrayList<String> queries = new ArrayList<String>()
getComponents(new FileReader(packagePath)).each { component ->
if (isDefaultComponent(component)) {
queries.add("${'SELECT Name FROM'} ${component}")
getComponents(new FileReader(packagePath)).each { typeMembers ->
if(defaultSubComponents.contains(typeMembers.name)) {
typeMembers.members.each { member ->
if (member != '*') {
queries.add("""${SELECT_FULL_NAME} ${typeMembers.name} ${WHERE_FULL_NAME} '${
Util.getDeveloperNameByMember(member)
}'""")
}
}
} else
if (isDefaultComponent(typeMembers.name)) {
queries.add("${SELECT_NAME} ${typeMembers.name}")
}
}
return queries
Expand Down Expand Up @@ -90,14 +101,10 @@ class QueryBuilder {
* @param reader is type Reader
* @return arrayList with sales force's components
*/
public ArrayList<String> getComponents(Reader reader) {
public ArrayList<PackageTypeMembers> getComponents(Reader reader) {
PackageBuilder packageBuilder = new PackageBuilder()
packageBuilder.read(reader)
ArrayList<String> components = new ArrayList<String>()
packageBuilder.metaPackage.types.each { type ->
components.add(type.name)
}
return components
return packageBuilder.metaPackage.types
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ class UtilTest extends Specification {
developerName == 'AuthTokenAPI'
}

def "Test should get developerName from a member" () {
when:
def developerName = Util.getDeveloperNameByMember('TwilioConfig__c.AuthTokenAPI__c')
then:
developerName == 'AuthTokenAPI'
}

def cleanupSpec() {
new File(Paths.get(resourcesPath, 'triggers').toString()).deleteDir()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?><Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>*</members>
<name>ApexClass</name>
</types>
<types>
<members>Component1__c.component</members>
<members>Component2__c.component</members>
<name>ApexComponent</name>
</types>
<types>
<members>Object5__c.Field11__c</members>
<members>Object5__c.Field22__c</members>
<members>Object5__c.Field33__c</members>
<name>CustomField</name>
</types>
<version>32.0</version>
</Package>
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,30 @@ class QueryBuilderTest extends Specification {
def packagePath = Paths.get(wscPath, 'resources', 'packageTest.xml').toString()
when:
def componentsObtained = queryBuilder.getComponents(new FileReader(packagePath))
def componentsName = new ArrayList<String>()
componentsObtained.each { component ->
componentsName.add(component.name)
}
componentsName = componentsName.sort()
then:
componentsObtained.sort() == ['ApexClass', 'ApexComponent', 'ApexPage', 'ApexTrigger', 'CustomObject', 'StaticResource'].sort()
componentsName.get(0) == 'ApexClass'
componentsName.get(1) == 'ApexComponent'
componentsName.get(2) == 'ApexPage'
componentsName.get(3) == 'ApexTrigger'
componentsName.get(4) == 'CustomObject'
componentsName.get(5) == 'StaticResource'
}

def "Test should return an array with queries that have fields" () {
given:
def packagePath = Paths.get(wscPath, 'resources', 'packageWithFields.xml').toString()
when:
def queries = queryBuilder.createQueryFromPackage(packagePath)
then:
queries.sort() == ['SELECT Name FROM ApexClass', 'SELECT Name FROM ApexComponent',
"${'SELECT FullName FROM CustomField WHERE DeveloperName = '}${"'Field11'"}",
"${'SELECT FullName FROM CustomField WHERE DeveloperName = '}${"'Field22'"}",
"${'SELECT FullName FROM CustomField WHERE DeveloperName = '}${"'Field33'"}",].sort()
}

def "Test should return an array with queries" () {
Expand Down

0 comments on commit 078d357

Please sign in to comment.