|
2 | 2 |
|
3 | 3 | import fi.helsinki.cs.tmc.data.Exercise;
|
4 | 4 | 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 |
5 | 11 | import fi.helsinki.cs.tmc.model.TmcProjectInfo;
|
6 | 12 | import fi.helsinki.cs.tmc.model.UserVisibleException;
|
7 | 13 | import fi.helsinki.cs.tmc.testscanner.TestMethod;
|
|
17 | 23 | import java.util.concurrent.CancellationException;
|
18 | 24 | import java.util.concurrent.ExecutionException;
|
19 | 25 | import java.util.concurrent.Future;
|
| 26 | +import java.util.concurrent.FutureTask; |
20 | 27 | import java.util.logging.Level;
|
| 28 | +import static java.util.logging.Level.INFO; |
21 | 29 | import java.util.logging.Logger;
|
22 | 30 | import org.apache.tools.ant.module.api.support.ActionUtils;
|
23 | 31 | import org.netbeans.api.java.classpath.ClassPath;
|
24 | 32 | import org.netbeans.api.project.Project;
|
25 | 33 | import org.openide.execution.ExecutorTask;
|
26 | 34 | import org.openide.filesystems.FileObject;
|
27 | 35 | import org.openide.filesystems.FileUtil;
|
| 36 | +import org.openide.util.Exceptions; |
28 | 37 | import org.openide.windows.InputOutput;
|
29 | 38 |
|
30 | 39 | public class AntExerciseRunner extends AbstractJavaExerciseRunner {
|
31 |
| - private static final Logger log = Logger.getLogger(AntExerciseRunner.class.getName()); |
32 | 40 |
|
33 |
| - @Override |
34 |
| - public Callable<Integer> getCompilingTask(TmcProjectInfo projectInfo) { |
35 |
| - Project project = projectInfo.getProject(); |
36 |
| - FileObject buildScript = project.getProjectDirectory().getFileObject("build.xml"); |
37 |
| - if (buildScript == null) { |
38 |
| - throw new RuntimeException("Project has no build.xml"); |
39 |
| - } |
40 |
| - ExecutorTask task; |
41 |
| - try { |
42 |
| - task = ActionUtils.runTarget(buildScript, new String[]{"compile-test"}, null); |
43 |
| - return executorTaskToCallable(task); |
44 |
| - } catch (IOException ex) { |
45 |
| - throw ExceptionUtils.toRuntimeException(ex); |
46 |
| - } |
47 |
| - } |
| 41 | + private static final Logger log = Logger.getLogger(AntExerciseRunner.class.getName()); |
48 | 42 |
|
49 | 43 | @Override
|
50 | 44 | public Callable<TestRunResult> getTestRunningTask(final TmcProjectInfo projectInfo) {
|
51 | 45 | return new Callable<TestRunResult>() {
|
| 46 | + |
52 | 47 | @Override
|
53 |
| - public TestRunResult call() throws UserVisibleException, IOException, InterruptedException, ExecutionException { |
54 |
| - FileObject testDir = findTestDir(projectInfo); |
55 |
| - if (testDir == null) { |
56 |
| - throw new UserVisibleException("No test directory in project"); |
57 |
| - } |
| 48 | + public TestRunResult call() throws Exception { |
58 | 49 |
|
59 |
| - List<TestMethod> tests = findProjectTests(projectInfo, testDir); |
| 50 | + log.log(INFO, |
| 51 | + "Starting compile"); |
| 52 | + |
| 53 | + Project project = projectInfo.getProject(); |
| 54 | + FileObject buildScript = project.getProjectDirectory().getFileObject("build.xml"); |
| 55 | + if (buildScript == null) { |
| 56 | + throw new RuntimeException("Project has no build.xml"); |
| 57 | + } |
| 58 | + ExecutorTask task; |
60 | 59 |
|
61 |
| - File tempFile; |
62 |
| - tempFile = File.createTempFile("tmc_test_results", ".txt"); |
63 | 60 | try {
|
64 |
| - return runTests(projectInfo, testDir, tests, tempFile); |
65 |
| - } finally { |
66 |
| - tempFile.delete(); |
| 61 | + task = ActionUtils.runTarget(buildScript, new String[]{"compile-test"}, null); |
| 62 | + } catch (IOException ex) { |
| 63 | + Exceptions.printStackTrace(ex); |
| 64 | + throw ExceptionUtils.toRuntimeException(ex); |
| 65 | + } catch (IllegalArgumentException ex) { |
| 66 | + Exceptions.printStackTrace(ex); |
| 67 | + throw ExceptionUtils.toRuntimeException(ex); |
| 68 | + } |
| 69 | + |
| 70 | + int compileResult = task.result(); |
| 71 | + if (compileResult == 0) { |
| 72 | + log.log(INFO, "Compile resulted in 0"); |
| 73 | + return runTests(projectInfo); |
| 74 | + } else { |
| 75 | + return null; |
67 | 76 | }
|
68 | 77 | }
|
69 | 78 | };
|
70 | 79 | }
|
71 | 80 |
|
| 81 | + protected TestRunResult runTests(final TmcProjectInfo projectInfo) throws UserVisibleException, IOException, InterruptedException, ExecutionException { |
| 82 | + |
| 83 | + FileObject testDir = findTestDir(projectInfo); |
| 84 | + if (testDir == null) { |
| 85 | + throw new UserVisibleException("No test directory in project"); |
| 86 | + } |
| 87 | + |
| 88 | + List<TestMethod> tests = findProjectTests(projectInfo, testDir); |
| 89 | + |
| 90 | + File tempFile; |
| 91 | + tempFile = File.createTempFile("tmc_test_results", ".txt"); |
| 92 | + try { |
| 93 | + return runTests(projectInfo, testDir, tests, tempFile); |
| 94 | + } finally { |
| 95 | + tempFile.delete(); |
| 96 | + } |
| 97 | + } |
| 98 | + |
72 | 99 | private TestRunResult runTests(final TmcProjectInfo projectInfo, FileObject testDir, List<TestMethod> testMethods, File tempFile) throws UserVisibleException {
|
73 | 100 | try {
|
74 | 101 | ArrayList<String> args = new ArrayList<String>();
|
|
0 commit comments