Skip to content

Commit dae3f74

Browse files
author
puny
committed
Refactored MakefileExerciseRunner
1 parent 97f4f07 commit dae3f74

File tree

2 files changed

+30
-35
lines changed

2 files changed

+30
-35
lines changed

tmc-plugin/src/fi/helsinki/cs/tmc/runners/MakefileExerciseRunner.java

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/**
2-
* package fi.helsinki.cs.tmc.runners;
1+
package fi.helsinki.cs.tmc.runners;
32

3+
import com.google.common.base.Optional;
44
import fi.helsinki.cs.tmc.data.Exercise;
55
import fi.helsinki.cs.tmc.data.TestRunResult;
66
import fi.helsinki.cs.tmc.model.TmcProjectInfo;
@@ -25,51 +25,47 @@
2525
public class MakefileExerciseRunner extends AbstractExerciseRunner {
2626

2727
private static final Logger log = Logger.getLogger(MakefileExerciseRunner.class.getName());
28-
28+
2929
@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>>() {
4132

42-
final InputOutput io = IOProvider.getDefault().getIO(projectInfo.getProjectName(), false);
43-
final ProcessRunner runner = new ProcessRunner(command, workDir, io);
44-
return new Callable<Integer>() {
4533
@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+
4750
try {
4851
ProcessResult result = runner.call();
4952
int ret = result.statusCode;
5053
if (ret != 0) {
5154
io.select();
55+
log.log(INFO, "Compile resulted in non-zero exit code {0}", result.statusCode);
56+
return Optional.absent();
5257
}
53-
return ret;
58+
59+
log.log(INFO, "Running tests");
60+
return Optional.of(runTests(projectInfo, true));
5461
} catch (Exception ex) {
55-
log.log(INFO, "Compilation failed, {0}", ex.getMessage());
5662
io.select();
5763
throw ex;
5864
}
5965
}
6066
};
6167
}
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+
7369
// TODO: use make
7470
private TestRunResult runTests(final TmcProjectInfo projectInfo, final boolean withValgrind) throws Exception {
7571
log.log(INFO, "Running tests {0}", projectInfo.getProjectName());
@@ -119,6 +115,4 @@ private TestRunResult runTests(final TmcProjectInfo projectInfo, final boolean w
119115
return resultParser.parseCTestResults(resultsFile, valgrindLog, null);
120116
}
121117
}
122-
}
123-
124-
*/
118+
}

tmc-plugin/src/fi/helsinki/cs/tmc/runners/TestRunHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ private AbstractExerciseRunner getRunner(TmcProjectInfo projectInfo) {
9696
log.log(INFO, "Ant task selected");
9797
return new AntExerciseRunner();
9898
case MAKEFILE:
99-
return null;
99+
log.log(INFO, "Makefile task selected");
100+
return new MakefileExerciseRunner();
100101
default:
101102
throw new IllegalArgumentException("Unknown project type: " + projectInfo.getProjectType());
102103
}

0 commit comments

Comments
 (0)