au.net.causal.maven.plugins.boxdb.db.ScriptUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of boxdb-maven-plugin Show documentation
Show all versions of boxdb-maven-plugin Show documentation
Maven plugin to start databases using Docker and VMs
package au.net.causal.maven.plugins.boxdb.db;
/**
* Tools for creating command lines for unix shell scripts.
*/
public final class ScriptUtils
{
/**
* Private constructor to prevent instantiation.
*/
private ScriptUtils()
{
}
/**
* Escapes a string suitable for use with a unix shell. Whole string is put in quotes, and existing quotes
* are escaped.
*
* @param s the string to escape.
*
* @return an escaped string.
*/
public static String shellEscape(String s)
{
StringBuilder buf = new StringBuilder();
buf.append('\'');
for (char c : s.toCharArray())
{
if (c == '\'')
buf.append("'\\''");
else
buf.append(c);
}
buf.append('\'');
return buf.toString();
}
}