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 ;
14
14
import java .util .List ;
15
15
import java .util .Map ;
16
16
import java .util .concurrent .Callable ;
17
- import java.util.logging.Level;
17
+ import static java .util .logging .Level .INFO ;
18
+ import java .util .logging .Logger ;
18
19
import org .apache .commons .lang3 .StringUtils ;
19
20
import org .openide .windows .IOProvider ;
20
21
import org .openide .windows .InputOutput ;
21
22
22
23
public class MavenExerciseRunner extends AbstractJavaExerciseRunner {
24
+
23
25
private static final String MAVEN_TEST_RUN_GOAL = "fi.helsinki.cs.tmc:tmc-maven-plugin:1.6:test" ;
26
+ private static final Logger log = Logger .getLogger (MavenExerciseRunner .class .getName ());
24
27
25
28
@ Override
26
- public Callable<Integer> getCompilingTask(TmcProjectInfo projectInfo) {
27
- File projectDir = projectInfo.getProjectDirAsFile();
28
-
29
- String goal = "test-compile";
30
- final InputOutput inOut = IOProvider.getDefault().getIO(projectInfo.getProjectName(), false);
31
-
32
- final ProcessRunner runner = new MavenRunBuilder()
33
- .setProjectDir(projectDir)
34
- .addGoal(goal)
35
- .setIO(inOut)
36
- .createProcessRunner();
37
-
38
- return new Callable<Integer>() {
29
+ public Callable <Optional <TestRunResult >> getTestRunningTask (final TmcProjectInfo projectInfo ) {
30
+ return new Callable <Optional <TestRunResult >>() {
39
31
@ Override
40
- public Integer call() throws Exception {
32
+ public Optional <TestRunResult > call () throws Exception {
33
+ File projectDir = projectInfo .getProjectDirAsFile ();
34
+ log .log (INFO , "Starting compile" );
35
+ String goal = "test-compile" ;
36
+ final InputOutput inOut = IOProvider .getDefault ().getIO (projectInfo .getProjectName (), false );
37
+
38
+ final ProcessRunner runner = new MavenRunBuilder ()
39
+ .setProjectDir (projectDir )
40
+ .addGoal (goal )
41
+ .setIO (inOut )
42
+ .createProcessRunner ();
41
43
try {
42
44
ProcessResult result = runner .call ();
43
45
int ret = result .statusCode ;
44
46
if (ret != 0 ) {
45
47
inOut .select ();
48
+ log .log (INFO , "Compile resulted in non-zero exit code {0}" , result .statusCode );
49
+ return Optional .absent ();
50
+ } else {
51
+ log .log (INFO , "Running tests" );
52
+ return Optional .of (runTests (projectInfo ));
46
53
}
47
- return ret;
48
54
} catch (Exception ex ) {
49
55
inOut .select ();
50
56
throw ex ;
51
57
}
52
58
}
59
+
53
60
};
54
61
}
55
62
56
- @Override
57
- public Callable<TestRunResult> getTestRunningTask(final TmcProjectInfo projectInfo) {
63
+ public TestRunResult runTests (final TmcProjectInfo projectInfo ) throws Exception {
58
64
final File projectDir = projectInfo .getProjectDirAsFile ();
59
65
String goal = MAVEN_TEST_RUN_GOAL ;
60
66
Map <String , String > props = new HashMap <String , String >();
@@ -83,17 +89,11 @@ public Callable<TestRunResult> getTestRunningTask(final TmcProjectInfo projectIn
83
89
.setIO (inOut )
84
90
.createProcessRunner ();
85
91
86
- return new Callable<TestRunResult>() {
87
- @Override
88
- public TestRunResult call() throws Exception {
89
- runner.call();
90
- File resultsFile = new File(
91
- projectDir.getPath() + File.separator
92
- + "target" + File.separator
93
- + "test_output.txt");
94
- return resultParser.parseTestResults(resultsFile);
95
- }
96
- };
92
+ runner .call ();
93
+ File resultsFile = new File (
94
+ projectDir .getPath () + File .separator
95
+ + "target" + File .separator
96
+ + "test_output.txt" );
97
+ return resultParser .parseTestResults (resultsFile );
97
98
}
98
99
}
99
- */
0 commit comments