Skip to content

Commit 5291ed1

Browse files
committed
avoid stderr to output when launching jruby
1 parent fcb3fe7 commit 5291ed1

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

ruby-tools/src/main/java/de/saumya/mojo/ruby/script/AntLauncher.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.io.File;
77
import java.io.IOException;
8+
import java.nio.file.Files;
89
import java.util.List;
910
import java.util.Map;
1011

@@ -105,7 +106,32 @@ protected void doExecute(final File launchDirectory,
105106
if (outputFile != null) {
106107
java.setOutput(outputFile);
107108
}
108-
java.execute();
109+
java.setLogError(true);
110+
File tempFile = null;
111+
try {
112+
tempFile = File.createTempFile("jruby-ant-launcher-", ".log");
113+
tempFile.deleteOnExit();
114+
java.setError(tempFile);
115+
java.execute();
116+
}
117+
catch(IOException e) {
118+
logger.warn("can not create tempfile for stderr");
119+
java.execute();
120+
}
121+
finally {
122+
if (tempFile != null) {
123+
try {
124+
byte[] encoded = Files.readAllBytes(tempFile.toPath());
125+
if (encoded.length > 0) {
126+
logger.error(new String(encoded));
127+
}
128+
}
129+
catch(IOException e) {
130+
logger.warn("can not read error file");
131+
}
132+
tempFile.delete();
133+
}
134+
}
109135
}
110136

111137
private Project createAntProject() {

0 commit comments

Comments
 (0)