Skip to content

Commit d38e426

Browse files
committed
RunTests
1 parent 6751d9e commit d38e426

File tree

4 files changed

+217
-73
lines changed

4 files changed

+217
-73
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>
@@ -343,6 +354,7 @@
343354
<publicPackage>fi.helsinki.cs.tmc.testrunner.*</publicPackage>
344355
<publicPackage>fi.helsinki.cs.tmc.testscanner.*</publicPackage>
345356
<publicPackage>hy.tmc.core.*</publicPackage>
357+
<publicPackage>fi.helsinki.cs.tmc.langs.*</publicPackage>
346358
<publicPackage>org.cometd.*</publicPackage>
347359
<publicPackage>org.eclipse.jetty.*</publicPackage>
348360
<publicPackage>org.slf4j.*</publicPackage>
Lines changed: 76 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,112 @@
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

27-
public void performAction(final ResultCollector resultCollector, final Project project) {
28-
29-
this.project = project;
28+
/*public void performAction(final ResultCollector resultCollector, final Project project) {
3029
31-
BgTask.start("Running validations", this, new BgTaskListener<Object>() {
30+
this.project = project;
3231
33-
@Override
34-
public void bgTaskFailed(final Throwable exception) {
32+
BgTask.start("Running validations", this, new BgTaskListener<Object>() {
3533
36-
dialogDisplayer.displayError("Failed to validate the code.");
37-
}
34+
@Override
35+
public void bgTaskFailed(final Throwable exception) {
3836
39-
@Override
40-
public void bgTaskCancelled() {}
37+
dialogDisplayer.displayError("Failed to validate the code.");
38+
}
4139
42-
@Override
43-
public void bgTaskReady(final Object nothing) {
44-
45-
resultCollector.setValidationResult(validationResult);
46-
}
47-
});
48-
}
40+
@Override
41+
public void bgTaskCancelled() {}
4942
50-
@Override
51-
public void run() {
43+
@Override
44+
public void bgTaskReady(final Object nothing) {
5245
46+
resultCollector.setValidationResult(validationResult);
47+
}
48+
});
49+
}*/
50+
public void performAction(final ResultCollector resultCollector, final Project project) {
51+
this.project = project;
5352
final TmcProjectInfo projectInfo = ProjectMediator.getInstance().wrapProject(project);
5453
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
6154
ProjectMediator.getInstance().saveAllFiles();
6255

6356
try {
64-
65-
final Locale locale = NBTmcSettings.getDefault().getErrorMsgLocale();
66-
validationResult = new CheckstyleRunner(projectInfo.getProjectDirAsFile(), locale).run();
67-
68-
} catch (TMCCheckstyleException exception) {
57+
ListenableFuture<ValidationResult> result = TmcCoreSingleton.getInstance().runCheckstyle(projectInfo.getProjectDirAsFile().getAbsolutePath(), NBTmcSettings.getDefault());
58+
Futures.addCallback(result, new FutureCallback<ValidationResult>() {
59+
60+
@Override
61+
public void onSuccess(final ValidationResult v) {
62+
SwingUtilities.invokeLater(new Runnable() {
63+
@Override
64+
public void run() {
65+
resultCollector.setValidationResult(v);
66+
}
67+
});
68+
}
69+
70+
@Override
71+
public void onFailure(Throwable thrwbl) {
72+
SwingUtilities.invokeLater(new Runnable() {
73+
@Override
74+
public void run() {
75+
dialogDisplayer.displayError("Failed to validate the code.");
76+
}
77+
});
78+
}
79+
80+
});
81+
82+
} catch (TmcCoreException ex) {
6983
ConvenientDialogDisplayer.getDefault().displayError("Checkstyle audit failed.");
70-
Exceptions.printStackTrace(exception);
84+
Exceptions.printStackTrace(ex);
7185
}
86+
7287
}
88+
89+
/*@Override
90+
public void run() {
91+
92+
final TmcProjectInfo projectInfo = ProjectMediator.getInstance().wrapProject(project);
93+
final String projectType = projectInfo.getProjectType().name();
94+
95+
if (!projectType.equals("JAVA_SIMPLE") && !projectType.equals("JAVA_MAVEN")) {
96+
return;
97+
}
98+
99+
// Save all files
100+
ProjectMediator.getInstance().saveAllFiles();
101+
102+
try {
103+
104+
final Locale locale = NBTmcSettings.getDefault().getErrorMsgLocale();
105+
validationResult = new CheckstyleRunner(projectInfo.getProjectDirAsFile(), locale).run();
106+
107+
} catch (TMCCheckstyleException exception) {
108+
ConvenientDialogDisplayer.getDefault().displayError("Checkstyle audit failed.");
109+
Exceptions.printStackTrace(exception);
110+
}
111+
}*/
73112
}

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

Lines changed: 127 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) {
@@ -51,53 +67,128 @@ public TestRunHandler() {
5167
this.courseDb = CourseDb.getInstance();
5268
}
5369

70+
/*public void performAction(final ResultCollector resultCollector, Project... projects) {
71+
projectMediator.saveAllFiles();
72+
for (final Project project : projects) {
73+
final TmcProjectInfo projectInfo = projectMediator.wrapProject(project);
74+
eventBus.post(new InvokedEvent(projectInfo));
75+
final ExerciseRunner runner = getRunner(projectInfo);
76+
BgTask.start("Running tests", runner.getTestRunningTask(projectInfo), new BgTaskListener<TestRunResult>() {
77+
@Override
78+
public void bgTaskReady(TestRunResult result) {
79+
if (!result.getCompilationSuccess()) {
80+
dialogDisplayer.displayError("The code did not compile.");
81+
return;
82+
}
83+
Exercise ex = projectMediator.tryGetExerciseForProject(projectInfo, courseDb);
84+
boolean canSubmit = ex.isReturnable();
85+
resultDisplayer.showLocalRunResult(result.getTestCaseResults(), canSubmit, new Runnable() {
86+
@Override
87+
public void run() {
88+
exerciseSubmitter.performAction(projectInfo.getProject());
89+
}
90+
}, resultCollector);
91+
}
92+
93+
@Override
94+
public void bgTaskFailed(Throwable ex) {
95+
log.log(INFO, "performAction of TestRunHandler failed with message: {0}, \ntrace: {1}",
96+
new Object[]{ex.getMessage(), Throwables.getStackTraceAsString(ex)});
97+
dialogDisplayer.displayError("Failed to run the tests: " + ex.getMessage());
98+
}
99+
100+
@Override
101+
public void bgTaskCancelled() {
102+
}
103+
});
104+
}
105+
}*/
54106
public void performAction(final ResultCollector resultCollector, Project... projects) {
55107
projectMediator.saveAllFiles();
56108
for (final Project project : projects) {
109+
System.out.println("Uusi Projekti");
57110
final TmcProjectInfo projectInfo = projectMediator.wrapProject(project);
58111
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;
112+
try {
113+
ListenableFuture<RunResult> result = TmcCoreSingleton.getInstance().test(projectInfo.getProjectDirAbsPath(), NBTmcSettings.getDefault());
114+
Futures.addCallback(result, new FutureCallback<RunResult>() {
115+
@Override
116+
public void onSuccess(final RunResult result) {
117+
System.out.println("RunResult onnistui");
118+
explainResults(result, projectInfo, resultCollector);
66119
}
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-
}
76120

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-
}
121+
@Override
122+
public void onFailure(final Throwable ex) {
123+
explainFailure(ex);
124+
}
125+
126+
});
127+
} catch (TmcCoreException ex) {
128+
Exceptions.printStackTrace(ex);
129+
}
83130

84-
@Override
85-
public void bgTaskCancelled() {
86-
}
87-
});
88131
}
132+
89133
}
90134

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());
135+
private void explainFailure(final Throwable ex) {
136+
System.out.println("Explain failuressa");
137+
SwingUtilities.invokeLater(new Runnable() {
138+
@Override
139+
public void run() {
140+
log.log(INFO, "performAction of TestRunHandler failed with message: {0}, \ntrace: {1}",
141+
new Object[]{ex.getMessage(), Throwables.getStackTraceAsString(ex)});
142+
dialogDisplayer.displayError("Failed to run the tests: " + ex.getMessage());
143+
}
144+
145+
});
146+
}
147+
148+
private void explainResults(final RunResult result, final TmcProjectInfo projectInfo, final ResultCollector resultCollector) {
149+
System.out.println("Explain resultissa");
150+
/*SwingUtilities.invokeLater(new Runnable() {
151+
152+
@Override
153+
public void run() {*/
154+
if (result.status == COMPILE_FAILED) {
155+
dialogDisplayer.displayError("The code did not compile.");
156+
return;
157+
}
158+
Exercise ex = projectMediator.tryGetExerciseForProject(projectInfo, courseDb);
159+
boolean canSubmit = ex.isReturnable();
160+
List<TestCaseResult> list = testResultsToTestCaseResults(result.testResults);
161+
resultDisplayer.showLocalRunResult(list, canSubmit, new Runnable() {
162+
@Override
163+
public void run() {
164+
exerciseSubmitter.performAction(projectInfo.getProject());
165+
}
166+
}, resultCollector);
167+
/*
168+
}
169+
170+
});*/
171+
}
172+
173+
private List<TestCaseResult> testResultsToTestCaseResults(ImmutableList<TestResult> testresults) {
174+
List<TestCaseResult> testCaseResults = new ArrayList<TestCaseResult>();
175+
for (TestResult result : testresults) {
176+
TestCaseResult testCase = new TestCaseResult(result.name, result.passed, result.errorMessage);
177+
testCaseResults.add(testCase);
101178
}
179+
return testCaseResults;
102180
}
181+
182+
/*private AbstractExerciseRunner getRunner(TmcProjectInfo projectInfo) {
183+
switch (projectInfo.getProjectType()) {
184+
case JAVA_MAVEN:
185+
return new MavenExerciseRunner();
186+
case JAVA_SIMPLE:
187+
return new AntExerciseRunner();
188+
case MAKEFILE:
189+
return new MakefileExerciseRunner();
190+
default:
191+
throw new IllegalArgumentException("Unknown project type: " + projectInfo.getProjectType());
192+
}
193+
}*/
103194
}

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)