mirror of https://github.com/apache/jclouds.git
Issue 502:Scriptbuilder functions are not tolerant of missing final newlines
This commit is contained in:
parent
32fe309424
commit
27c45dce0d
|
@ -133,8 +133,10 @@ public class Utils {
|
|||
|
||||
public static String writeFunctionFromResource(String function, OsFamily family) {
|
||||
try {
|
||||
return CharStreams.toString(Resources.newReaderSupplier(Resources.getResource(Utils.class, String
|
||||
String toReturn = CharStreams.toString(Resources.newReaderSupplier(Resources.getResource(Utils.class, String
|
||||
.format("/functions/%s.%s", function, ShellToken.SH.to(family))), Charsets.UTF_8));
|
||||
String lf = ShellToken.LF.to(family);
|
||||
return toReturn.endsWith(lf) ? toReturn : new StringBuilder(toReturn).append(lf).toString();
|
||||
} catch (IOException e) {
|
||||
throw new FunctionNotFoundException(function, family, e);
|
||||
}
|
||||
|
|
|
@ -39,6 +39,15 @@ public class UtilsTest {
|
|||
"hello world");
|
||||
}
|
||||
|
||||
public void testWriteFunctionFromResourceAddsNewlineUNIX() {
|
||||
assertEquals(Utils.writeFunctionFromResource("nonewline", OsFamily.UNIX), "foo\n");
|
||||
}
|
||||
|
||||
|
||||
public void testWriteFunctionFromResourceAddsNewlineWINDOWS() {
|
||||
assertEquals(Utils.writeFunctionFromResource("nonewline", OsFamily.WINDOWS), "foo\r\n");
|
||||
}
|
||||
|
||||
public void testWriteVariableExportersUNIX() {
|
||||
assertEquals(Utils.writeVariableExporters(ImmutableMap.of("mavenOpts",
|
||||
"-Xms128m -Xmx256m -XX:+HeapDumpOnOutOfMemoryError"), OsFamily.UNIX),
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
foo
|
|
@ -0,0 +1 @@
|
|||
foo
|
Loading…
Reference in New Issue