Skip to content

Commit 805a9ef

Browse files
committed
Fix MavenPlugin returning empty stdout&stderr data
1 parent 017a5b0 commit 805a9ef

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

tmc-langs-java/src/main/java/fi/helsinki/cs/tmc/langs/java/maven/MavenInvokatorMavenTaskRunner.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ public MavenExecutionResult exec(Path projectPath, String[] mavenArgs) {
6363
invoker.setMavenHome(new File(mavenHome));
6464

6565
final ByteArrayOutputStream outBuf = new ByteArrayOutputStream();
66+
final ByteArrayOutputStream errBuf = new ByteArrayOutputStream();
6667
final PrintStream out = new PrintStream(outBuf);
68+
final PrintStream err = new PrintStream(errBuf);
6769

6870
InvocationResult result = null;
6971
request.setPomFile(projectPath.resolve("pom.xml").toFile());
@@ -73,18 +75,29 @@ public MavenExecutionResult exec(Path projectPath, String[] mavenArgs) {
7375

7476
@Override
7577
public void consumeLine(String line) {
76-
log.info("MavenInvokator: m{}", line);
77-
out.append(line);
78+
log.info("MavenInvokator: {}", line);
79+
out.println(line);
80+
}
81+
});
82+
request.setErrorHandler(
83+
new InvocationOutputHandler() {
84+
85+
@Override
86+
public void consumeLine(String line) {
87+
log.info("MavenInvokator: {}", line);
88+
err.println(line);
7889
}
7990
});
8091

8192
request.setGoals(Arrays.asList(mavenArgs));
8293

83-
MavenExecutionResult compilationResult =
84-
new MavenExecutionResult().setStdOut(outBuf.toByteArray()).setStdErr(new byte[0]);
94+
MavenExecutionResult compilationResult = new MavenExecutionResult();
8595
try {
8696
result = invoker.execute(request);
8797
compilationResult.setExitCode(result.getExitCode());
98+
// outBuf and errBuf are empty until invoker is executed
99+
compilationResult.setStdOut(outBuf.toByteArray());
100+
compilationResult.setStdErr(errBuf.toByteArray());
88101
CommandLineException exp = result.getExecutionException();
89102
if (exp != null) {
90103
throw new MavenExecutorException(exp);

0 commit comments

Comments
 (0)