DSL for executing commands over SSH
DSL is quite a popular technique to help a developer to define program or business logic in a more readable and concise way compared to using the general-purpose language features. There are two types of DSLs: internal and external. Internal (or embedded) DSLs exploit host language features to build a fluent library API that makes certain concepts more readable in the host language itself. External DSLs call for a specifically designed language that is not bound to host language and usually requires a separately developed DSL parser.
With the help of Groovy, you can create both DSL types with ease. In this recipe, we will define an internal DSL for executing remote SSH commands.
Getting ready
We are going to use the JSch
library (http://www.jcraft.com/jsch/), which is used by many other Java libraries that require SSH connectivity.
The following Gradle script (see the Integrating Groovy into the build process using Gradle recipe in Chapter 2, Using Groovy...