1
- /**
2
- * package fi.helsinki.cs.tmc.runners;
1
+ package fi .helsinki .cs .tmc .runners ;
3
2
3
+ import com .google .common .base .Optional ;
4
4
import fi .helsinki .cs .tmc .data .Exercise ;
5
5
import fi .helsinki .cs .tmc .data .TestRunResult ;
6
6
import fi .helsinki .cs .tmc .model .TmcProjectInfo ;
25
25
public class MakefileExerciseRunner extends AbstractExerciseRunner {
26
26
27
27
private static final Logger log = Logger .getLogger (MakefileExerciseRunner .class .getName ());
28
-
28
+
29
29
@ Override
30
- public Callable<Integer> getCompilingTask(TmcProjectInfo projectInfo) {
31
- log.log(Level.INFO, "Compiling project {0}", projectInfo.getProjectName());
32
- Project project = projectInfo.getProject();
33
- FileObject makeFile = project.getProjectDirectory().getFileObject("Makefile");
34
- File workDir = projectInfo.getProjectDirAsFile();
35
-
36
- if (makeFile == null) {
37
- log.log(INFO, "Project has no Makefile");
38
- throw new RuntimeException("Project has no Makefile");
39
- }
40
- String[] command = {"make", "test"};
30
+ public Callable <Optional <TestRunResult >> getTestRunningTask (final TmcProjectInfo projectInfo ) {
31
+ return new Callable <Optional <TestRunResult >>() {
41
32
42
- final InputOutput io = IOProvider.getDefault().getIO(projectInfo.getProjectName(), false);
43
- final ProcessRunner runner = new ProcessRunner(command, workDir, io);
44
- return new Callable<Integer>() {
45
33
@ Override
46
- public Integer call() throws Exception {
34
+ public Optional <TestRunResult > call () throws Exception {
35
+ log .log (Level .INFO , "Compiling project {0}" , projectInfo .getProjectName ());
36
+ Project project = projectInfo .getProject ();
37
+ FileObject makeFile = project .getProjectDirectory ().getFileObject ("Makefile" );
38
+
39
+ if (makeFile == null ) {
40
+ log .log (INFO , "Project has no Makefile" );
41
+ return Optional .absent ();
42
+ }
43
+
44
+ File workDir = projectInfo .getProjectDirAsFile ();
45
+ String [] command = {"make" , "test" };
46
+
47
+ final InputOutput io = IOProvider .getDefault ().getIO (projectInfo .getProjectName (), false );
48
+ final ProcessRunner runner = new ProcessRunner (command , workDir , io );
49
+
47
50
try {
48
51
ProcessResult result = runner .call ();
49
52
int ret = result .statusCode ;
50
53
if (ret != 0 ) {
51
54
io .select ();
55
+ log .log (INFO , "Compile resulted in non-zero exit code {0}" , result .statusCode );
56
+ return Optional .absent ();
52
57
}
53
- return ret;
58
+
59
+ log .log (INFO , "Running tests" );
60
+ return Optional .of (runTests (projectInfo , true ));
54
61
} catch (Exception ex ) {
55
- log.log(INFO, "Compilation failed, {0}", ex.getMessage());
56
62
io .select ();
57
63
throw ex ;
58
64
}
59
65
}
60
66
};
61
67
}
62
-
63
- @Override
64
- public Callable<TestRunResult> getTestRunningTask(final TmcProjectInfo projectInfo) {
65
- return new Callable<TestRunResult>() {
66
- @Override
67
- public TestRunResult call() throws Exception {
68
- return runTests(projectInfo, true);
69
- }
70
- };
71
- }
72
-
68
+
73
69
// TODO: use make
74
70
private TestRunResult runTests (final TmcProjectInfo projectInfo , final boolean withValgrind ) throws Exception {
75
71
log .log (INFO , "Running tests {0}" , projectInfo .getProjectName ());
@@ -119,6 +115,4 @@ private TestRunResult runTests(final TmcProjectInfo projectInfo, final boolean w
119
115
return resultParser .parseCTestResults (resultsFile , valgrindLog , null );
120
116
}
121
117
}
122
- }
123
-
124
- */
118
+ }
0 commit comments