-
Notifications
You must be signed in to change notification settings - Fork 0
/
drush.gradle
80 lines (74 loc) · 2.61 KB
/
drush.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
repositories {
mavenCentral()
}
configurations {
antssh
}
dependencies {
antssh group: 'org.apache.ant', name: 'ant-jsch', version: '1.7.0'
}
ClassLoader antClassLoader = org.apache.tools.ant.Project.class.classLoader
configurations.antssh.each { File f ->
antClassLoader.addURL(f.toURI().toURL())
}
ext.drush = { Map args ->
String drushCmd = args.drushCmd
String siteUrl = args.siteUrl?:ant.properties."drush.url"
String root = args.root?:ant.properties."drush.root"
String host = args.host?:ant.properties."drush.host"
String keyFile = args.keyFile?:ant.properties."build.userkey"
String buildUser = args.buildUser?:ant.properties."build.user"
String passphrase = args.passphrase?:ant.properties."build.userPassphrase"
Boolean failOnError = args.failOnError?: true
String extraDrushParams = args.extraDrushParams?:""
def cmd = "${ant.properties["drush.executable"]} ${extraDrushParams} --uri=${siteUrl} --root=${root} --yes --verbose ${drushCmd}"
new File(ant.properties.remoteOutputFile).append("\nRunning:: ${cmd}\nOn host ${host} As ${buildUser}\nOutput:\n")
ant.sshexec(
username: buildUser,
host:host,
command: cmd,
failonerror:false,
keyfile:keyFile,
passphrase:passphrase,
append: true,
trust:true,
outputproperty: "drushOutputBuffer",
output:ant.properties.remoteOutputFile,
verbose: 'true'
)
if (args.failOnError && ant.properties.drushOutputBuffer.contains("[error]")){
throw new Exception("Drush command returned an error:\n${ant.properties.drushOutputBuffer}")
}
}
ext.drushMake = { Map args ->
String makeFile = args.makeFile
String target = args.target?:ant.properties.build
Boolean failOnError = args.failOnError?: true
def cmd = "${ant.properties["drush.executable"]} --debug make ${args.extraArgs} ${makeFile} ${target}"
new File(ant.properties.remoteOutputFile).append("\nRunning:: ${cmd}\nOn localhost in ${ant.properties.workspace}")
runCmd(
cmd,
new File(ant.properties.workspace)
)
}
try {
ext.drushTasks = []
drush(drushCmd: "help --pipe 2> /dev/null")
ant.properties.drushOutputBuffer.split("\n").each{
it.split(/\s/).each{ cmd ->
drushTasks << cmd
}
}
} catch (Exception e){
println e
println "WARNING: Drush failed to initialise all drush commands. This is not a fatal error."
}
drushTasks.each{ command ->
task "drush_$command" << {
if (project.hasProperty('drushArgs'))
command = "$command ${project.ext.drushArgs}"
drush(
drushCmd: "$command"
)
}
}