Skip to content

Commit fa6652f

Browse files
committed
Merge branch 'core_integration' of github.com:rage/tmc-netbeans into listCourses
2 parents 264c301 + 0533b6c commit fa6652f

File tree

4 files changed

+124
-74
lines changed

4 files changed

+124
-74
lines changed

maven-wrapper/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@
4040
<enabled>true</enabled>
4141
</snapshots>
4242
</repository>
43+
<repository>
44+
<releases>
45+
<enabled>true</enabled>
46+
<updatePolicy>always</updatePolicy>
47+
<checksumPolicy>fail</checksumPolicy>
48+
</releases>
49+
<id>org</id>
50+
<name>tmccli</name>
51+
<url>http://tmc-cli.jvn.lu/maven2/</url>
52+
<layout>default</layout>
53+
</repository>
4354
</repositories>
4455

4556
<dependencies>
@@ -342,6 +353,7 @@
342353
<publicPackage>fi.helsinki.cs.tmc.testrunner.*</publicPackage>
343354
<publicPackage>fi.helsinki.cs.tmc.testscanner.*</publicPackage>
344355
<publicPackage>hy.tmc.core.*</publicPackage>
356+
<publicPackage>fi.helsinki.cs.tmc.langs.*</publicPackage>
345357
<publicPackage>org.cometd.*</publicPackage>
346358
<publicPackage>org.eclipse.jetty.*</publicPackage>
347359
<publicPackage>org.slf4j.*</publicPackage>
Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,76 @@
11
package fi.helsinki.cs.tmc.runners;
22

3+
import com.google.common.util.concurrent.FutureCallback;
4+
import com.google.common.util.concurrent.Futures;
5+
import com.google.common.util.concurrent.ListenableFuture;
36
import fi.helsinki.cs.tmc.data.ResultCollector;
47
import fi.helsinki.cs.tmc.model.ProjectMediator;
58
import fi.helsinki.cs.tmc.model.TmcProjectInfo;
69
import fi.helsinki.cs.tmc.model.NBTmcSettings;
7-
import fi.helsinki.cs.tmc.stylerunner.CheckstyleRunner;
8-
import fi.helsinki.cs.tmc.stylerunner.exception.TMCCheckstyleException;
10+
import fi.helsinki.cs.tmc.model.TmcCoreSingleton;
911
import fi.helsinki.cs.tmc.stylerunner.validation.CheckstyleResult;
1012
import fi.helsinki.cs.tmc.stylerunner.validation.ValidationResult;
1113
import fi.helsinki.cs.tmc.ui.ConvenientDialogDisplayer;
12-
import fi.helsinki.cs.tmc.utilities.BgTask;
13-
import fi.helsinki.cs.tmc.utilities.BgTaskListener;
14+
import hy.tmc.core.exceptions.TmcCoreException;
1415

15-
import java.util.Locale;
16+
import javax.swing.SwingUtilities;
1617

1718
import org.netbeans.api.project.Project;
1819

1920
import org.openide.util.Exceptions;
2021

21-
public final class CheckstyleRunHandler implements Runnable {
22+
public final class CheckstyleRunHandler {
2223

2324
private Project project;
2425
private final ConvenientDialogDisplayer dialogDisplayer = ConvenientDialogDisplayer.getDefault();
2526
private ValidationResult validationResult = new CheckstyleResult();
2627

2728
public void performAction(final ResultCollector resultCollector, final Project project) {
28-
2929
this.project = project;
30+
final TmcProjectInfo projectInfo = ProjectMediator.getInstance().wrapProject(project);
31+
final String projectType = projectInfo.getProjectType().name();
32+
ProjectMediator.getInstance().saveAllFiles();
3033

31-
BgTask.start("Running validations", this, new BgTaskListener<Object>() {
34+
try {
35+
ListenableFuture<ValidationResult> result = TmcCoreSingleton.getInstance().runCheckstyle(projectInfo.getProjectDirAsFile().getAbsolutePath(), NBTmcSettings.getDefault());
36+
Futures.addCallback(result, new ExplainValidationResult(resultCollector, dialogDisplayer));
3237

33-
@Override
34-
public void bgTaskFailed(final Throwable exception) {
38+
} catch (TmcCoreException ex) {
39+
ConvenientDialogDisplayer.getDefault().displayError("Checkstyle audit failed.");
40+
Exceptions.printStackTrace(ex);
41+
}
3542

36-
dialogDisplayer.displayError("Failed to validate the code.");
37-
}
43+
}
3844

39-
@Override
40-
public void bgTaskCancelled() {}
45+
}
4146

42-
@Override
43-
public void bgTaskReady(final Object nothing) {
47+
class ExplainValidationResult implements FutureCallback<ValidationResult> {
4448

45-
resultCollector.setValidationResult(validationResult);
49+
ResultCollector resultCollector;
50+
ConvenientDialogDisplayer dialogDisplayer;
51+
52+
public ExplainValidationResult(ResultCollector resultCollector, ConvenientDialogDisplayer dialogDisplayer) {
53+
this.resultCollector = resultCollector;
54+
this.dialogDisplayer = dialogDisplayer;
55+
}
56+
57+
@Override
58+
public void onSuccess(final ValidationResult v) {
59+
SwingUtilities.invokeLater(new Runnable() {
60+
@Override
61+
public void run() {
62+
resultCollector.setValidationResult(v);
4663
}
4764
});
4865
}
4966

5067
@Override
51-
public void run() {
52-
53-
final TmcProjectInfo projectInfo = ProjectMediator.getInstance().wrapProject(project);
54-
final String projectType = projectInfo.getProjectType().name();
55-
56-
if (!projectType.equals("JAVA_SIMPLE") && !projectType.equals("JAVA_MAVEN")) {
57-
return;
58-
}
59-
60-
// Save all files
61-
ProjectMediator.getInstance().saveAllFiles();
62-
63-
try {
64-
65-
final Locale locale = NBTmcSettings.getDefault().getErrorMsgLocale();
66-
validationResult = new CheckstyleRunner(projectInfo.getProjectDirAsFile(), locale).run();
67-
68-
} catch (TMCCheckstyleException exception) {
69-
ConvenientDialogDisplayer.getDefault().displayError("Checkstyle audit failed.");
70-
Exceptions.printStackTrace(exception);
71-
}
68+
public void onFailure(Throwable thrwbl) {
69+
SwingUtilities.invokeLater(new Runnable() {
70+
@Override
71+
public void run() {
72+
dialogDisplayer.displayError("Failed to validate the code.");
73+
}
74+
});
7275
}
7376
}

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

Lines changed: 69 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@
22

33
import com.google.common.base.Optional;
44
import com.google.common.base.Throwables;
5+
import com.google.common.collect.ImmutableList;
6+
import com.google.common.util.concurrent.FutureCallback;
7+
import com.google.common.util.concurrent.Futures;
8+
import com.google.common.util.concurrent.ListenableFuture;
59
import hy.tmc.core.domain.Exercise;
610
import fi.helsinki.cs.tmc.data.ResultCollector;
11+
import fi.helsinki.cs.tmc.data.TestCaseResult;
712
import fi.helsinki.cs.tmc.data.TestRunResult;
813
import fi.helsinki.cs.tmc.events.TmcEvent;
914
import fi.helsinki.cs.tmc.events.TmcEventBus;
1015
import fi.helsinki.cs.tmc.exerciseSubmitter.ExerciseSubmitter;
16+
import fi.helsinki.cs.tmc.langs.RunResult;
17+
import static fi.helsinki.cs.tmc.langs.RunResult.Status.COMPILE_FAILED;
18+
import fi.helsinki.cs.tmc.langs.TestResult;
1119
import fi.helsinki.cs.tmc.model.CourseDb;
20+
import fi.helsinki.cs.tmc.model.NBTmcSettings;
1221
import fi.helsinki.cs.tmc.model.ProjectMediator;
22+
import fi.helsinki.cs.tmc.model.TmcCoreSingleton;
1323
import fi.helsinki.cs.tmc.model.TmcProjectInfo;
1424
import static fi.helsinki.cs.tmc.model.TmcProjectType.JAVA_MAVEN;
1525
import static fi.helsinki.cs.tmc.model.TmcProjectType.JAVA_SIMPLE;
@@ -18,16 +28,22 @@
1828
import fi.helsinki.cs.tmc.ui.TestResultDisplayer;
1929
import fi.helsinki.cs.tmc.utilities.BgTask;
2030
import fi.helsinki.cs.tmc.utilities.BgTaskListener;
31+
import hy.tmc.core.exceptions.TmcCoreException;
32+
import java.util.ArrayList;
2133
import java.util.Arrays;
34+
import java.util.List;
2235
import static java.util.logging.Level.INFO;
2336
import java.util.logging.Logger;
37+
import javax.swing.SwingUtilities;
2438
import org.netbeans.api.project.Project;
39+
import org.openide.util.Exceptions;
2540

2641
public class TestRunHandler {
2742

2843
private static final Logger log = Logger.getLogger(TestRunHandler.class.getName());
2944

3045
public static class InvokedEvent implements TmcEvent {
46+
3147
public final TmcProjectInfo projectInfo;
3248

3349
public InvokedEvent(TmcProjectInfo projectInfo) {
@@ -56,48 +72,65 @@ public void performAction(final ResultCollector resultCollector, Project... proj
5672
for (final Project project : projects) {
5773
final TmcProjectInfo projectInfo = projectMediator.wrapProject(project);
5874
eventBus.post(new InvokedEvent(projectInfo));
59-
final ExerciseRunner runner = getRunner(projectInfo);
60-
BgTask.start("Running tests", runner.getTestRunningTask(projectInfo), new BgTaskListener<TestRunResult>() {
61-
@Override
62-
public void bgTaskReady(TestRunResult result) {
63-
if (!result.getCompilationSuccess()) {
64-
dialogDisplayer.displayError("The code did not compile.");
65-
return;
75+
try {
76+
ListenableFuture<RunResult> result = TmcCoreSingleton.getInstance().test(projectInfo.getProjectDirAbsPath(), NBTmcSettings.getDefault());
77+
Futures.addCallback(result, new FutureCallback<RunResult>() {
78+
@Override
79+
public void onSuccess(final RunResult result) {
80+
explainResults(result, projectInfo, resultCollector);
6681
}
67-
Exercise ex = projectMediator.tryGetExerciseForProject(projectInfo, courseDb);
68-
boolean canSubmit = ex.isReturnable();
69-
resultDisplayer.showLocalRunResult(result.getTestCaseResults(), canSubmit, new Runnable() {
70-
@Override
71-
public void run() {
72-
exerciseSubmitter.performAction(projectInfo.getProject());
73-
}
74-
}, resultCollector);
75-
}
7682

77-
@Override
78-
public void bgTaskFailed(Throwable ex) {
79-
log.log(INFO, "performAction of TestRunHandler failed with message: {0}, \ntrace: {1}",
80-
new Object[]{ex.getMessage(), Throwables.getStackTraceAsString(ex)});
81-
dialogDisplayer.displayError("Failed to run the tests: " + ex.getMessage());
82-
}
83+
@Override
84+
public void onFailure(final Throwable ex) {
85+
explainFailure(ex);
86+
}
8387

84-
@Override
85-
public void bgTaskCancelled() {
86-
}
87-
});
88+
});
89+
} catch (TmcCoreException ex) {
90+
Exceptions.printStackTrace(ex);
91+
}
8892
}
8993
}
9094

91-
private AbstractExerciseRunner getRunner(TmcProjectInfo projectInfo) {
92-
switch (projectInfo.getProjectType()) {
93-
case JAVA_MAVEN:
94-
return new MavenExerciseRunner();
95-
case JAVA_SIMPLE:
96-
return new AntExerciseRunner();
97-
case MAKEFILE:
98-
return new MakefileExerciseRunner();
99-
default:
100-
throw new IllegalArgumentException("Unknown project type: " + projectInfo.getProjectType());
95+
private void explainFailure(final Throwable ex) {
96+
SwingUtilities.invokeLater(new Runnable() {
97+
@Override
98+
public void run() {
99+
log.log(INFO, "performAction of TestRunHandler failed with message: {0}, \ntrace: {1}",
100+
new Object[]{ex.getMessage(), Throwables.getStackTraceAsString(ex)});
101+
dialogDisplayer.displayError("Failed to run the tests: " + ex.getMessage());
102+
}
103+
});
104+
}
105+
106+
private void explainResults(final RunResult result, final TmcProjectInfo projectInfo, final ResultCollector resultCollector) {
107+
SwingUtilities.invokeLater(new Runnable() {
108+
109+
@Override
110+
public void run() {
111+
if (result.status == COMPILE_FAILED) {
112+
dialogDisplayer.displayError("The code did not compile.");
113+
return;
114+
}
115+
Exercise ex = projectMediator.tryGetExerciseForProject(projectInfo, courseDb);
116+
boolean canSubmit = ex.isReturnable();
117+
List<TestCaseResult> list = testResultsToTestCaseResults(result.testResults);
118+
resultDisplayer.showLocalRunResult(list, canSubmit, new Runnable() {
119+
@Override
120+
public void run() {
121+
exerciseSubmitter.performAction(projectInfo.getProject());
122+
}
123+
}, resultCollector);
124+
}
125+
});
126+
}
127+
128+
private List<TestCaseResult> testResultsToTestCaseResults(ImmutableList<TestResult> testresults) {
129+
List<TestCaseResult> testCaseResults = new ArrayList<TestCaseResult>();
130+
for (TestResult result : testresults) {
131+
TestCaseResult testCase = new TestCaseResult(result.name, result.passed, result.errorMessage);
132+
testCaseResults.add(testCase);
101133
}
134+
return testCaseResults;
102135
}
103136
}

tmc-plugin/src/fi/helsinki/cs/tmc/ui/TestResultDisplayer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ public void showLocalRunResult(final List<TestCaseResult> results,
138138
final boolean returnable,
139139
final Runnable submissionCallback,
140140
final ResultCollector resultCollector) {
141+
142+
System.out.println("Näyttämässä lokaalia testitulosta");
141143

142144
resultCollector.setSubmissionCallback(submissionCallback);
143145

0 commit comments

Comments
 (0)