org.hidetake.gradle.ssh.internal.DefaultShellContext.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-ssh-plugin Show documentation
Show all versions of gradle-ssh-plugin Show documentation
Gradle SSH Plugin provides remote execution and file transfer capabilities
package org.hidetake.gradle.ssh.internal
import com.jcraft.jsch.ChannelShell
import groovy.transform.TupleConstructor
import org.gradle.api.logging.LogLevel
import org.gradle.api.logging.Logging
import org.hidetake.gradle.ssh.api.CommandContext
import org.hidetake.gradle.ssh.api.command.Stream
import org.hidetake.gradle.ssh.internal.command.Engine
import org.hidetake.gradle.ssh.internal.command.InteractionDelegate
import org.hidetake.gradle.ssh.internal.command.LineOutputStream
@TupleConstructor
class DefaultShellContext implements CommandContext {
final ChannelShell channel
final OutputStream standardInput
final LineOutputStream standardOutput
private static final logger = Logging.getLogger(DefaultShellContext)
/**
* Create an instance for the channel.
*
* @param channel the channel
* @param charset character set for streams
* @return an instance
*/
static create(ChannelShell channel, String charset) {
def standardOutputStream = new LineOutputStream(charset)
channel.outputStream = standardOutputStream
new DefaultShellContext(channel, channel.outputStream, standardOutputStream)
}
void enableLogging(LogLevel standardOutputLevel) {
standardOutput.loggingListeners.add { String message -> logger.log(standardOutputLevel, message) }
}
@Override
void interaction(Closure closure) {
def delegate = new InteractionDelegate(standardInput)
def rules = delegate.evaluate(closure)
def engine = new Engine(delegate)
engine.alterInteractionRules(rules)
engine.attach(standardOutput, Stream.StandardOutput)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy