-
Notifications
You must be signed in to change notification settings - Fork 1
/
mrgadget-plugin.gradle
156 lines (110 loc) · 3.82 KB
/
mrgadget-plugin.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
// THIS FILE IS AUTOGENERATED -- DO NOT EDIT!
import org.gradle.api.Plugin;
import org.gradle.api.Project;
apply plugin: 'groovy'
apply plugin: MrGadgetPlugin
buildscript {
repositories {
ivy {
url = 'https://raw.github.com/moksamedia/mrgadget/master/repo'
name = 'mrgadget-plugin'
layout 'pattern' , {
artifact "[organization]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]"
}
}
}
dependencies {
classpath "com_moksamedia:mrgadget:${project.ext.hasProperty('mrGadgetVersion') ? project.ext.mrGadgetVersion : "0.3.1"}:jar-with-dependencies"
}
}
import org.gradle.api.Plugin
import org.gradle.api.Project
import com.moksamedia.mrgadget.MrGadget
class MrGadgetPlugin implements Plugin<Project> {
MrGadget mrg
void apply(Project project) {
project.extensions.mrgadget = new MrGadgetPluginExtension()
project.metaClass.initMrGadget = { def params = [:] ->
def toUse = project.extensions.mrgadget.properties
toUse.putAll(params)
toUse.remove('metaClass') // not strictly necessary, but why not?
toUse.remove('class')
mrg?.closeSession()
mrg = new MrGadget(toUse)
}
project.metaClass."$project.extensions.mrgadget.execRemoteMethodName" = { def params ->
// if we pass in a string
if (params instanceof String || params instanceof GString) {
if (mrg==null) {
initMrGadget() // init with params defined in extension
}
mrg.execRemote(params)
}
else {
if (mrg==null) initMrGadget(params)
else mrg.setParams(params)
assert params.command != null
mrg.execRemote(params.command)
}
}
project.metaClass."$project.extensions.mrgadget.execRemoteSudoMethodName" = { def params ->
if (params instanceof String || params instanceof GString) {
if (mrg==null) {
initMrGadget()
}
mrg.execRemoteSudo(params)
}
else {
if (mrg==null) initMrGadget(params)
else mrg.setParams(params)
assert params.command != null
mrg.execRemoteSudo(params.command)
}
}
project.metaClass."$project.extensions.mrgadget.copyToRemoteSCPMethodName" = { def params = [:] ->
if (mrg==null) initMrGadget(params)
else mrg.setParams(params)
mrg.copyToRemoteSCP([localFile:params.localFile, remoteFile:params.remoteFile])
}
project.metaClass."$project.extensions.mrgadget.copyToRemoteSFTPMethodName" = { def params = [:] ->
if (mrg==null) initMrGadget(params)
else mrg.setParams(params)
mrg.copyToRemoteSFTP([localFile:params.localFile, remoteFile:params.remoteFile])
}
project.metaClass."$project.extensions.mrgadget.copyToRemoteRSYNCMethodName" = { def params = [:] ->
if (mrg==null) initMrGadget(params)
else mrg.setParams(params)
mrg.copyToRemoteRSYNC(params)
}
project.metaClass.closeMrGadgetSession = {
mrg?.closeSession()
}
project.metaClass.clearMrGadgetPasswords = {
if (mrg==null) initMrGadget(clearAllPasswords:true)
else mrg.clearAllPasswords()
}
project.metaClass.getMrGadget = {
mrg
}
}
}
class MrGadgetPluginExtension {
def String user
def String host
def String prefEncryptionKey = null
def String password = null
def String sudoPassword = null
def String privateKey = null
def int logProgressGranularity = 10
def boolean leaveSessionOpen = false
def boolean sudoPassDifferent = false
def boolean promptToSavePass = true
def boolean strictHostKeyChecking = true
def boolean showProgressDialog = true
def boolean preserveTimestamp = false
def String execRemoteMethodName = "execRemote"
def String execRemoteSudoMethodName = "execRemoteSudo"
def String copyToRemoteSCPMethodName = "copyToRemoteSCP"
def String copyToRemoteSFTPMethodName = "copyToRemoteSFTP"
def String copyToRemoteRSYNCMethodName = "copyToRemoteRSYNC"
}