|
11 | 11 | import fi.helsinki.cs.tmc.langs.java.TestRunFileAndLogs;
|
12 | 12 | import fi.helsinki.cs.tmc.langs.java.exception.TestRunnerException;
|
13 | 13 | import fi.helsinki.cs.tmc.langs.java.exception.TestScannerException;
|
| 14 | +import fi.helsinki.cs.tmc.langs.utils.ProcessResult; |
| 15 | +import fi.helsinki.cs.tmc.langs.utils.ProcessRunner; |
14 | 16 |
|
15 | 17 | import com.google.common.base.Optional;
|
16 | 18 | import com.google.common.base.Preconditions;
|
|
25 | 27 | import org.slf4j.Logger;
|
26 | 28 | import org.slf4j.LoggerFactory;
|
27 | 29 |
|
28 |
| -import java.io.BufferedReader; |
29 | 30 | import java.io.File;
|
30 | 31 | import java.io.IOException;
|
31 | 32 | import java.io.InputStream;
|
32 |
| -import java.io.InputStreamReader; |
33 | 33 | import java.io.PrintStream;
|
34 | 34 | import java.nio.charset.Charset;
|
35 | 35 | import java.nio.file.Files;
|
36 | 36 | import java.nio.file.LinkOption;
|
37 | 37 | import java.nio.file.Path;
|
38 | 38 | import java.nio.file.Paths;
|
39 | 39 | import java.nio.file.StandardCopyOption;
|
40 |
| -import java.util.List; |
41 |
| -import java.util.Map; |
42 | 40 |
|
43 | 41 | /**
|
44 | 42 | * A {@link fi.helsinki.cs.tmc.langs.LanguagePlugin} that defines the behaviour
|
@@ -211,37 +209,21 @@ protected TestRunFileAndLogs createRunResultFile(Path projectBasePath)
|
211 | 209 | resultFile,
|
212 | 210 | classPath,
|
213 | 211 | exercise.get());
|
214 |
| - List<String> testRunnerArguments = argumentBuilder.getArguments(); |
215 | 212 |
|
216 |
| - StringBuilder stdout = new StringBuilder(); |
217 |
| - StringBuilder stderr = new StringBuilder(); |
| 213 | + ProcessRunner runner = new ProcessRunner(argumentBuilder.getCommand(), projectBasePath); |
218 | 214 |
|
219 | 215 | try {
|
220 |
| - Process process = new ProcessBuilder(testRunnerArguments).start(); |
221 |
| - process.waitFor(); |
222 |
| - final BufferedReader output = |
223 |
| - new BufferedReader(new InputStreamReader(process.getInputStream())); |
224 |
| - final BufferedReader error = |
225 |
| - new BufferedReader(new InputStreamReader(process.getErrorStream())); |
226 |
| - |
227 |
| - String line; |
228 |
| - while ((line = output.readLine()) != null) { |
229 |
| - stdout.append(line); |
230 |
| - } |
231 |
| - while ((line = error.readLine()) != null) { |
232 |
| - stderr.append(line); |
233 |
| - } |
| 216 | + ProcessResult result = runner.call(); |
| 217 | + log.info("Successfully ran tests for project at {}", projectBasePath); |
| 218 | + return new TestRunFileAndLogs( |
| 219 | + resultFile.toFile(), |
| 220 | + result.output.getBytes(Charset.forName("UTF-8")), |
| 221 | + result.errorOutput.getBytes(Charset.forName("UTF-8")) |
| 222 | + ); |
234 | 223 | } catch (InterruptedException | IOException e) {
|
235 | 224 | log.error("Failed to run tests", e);
|
236 | 225 | throw new TestRunnerException(e);
|
237 | 226 | }
|
238 |
| - |
239 |
| - log.info("Successfully ran tests for project at {}", projectBasePath); |
240 |
| - |
241 |
| - return new TestRunFileAndLogs( |
242 |
| - resultFile.toFile(), |
243 |
| - stdout.toString().getBytes(Charset.forName("UTF-8")), |
244 |
| - stderr.toString().getBytes(Charset.forName("UTF-8"))); |
245 | 227 | }
|
246 | 228 |
|
247 | 229 | private String getJvmOptions(Path projectBasePath) {
|
|
0 commit comments