-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle
769 lines (648 loc) · 26.1 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
// apply plugin: 'java'
// apply plugin: 'groovy'
import groovy.xml.*
import groovy.json.*
import groovy.xml.NamespaceBuilder
import groovy.transform.ToString
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.*
import static groovyx.net.http.ContentType.*
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'org.codehaus.groovy.modules.http-builder', name: 'http-builder', version: '0.7.1'
}
}
Properties privateProperties = new Properties()
privateProperties.load(new FileInputStream("private.sf.properties"))
ext {
sfUsername = privateProperties.getProperty('sf.username')
sfPassword = privateProperties.getProperty('sf.password')
serverUrlSyncFrom = getProjectProperty('sf.url.sync.from')
sfUsernameSyncFrom = privateProperties.getProperty('sf.username.sync.from')
sfPasswordSyncFrom = privateProperties.getProperty('sf.password.sync.from')
serverUrlSyncTo = getProjectProperty('sf.url.sync.to')
sfUsernameSyncTo = privateProperties.getProperty('sf.username.sync.to')
sfPasswordSyncTo = privateProperties.getProperty('sf.password.sync.to')
gradleHome = System.getenv('GRADLE_HOME')
sfLibPath = gradleHome + '/lib/ant-salesforce.jar'
}
ant.taskdef(
resource: 'com/salesforce/antlib.xml',
uri: 'antlib:com.salesforce',
classpath: sfLibPath
)
def sfAnt = NamespaceBuilder.newInstance(ant, 'antlib:com.salesforce')
task cleanDirs << {
def syncDirName = getProjectProperty('sync.folder')
def syncDir = new File(syncDirName)
if(syncDir.exists()) {
delete syncDirName
}
syncDir.mkdir()
def buildDirName = getProjectProperty('build.dir')
def buildDir = new File(buildDirName)
if(buildDir.exists()) {
delete buildDirName
}
buildDir.mkdir()
}
task sync(dependsOn: cleanDirs) << {
def fromBranchName = getProjectProperty('git.branch.sync.from')
def toBranchName = getProjectProperty('git.branch.sync.to')
def remote = getProjectProperty('git.remote')
def requiredMetadataSet = getProjectProperty('sync.metadata').tokenize(',').toSet()
// // From
def toAvalibleMetadataList = getAvalibleMetadata(sfAnt, sfUsernameSyncFrom, sfPasswordSyncFrom, serverUrlSyncFrom)
formatPrint('Generating package.xml')
generateFullPackageXml(sfAnt, sfUsernameSyncFrom, sfPasswordSyncFrom, serverUrlSyncFrom,
toAvalibleMetadataList, requiredMetadataSet)
getMetadataAndCommit(sfAnt, sfUsernameSyncFrom, sfPasswordSyncFrom, serverUrlSyncFrom, fromBranchName)
tasks.cleanDirs.execute()
// To
def fromAvalibleMetadataList = getAvalibleMetadata(sfAnt, sfUsernameSyncTo, sfPasswordSyncTo, serverUrlSyncTo)
formatPrint('Generating package.xml')
generateFullPackageXml(sfAnt, sfUsernameSyncTo, sfPasswordSyncTo, serverUrlSyncTo, fromAvalibleMetadataList, requiredMetadataSet)
getMetadataAndCommit(sfAnt, sfUsernameSyncTo, sfPasswordSyncTo, serverUrlSyncTo, toBranchName)
def stream = new ByteArrayOutputStream()
execGit('.', ['diff', '--name-status', "${remote}/${toBranchName}..${remote}/${fromBranchName}", 'src'],
stream)
deployChangesInGit(sfAnt, stream.toString(), sfUsernameSyncTo, sfPasswordSyncTo, serverUrlSyncTo, 'deploy/src', toAvalibleMetadataList)
}
def getMetadataAndCommit(sfAnt, username, password, serverUrl, branchName) {
def commitMsg = getProjectProperty('git.commit.sync.msg') + ' on ' + new Date()
def syncFolderName = getProjectProperty('sync.folder')
def srcFolderName = 'src'
def syncDir = new File(syncFolderName)
if(!syncDir.exists()) {
syncDir.mkdir()
}
def srcFolder = new File(srcFolderName)
if(!srcFolder.exists()) {
srcFolder.mkdir()
}
formatPrint('Checkout to branch : ' + branchName)
execGit('.', ['checkout', branchName], null)
formatPrint('Retrieve Metadata from server')
retrieveMetadataFromServer(sfAnt, username, password, serverUrl, 'src', syncFolderName + '/package.xml')
formatPrint('Add files to index...')
execGit('src', ['add', '-A'], null)
formatPrint('Diffing...')
ByteArrayOutputStream stream = new ByteArrayOutputStream()
execGit('.', ['diff', 'HEAD', '--name-only'], stream)
String gitOutput = stream.toString()
Boolean isAnyChanges = gitOutput != null && gitOutput.trim() != '';
if (!isAnyChanges) {
formatPrint('There are no chages in branch : ' + branchName)
}
formatPrint('Commit...')
execGit('.', ['commit', '-m', commitMsg], null)
formatPrint('Push...')
execGit('.', ['push', 'origin', branchName], null)
}
def getEmailTemplates(serverUrl, username, password) {
def emailTemplates = []
def sessionIdObj = getSessionId(serverUrl, username, password)
String sessionId = sessionIdObj.sessionId
URI fullUri = new URI(sessionIdObj.url as String)
def http = new HTTPBuilder("${fullUri.scheme}://${fullUri.host}")
http.request(GET) { req ->
uri.path = '/services/data/v33.0/tooling/query'
uri.query = [q : 'Select id,FullName from EmailTemplate' ]
headers.'Authorization' = "Bearer ${sessionId}"
response.success = { resp, reader ->
reader.records.each {
emailTemplates.add(it.FullName)
}
}
response.failure = { resp ->
formatPrint('Get Email Templates request error')
}
}
return emailTemplates
}
def Expando getSessionId(url, username, password) {
def http = new HTTPBuilder(url)
String requestBody =
"""
<env:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
<env:Body>
<sf:login xmlns:sf='urn:enterprise.soap.sforce.com'>
<sf:username>${username}</sf:username>
<sf:password>${password}</sf:password>
</sf:login>
</env:Body>
</env:Envelope>
"""
http.request(POST) { req ->
uri.path = '/services/Soap/c/33.0'
requestContentType = URLENC
headers.'Content-Type' = "text/xml"
headers.'SOAPAction' = "login"
body = requestBody
response.success = { resp, reader ->
return new Expando(sessionId : reader.Body.loginResponse.result.sessionId,
url : reader.Body.loginResponse.result.serverUrl);
}
response.failure = { resp ->
formatPrint('Session Id request error')
}
}
}
def getAvalibleMetadata(sfAnt, username, password, serverUrl) {
String describeFileName = getProjectProperty('sync.describe.path');
getMetadataDescription(sfAnt, username, password, serverUrl, describeFileName)
def describeFile = new File(describeFileName)
if(!describeFile.exists()) {
return
}
String XML_NAME = 'XMLName: '
String DIR_NAME = 'DirName: '
String SUFFIX = 'Suffix: '
String HASMETAFILE = 'HasMetaFile: '
String INFOLDER = 'InFolder: '
String CHILDOBJECTS = 'ChildObjects: '
List<MetadataType> sfMetadataList = new ArrayList<MetadataType>()
MetadataType metaType;
describeFile.eachLine { line, index ->
if(line.startsWith('*****')) {
if(index > 1) {
sfMetadataList.add(metaType)
}
metaType = new MetadataType()
return
}
if(line.startsWith(XML_NAME)) {
metaType.xmlName = line.substring(XML_NAME.length())
} else if(line.startsWith(DIR_NAME)) {
metaType.dirName = line.substring(DIR_NAME.length())
} else if(line.startsWith(SUFFIX)) {
metaType.suffix = line.substring(SUFFIX.length())
} else if(line.startsWith(HASMETAFILE)) {
metaType.hasMetaFile = line.substring(HASMETAFILE.length()).toBoolean()
} else if(line.startsWith(INFOLDER)) {
metaType.inFolder = line.substring(INFOLDER.length()).toBoolean()
} else if(line.startsWith(CHILDOBJECTS)) {
def commaSeparatedValues = line.substring(CHILDOBJECTS.length())
if(!commaSeparatedValues.contains(',')) {
return
}
def childs = commaSeparatedValues.split(',')
metaType.childObjects = childs.take(childs.size() - 1)
}
}
return sfMetadataList
}
def generateFullPackageXml(sfAnt, username, password, serverUrl, avalibleMetadataList, requiredMetadataSet) {
String tempFolderName = getProjectProperty('sync.folder')
def folder = new File(tempFolderName)
if(!folder.exists()) {
folder.mkdir()
}
def ignoredMetadataTypes = ['EmailTemplate', 'Scontrol']
def metadataTypeFileNamesMap = [:]
def FOLDER = 'Folder'
def METADATA_ID = 'FullName/Id: '
def MANAGEABLE_STATE = 'Manageable State: '
def manageableStateValues = ['unmanaged', 'null']
avalibleMetadataList.each { metaType ->
if(ignoredMetadataTypes.contains(metaType.xmlName)) {
return
}
if(!requiredMetadataSet.contains(metaType.xmlName)) {
return
}
formatPrint('Processing : ' + metaType.xmlName)
def metaFilesLocation = "${tempFolderName}/${metaType.dirName}"
def folders = []
if(metaType.inFolder) {
getListMetadata(sfAnt, username, password, serverUrl, metaType.xmlName + FOLDER, metaFilesLocation, '')
def metaFile = new File(metaFilesLocation)
if(!metaFile.exists()) {
return
}
metaFile.eachLine { line ->
if(line.startsWith(METADATA_ID)) {
def fName = line.substring(METADATA_ID.length(),
line.indexOf('/', METADATA_ID.length()))
folders.add(fName)
}
}
} else {
folders.add('')
}
folders.each { folderName ->
getListMetadata(sfAnt, username, password, serverUrl, metaType.xmlName, metaFilesLocation, folderName)
def metaFile = new File(metaFilesLocation)
if(!metaFile.exists()) {
return
}
def metadataFiles = []
def metadataFileName = ''
metaFile.eachLine { line ->
if(line.startsWith('*****')) {
metadataFileName = ''
return
}
if(line.startsWith(METADATA_ID)) {
metadataFileName = line.substring(METADATA_ID.length(),
line.indexOf('/', METADATA_ID.length()))
}
if(line.startsWith(MANAGEABLE_STATE)) {
def manageableStateValue = line.substring(MANAGEABLE_STATE.length())
if(manageableStateValues.contains(manageableStateValue)
&& metadataFileName != '') {
metadataFiles.add(metadataFileName)
}
}
}
metadataTypeFileNamesMap.put(metaType.xmlName, metadataFiles.toSet())
}
}
metadataTypeFileNamesMap.put('EmailTemplate', getEmailTemplates(serverUrl, username, password))
String packageXmlLocation = "${tempFolderName}/package.xml"
def packageXmlFile = new File(packageXmlLocation)
packageXmlFile.setText(createPackageXml(metadataTypeFileNamesMap, false, null), 'UTF-8')
}
task deployChanges(/*dependsOn: 'backup'*/) << {
def stream = new ByteArrayOutputStream()
def result = execGit('.', ['diff-tree', '--no-commit-id', '--name-status','-r',
getProjectProperty('git.commit.id.last'),
getProjectProperty('git.commit.id.first')], stream)
// TODO: Define required params
// deployChanges(stream.toString())
}
def deployChangesInGit(sfAnt, gitDiffOutput, username, password, serverUrl, projectFolder, avalibleMetadataList) {
formatPrint('Changed files : \r\n' + gitDiffOutput)
def parseWrapper = parseGitOutput(gitDiffOutput)
def changedSourceFiles = parseWrapper.changedFiles
def folderNameChangedFilesMap = parseWrapper.folderFilesMap
def folderNameDeletedFilesMap = parseWrapper.filderDeletedFilesMap
if (changedSourceFiles.size() == 0 && folderNameDeletedFilesMap.keySet().size() == 0) {
formatPrint('There no changed files for deploy')
return
}
def sourceAndItsMetadataFiles = addMetadataFilesToSources(changedSourceFiles)
formatPrint('Changed Files For Deploy : \r\n' + sourceAndItsMetadataFiles)
delete getProjectProperty('build.dir')
formatPrint('Delete Forlder : ' + getProjectProperty('build.dir'))
File deployDir = new File(getProjectProperty('build.dir'))
deployDir.mkdir()
copy {
from getProjectProperty('src.dir')
into getProjectProperty('build.dir')
include sourceAndItsMetadataFiles
}
formatPrint('Copy Files From : ' + getProjectProperty('src.dir') +
' To : ' + getProjectProperty('build.dir'))
// def currentSfApiVersion = getCurrentSfApiVersion()
// formatPrint('Current SF API Version : ' + currentSfApiVersion)
if (folderNameDeletedFilesMap.keySet().size() > 0) {
String antOutput = '';
// def metadataDescribe = new JsonSlurper()
// .parse(file(getProjectProperty('metadata.describe.location')))
folderNameDeletedFilesMap.each { folder, listOfMetadata ->
def theNode = avalibleMetadataList.find { it.dirName == folder }
println 'folder = ' + folder
println 'theNode = ' + theNode
if(theNode == null) {
return
}
getListMetadata(sfAnt, username, password, serverUrl, theNode.xmlName, 'listMetadata.log', '')
antOutput += new File('listMetadata.log').text
}
def folderNameExistDeleteFilesMap = [:]
folderNameDeletedFilesMap.each { folder, listOfMetadata ->
listOfMetadata.each { metadataFile ->
def folderWithMetadata = folder + '/' + metadataFile
if (antOutput.contains(folderWithMetadata)) {
def metadataList = folderNameExistDeleteFilesMap.get(folder)
if (metadataList) {
metadataList.add(metadataFile)
} else{
metadataList = [metadataFile]
}
folderNameExistDeleteFilesMap.put(folder, metadataList)
}
}
}
if(folderNameExistDeleteFilesMap.keySet().size() == 0
&& changedSourceFiles.size() == 0) {
return
}
if (folderNameExistDeleteFilesMap.keySet().size() > 0) {
def destructiveChangesXmlString = createPackageXml(folderNameExistDeleteFilesMap, true, avalibleMetadataList)
formatPrint('destructiveChnges.xml : \r\n' + destructiveChangesXmlString)
def destructiveChangesXml =
new File(getProjectProperty('build.dir') + '/src/destructiveChanges.xml')
destructiveChangesXml.text = destructiveChangesXmlString
}
}
def packageXmlString = createPackageXml(folderNameChangedFilesMap, true, avalibleMetadataList)
formatPrint('Package.xml : \r\n' + packageXmlString)
def packageXml = new File(getProjectProperty('build.dir') + '/src/package.xml')
packageXml.text = packageXmlString
// tasks.'deployMetadata'.execute()
deployMetadata(sfAnt, username, password, serverUrl, projectFolder)
}
task backup << {
def backupDir = getProjectProperty('backup.dir')
def backupPackageXml = getProjectProperty('backup.packageXml')
def repositoryUrl = getProjectProperty('git.repository.url')
def remote = getProjectProperty('git.remote.name')
def backupBranch = getProjectProperty('git.backup.branch')
def commitMsg = getProjectProperty('git.commit.backup.msg') + ' ' + new Date()
def folder = new File(backupDir)
if (!folder.exists()) {
folder.mkdirs()
} else {
folder.deleteDir()
}
formatPrint('Cloning...')
def result = execGit('.', ['clone', repositoryUrl, backupDir], null)
def stream = new ByteArrayOutputStream()
result = execGit(backupDir, ['branch', '-r'], stream)
String gitOutput = stream.toString()
formatPrint('Checkout to backup branch...')
if (!gitOutput.contains(remote + '/' + backupBranch)) {
result = execGit(backupDir, ['checkout', '-b', backupBranch], null)
} else {
result = execGit(backupDir, ['checkout', backupBranch], null)
}
formatPrint('Retrieve Metadata...')
retrieveMetadataFromServer(sfAnt, backupDir + '/src', backupPackageXml)
formatPrint('Add file to index...')
result = execGit(backupDir, ['add', '-A'], null)
formatPrint('Diffing...')
gitOutput = ''
stream = new ByteArrayOutputStream()
result = execGit(backupDir, ['diff', 'HEAD', '--name-only'], stream)
gitOutput = stream.toString()
Boolean isAnyChanges = gitOutput != null && gitOutput.trim() != '';
if (!isAnyChanges) {
formatPrint('There are no chages. Backup is up to date.')
return
}
formatPrint('Commit...')
result = execGit(backupDir, ['commit', '-m', commitMsg], null)
formatPrint('Push...')
result = execGit(backupDir, ['push', 'origin', backupBranch], null)
}
def Expando parseGitOutput(String output) {
def changedFiles = output.split('\\n')
def changedSourceFiles = [];
def folderNameChangedFilesMap = [:]
def folderNameDeletedFilesMap = [:]
changedFiles.each { changedFile ->
// Possible Modifiers
// ' ' = unmodified
// M = modified
// A = added
// D = deleted
// R = renamed
// C = copied
// U = updated but unmerged
def modifier = changedFile.substring(0, 1)
// Remove Modifier
changedFile = changedFile.substring(1, changedFile.length()).trim()
def filePath = changedFile.split('/')
if (filePath.size() >= 3) {
def metadataFolderName = filePath[1]
def changedFilesInFolder = null
if (modifier == 'D') {
changedFilesInFolder = folderNameDeletedFilesMap.get(metadataFolderName)
} else {
changedFilesInFolder = folderNameChangedFilesMap.get(metadataFolderName)
}
def currentFile = filePath[filePath.size() - 1]
if (currentFile.indexOf('-meta.xml') == -1) {
def currentFileWithoutExtension = currentFile
.substring(0, currentFile.lastIndexOf('.'))
if (changedFilesInFolder) {
changedFilesInFolder.add(currentFileWithoutExtension)
} else {
changedFilesInFolder = [ currentFileWithoutExtension ]
}
if (modifier == 'D') {
folderNameDeletedFilesMap.put(metadataFolderName, changedFilesInFolder)
} else {
changedSourceFiles.add(changedFile)
folderNameChangedFilesMap.put(metadataFolderName, changedFilesInFolder)
}
}
}
}
return new Expando( changedFiles : changedSourceFiles,
folderFilesMap : folderNameChangedFilesMap,
filderDeletedFilesMap : folderNameDeletedFilesMap);
}
def List<String> addMetadataFilesToSources(List<String> changedSourceFiles) {
def sourceAndItsMetadataFiles = []
for (def i in changedSourceFiles) {
sourceAndItsMetadataFiles.add(i)
sourceAndItsMetadataFiles.add(i + '-meta.xml')
}
return sourceAndItsMetadataFiles
}
def String getCurrentSfApiVersion() {
def originalPackageXml = new XmlParser()
.parse('src/package.xml')
return originalPackageXml.get('version').text();
}
def String createPackageXml(Map<String, List<String>> folderNameChangedFilesMap, Boolean translateName, avalibleMetadataList) {
// def metadataDescribe = new JsonSlurper()
// .parse(file(getProjectProperty('metadata.describe.location')))
def ignoredMap = ['CustomObject':['UserTerritory2Association', 'Territory2Model', 'Territory2']]
def stringWriter = new StringWriter()
def builder = new MarkupBuilder(stringWriter)
builder.mkp.xmlDeclaration(version: "1.0", encoding: "UTF-8")
builder.package('xmlns' : "http://soap.sforce.com/2006/04/metadata"){
for(filderName in folderNameChangedFilesMap.keySet()) {
types() {
def files = folderNameChangedFilesMap.get(filderName)
for(file in files) {
members(file)
}
String xmlName = '';
if(translateName) {
def theNode = avalibleMetadataList
.find { it.dirName == filderName }
xmlName = theNode.xmlName
} else {
xmlName = filderName
}
delegate.name(xmlName)
}
}
delegate.version('33.0'/*currentSfApiVersion*/)
}
return stringWriter.toString()
}
def String getProjectProperty(String propertyName) {
String customProprty = null
if (hasProperty(propertyName)) {
customProprty = this.properties[propertyName]
}
return customProprty
}
def String execGit(String gitWorkingDir, List<String> gitArgs, OutputStream output) {
if (output == null) {
output = System.out
}
return exec {
workingDir = gitWorkingDir
executable = 'git'
args = gitArgs
standardOutput = output
}
}
def formatPrint(String message) {
logger.quiet('')
logger.quiet('==========================================')
logger.quiet(message)
logger.quiet('==========================================')
logger.quiet('')
}
def retrieveMetadataFromServer(sfAnt, String targetPath, String packageXmlPath) {
sfAnt.retrieve(
username : sfUsername,
password : sfPassword,
serverurl : getProjectProperty('sf.serverurl'),
maxPoll : getProjectProperty('sf.maxPoll'),
retrieveTarget : targetPath,
unpackaged : packageXmlPath
)
}
def retrieveMetadataFromServer(sfAnt, username, password, serverUrl, targetPath, packageXmlPath) {
sfAnt.retrieve(
username : username,
password : password,
serverurl : serverUrl,
maxPoll : getProjectProperty('sf.maxPoll'),
retrieveTarget : targetPath,
unpackaged : packageXmlPath
)
}
def getListMetadata(sfAnt, String metadataType, String resultPath) {
sfAnt.listMetadata(
username : sfUsername,
password : sfPassword,
serverurl : getProjectProperty('sf.serverurl'),
metadataType : metadataType,
resultFilePath : resultPath
)
}
def getListMetadata(sfAnt, String metadataType, String resultPath, String folderName) {
sfAnt.listMetadata(
username : sfUsername,
password : sfPassword,
serverurl : getProjectProperty('sf.serverurl'),
metadataType : metadataType,
folder : folderName,
resultFilePath : resultPath
)
}
def getMetadataDescription(sfAnt, filePath) {
sfAnt.describeMetadata(
username : sfUsername,
password : sfPassword,
serverurl : getProjectProperty('sf.serverurl'),
resultFilePath : filePath
)
}
def getMetadataDescription(sfAnt, username, password, serverUrl, filePath) {
sfAnt.describeMetadata(
username : username,
password : password,
serverurl : serverUrl,
resultFilePath : filePath
)
}
def getListMetadata(sfAnt, username, password, serverUrl, metadataType, resultPath, folderName) {
sfAnt.listMetadata(
username : username,
password : password,
serverurl : serverUrl,
metadataType : metadataType,
folder : folderName,
resultFilePath : resultPath
)
}
def deployMetadata(sfAnt, username, password, url, folder) {
sfAnt.deploy(
serverurl : url,
username : username,
password : password,
maxPoll : getProjectProperty('sf.maxPoll'),
deployRoot : folder,
rollbackOnError : getProjectProperty('sf.rollbackOnError'),
checkOnly : getProjectProperty('sf.checkOnly'),
runAllTests : getProjectProperty('sf.runAllTests')
)
}
// Standard task
task retrieveMetadata << {
sfAnt.retrieve(
username : sfUsername,
password : sfPassword,
serverurl : getProjectProperty('sf.serverurl'),
maxPoll : getProjectProperty('sf.maxPoll'),
retrieveTarget : getProjectProperty('sf.path.retrieveTarget'),
unpackaged : getProjectProperty('sf.path.packageXml')
)
}
task deployMetadata << {
sfAnt.deploy(
serverurl : getProjectProperty('sf.serverurl'),
username : sfUsername,
password : sfPassword,
maxPoll : getProjectProperty('sf.maxPoll'),
deployRoot : getProjectProperty('sf.deployRoot'),
rollbackOnError : getProjectProperty('sf.rollbackOnError'),
checkOnly : getProjectProperty('sf.checkOnly'),
runAllTests : getProjectProperty('sf.runAllTests')
)
}
// <!-- logType="Debugonly" -->
// <!-- <runTest>SampleDeployClass</runTest> -->
task listMetadata << {
sfAnt.listMetadata(
username : sfUsername,
password : sfPassword,
serverurl : getProjectProperty('sf.serverurl'),
folder : '',
metadataType : getProjectProperty('sf.metadataType')
)
}
task bulkRetrieve << {
sfAnt.bulkRetrieve(
username : sfUsername,
password : sfPassword,
serverurl : getProjectProperty('sf.serverurl'),
maxPoll : getProjectProperty('sf.maxPoll'),
metadataType : getProjectProperty('sf.metadataType'),
retrieveTarget : getProjectProperty('sf.metadataDir')
)
}
task describeMetadata << {
sfAnt.describeMetadata(
username : sfUsername,
password : sfPassword,
serverurl : getProjectProperty('sf.serverurl'),
resultFilePath : 'describe.log'
)
}
@ToString(includeNames=true)
class MetadataType {
String xmlName
String dirName
String suffix
Boolean hasMetaFile
Boolean inFolder
String[] childObjects
}
tasks.each {
task -> task.group = 'gres.sf'
}