Skip to content

Commit 41aef22

Browse files
Ville Heikkinenpuny
authored andcommitted
Change ExerciseRunner to return Optional, when not present assumed a compilation error
1 parent e68600d commit 41aef22

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
package fi.helsinki.cs.tmc.runners;
22

3+
import com.google.common.base.Optional;
34
import fi.helsinki.cs.tmc.data.Exercise;
45
import fi.helsinki.cs.tmc.data.TestRunResult;
5-
<<<<<<< HEAD
6-
=======
7-
import fi.helsinki.cs.tmc.langs.TestResult;
8-
import fi.helsinki.cs.tmc.langs.util.TaskExecutor;
9-
import fi.helsinki.cs.tmc.langs.util.TaskExecutorImpl;
10-
>>>>>>> 7e632d9... Initial refactoring, ant testrunning reworked
116
import fi.helsinki.cs.tmc.model.TmcProjectInfo;
127
import fi.helsinki.cs.tmc.model.UserVisibleException;
138
import fi.helsinki.cs.tmc.testscanner.TestMethod;
@@ -23,7 +18,6 @@
2318
import java.util.concurrent.CancellationException;
2419
import java.util.concurrent.ExecutionException;
2520
import java.util.concurrent.Future;
26-
import java.util.concurrent.FutureTask;
2721
import java.util.logging.Level;
2822
import static java.util.logging.Level.INFO;
2923
import java.util.logging.Logger;
@@ -41,11 +35,10 @@ public class AntExerciseRunner extends AbstractJavaExerciseRunner {
4135
private static final Logger log = Logger.getLogger(AntExerciseRunner.class.getName());
4236

4337
@Override
44-
public Callable<TestRunResult> getTestRunningTask(final TmcProjectInfo projectInfo) {
45-
return new Callable<TestRunResult>() {
46-
38+
public Callable<Optional<TestRunResult>> getTestRunningTask(final TmcProjectInfo projectInfo) {
39+
return new Callable<Optional<TestRunResult>>() {
4740
@Override
48-
public TestRunResult call() throws Exception {
41+
public Optional<TestRunResult> call() throws Exception {
4942

5043
log.log(INFO,
5144
"Starting compile");
@@ -69,10 +62,10 @@ public TestRunResult call() throws Exception {
6962

7063
int compileResult = task.result();
7164
if (compileResult == 0) {
72-
log.log(INFO, "Compile resulted in 0");
73-
return runTests(projectInfo);
65+
log.log(INFO, "Compile success for project {0}", projectInfo.toString());
66+
return Optional.of(runTests(projectInfo));
7467
} else {
75-
return null;
68+
return Optional.absent();
7669
}
7770
}
7871
};
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
package fi.helsinki.cs.tmc.runners;
22

3+
import com.google.common.base.Optional;
34
import fi.helsinki.cs.tmc.data.TestRunResult;
45
import fi.helsinki.cs.tmc.model.TmcProjectInfo;
56
import java.util.concurrent.Callable;
67

8+
/**
9+
* ExerciseRunner for implementing runner tasks
10+
* Using Optional as a container for the result itself, if TestRunResult is not present
11+
* compilation failure should be assumed.
12+
*
13+
*/
714
public interface ExerciseRunner {
8-
public abstract Callable<TestRunResult> getTestRunningTask(TmcProjectInfo projectInfo);
15+
public abstract Callable<Optional<TestRunResult>> getTestRunningTask(TmcProjectInfo projectInfo);
916
}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package fi.helsinki.cs.tmc.runners;
22

3+
import com.google.common.base.Optional;
34
import fi.helsinki.cs.tmc.data.Exercise;
45
import fi.helsinki.cs.tmc.data.ResultCollector;
56
import fi.helsinki.cs.tmc.data.TestRunResult;
@@ -33,12 +34,12 @@ public InvokedEvent(TmcProjectInfo projectInfo) {
3334
}
3435
}
3536

36-
private ProjectMediator projectMediator;
37-
private ConvenientDialogDisplayer dialogDisplayer;
38-
private TmcEventBus eventBus;
39-
private TestResultDisplayer resultDisplayer;
40-
private ExerciseSubmitter exerciseSubmitter;
41-
private CourseDb courseDb;
37+
private final ProjectMediator projectMediator;
38+
private final ConvenientDialogDisplayer dialogDisplayer;
39+
private final TmcEventBus eventBus;
40+
private final TestResultDisplayer resultDisplayer;
41+
private final ExerciseSubmitter exerciseSubmitter;
42+
private final CourseDb courseDb;
4243

4344
public TestRunHandler() {
4445
this.projectMediator = ProjectMediator.getInstance();
@@ -55,17 +56,16 @@ public void performAction(final ResultCollector resultCollector, Project... proj
5556
final TmcProjectInfo projectInfo = projectMediator.wrapProject(project);
5657
eventBus.post(new InvokedEvent(projectInfo));
5758
final ExerciseRunner runner = getRunner(projectInfo);
58-
BgTask.start("Running tests", runner.getTestRunningTask(projectInfo), new BgTaskListener<TestRunResult>() {
59+
BgTask.start("Running tests", runner.getTestRunningTask(projectInfo), new BgTaskListener<Optional<TestRunResult>>() {
5960
@Override
60-
public void bgTaskReady(TestRunResult result) {
61-
if (result == null) {
61+
public void bgTaskReady(Optional<TestRunResult> result) {
62+
if (!result.isPresent()) {
6263
dialogDisplayer.displayError("The code did not compile.");
6364
return;
64-
6565
}
6666
Exercise ex = projectMediator.tryGetExerciseForProject(projectInfo, courseDb);
6767
boolean canSubmit = ex.isReturnable();
68-
resultDisplayer.showLocalRunResult(result.getTestCaseResults(), canSubmit, new Runnable() {
68+
resultDisplayer.showLocalRunResult(result.get().getTestCaseResults(), canSubmit, new Runnable() {
6969
@Override
7070
public void run() {
7171
exerciseSubmitter.performAction(projectInfo.getProject());
@@ -75,7 +75,7 @@ public void run() {
7575

7676
@Override
7777
public void bgTaskFailed(Throwable ex) {
78-
log.log(INFO, "performAction failed message: {0}, trace: {1}",
78+
log.log(INFO, "performAction of TestRunHandler failed with message: {0}, trace: {1}",
7979
new Object[]{ex.getMessage(), Arrays.deepToString(ex.getStackTrace())});
8080
dialogDisplayer.displayError("Failed to run the tests: " + ex.getMessage());
8181
}

0 commit comments

Comments
 (0)