From 629cbd8eedc0147b701f22f28b9ec8b1b8084015 Mon Sep 17 00:00:00 2001 From: Pavel Punegov <32519625+PavelPunegov@users.noreply.github.com> Date: Tue, 7 Nov 2017 16:41:30 +0300 Subject: [PATCH] Make execRemote work for both action and closure --- .../org/jetbrains/kotlin/ExecRemote.groovy | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/ExecRemote.groovy b/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/ExecRemote.groovy index eec841e0dfb..e3dad8b2d1c 100644 --- a/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/ExecRemote.groovy +++ b/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/ExecRemote.groovy @@ -33,7 +33,7 @@ import java.util.function.Function class ExecRemote { private final Project project - private final Function, ExecResult> executor + private final Function, ExecResult> executor ExecRemote(Project project) { this.project = project @@ -41,37 +41,41 @@ class ExecRemote { def remote = project.property('remote') as String executor = new SSHExecutor(remote) } else { - executor = { project.exec(ConfigureUtil.configureUsing(it)) } + executor = { project.exec(it) } } } - ExecResult execRemote(Action action) { - project.exec(action) - } - ExecResult execRemote(Closure closure) { - this.executor.apply(closure) + this.execRemote(ConfigureUtil.configureUsing(closure)) } - private class SSHExecutor implements Function, ExecResult> { + ExecResult execRemote(Action action) { + this.executor.apply(action) + } + + private class SSHExecutor implements Function, ExecResult> { private final String remote private final String remoteDir SSHExecutor(String remote) { this.remote = remote this.remoteDir = uniqueSessionName() - createRemoteDir() } @Override - ExecResult apply(Closure closure) { + ExecResult apply(Action action) { String execFile - def execResult = project.exec closure >> { - upload(executable) - execFile = executable = "$remoteDir/${new File(executable).name}" - commandLine = ['/usr/bin/ssh', remote] + commandLine + + createRemoteDir() + def execResult = project.exec { ExecSpec execSpec -> + action.execute(execSpec) + execSpec.with { + upload(executable) + execFile = executable = "$remoteDir/${new File(executable).name}" + commandLine = ['/usr/bin/ssh', remote] + commandLine + } } - if (execFile != null) cleanup(execFile) + cleanup(execFile) return execResult }