Skip to content

Commit 30fcf6d

Browse files
committed
RunTests & Checkstyle
1 parent d38e426 commit 30fcf6d

File tree

2 files changed

+32
-126
lines changed

2 files changed

+32
-126
lines changed

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

Lines changed: 28 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,6 @@ public final class CheckstyleRunHandler {
2525
private final ConvenientDialogDisplayer dialogDisplayer = ConvenientDialogDisplayer.getDefault();
2626
private ValidationResult validationResult = new CheckstyleResult();
2727

28-
/*public void performAction(final ResultCollector resultCollector, final Project project) {
29-
30-
this.project = project;
31-
32-
BgTask.start("Running validations", this, new BgTaskListener<Object>() {
33-
34-
@Override
35-
public void bgTaskFailed(final Throwable exception) {
36-
37-
dialogDisplayer.displayError("Failed to validate the code.");
38-
}
39-
40-
@Override
41-
public void bgTaskCancelled() {}
42-
43-
@Override
44-
public void bgTaskReady(final Object nothing) {
45-
46-
resultCollector.setValidationResult(validationResult);
47-
}
48-
});
49-
}*/
5028
public void performAction(final ResultCollector resultCollector, final Project project) {
5129
this.project = project;
5230
final TmcProjectInfo projectInfo = ProjectMediator.getInstance().wrapProject(project);
@@ -55,29 +33,7 @@ public void performAction(final ResultCollector resultCollector, final Project p
5533

5634
try {
5735
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-
});
36+
Futures.addCallback(result, new ExplainValidationResult(resultCollector, dialogDisplayer));
8137

8238
} catch (TmcCoreException ex) {
8339
ConvenientDialogDisplayer.getDefault().displayError("Checkstyle audit failed.");
@@ -86,27 +42,35 @@ public void run() {
8642

8743
}
8844

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-
}
45+
}
9846

99-
// Save all files
100-
ProjectMediator.getInstance().saveAllFiles();
47+
class ExplainValidationResult implements FutureCallback<ValidationResult> {
10148

102-
try {
49+
ResultCollector resultCollector;
50+
ConvenientDialogDisplayer dialogDisplayer;
51+
52+
public ExplainValidationResult(ResultCollector resultCollector, ConvenientDialogDisplayer dialogDisplayer) {
53+
this.resultCollector = resultCollector;
54+
this.dialogDisplayer = dialogDisplayer;
55+
}
10356

104-
final Locale locale = NBTmcSettings.getDefault().getErrorMsgLocale();
105-
validationResult = new CheckstyleRunner(projectInfo.getProjectDirAsFile(), locale).run();
57+
@Override
58+
public void onSuccess(final ValidationResult v) {
59+
SwingUtilities.invokeLater(new Runnable() {
60+
@Override
61+
public void run() {
62+
resultCollector.setValidationResult(v);
63+
}
64+
});
65+
}
10666

107-
} catch (TMCCheckstyleException exception) {
108-
ConvenientDialogDisplayer.getDefault().displayError("Checkstyle audit failed.");
109-
Exceptions.printStackTrace(exception);
110-
}
111-
}*/
67+
@Override
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+
});
75+
}
11276
}

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

Lines changed: 4 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -67,54 +67,16 @@ public TestRunHandler() {
6767
this.courseDb = CourseDb.getInstance();
6868
}
6969

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-
}*/
10670
public void performAction(final ResultCollector resultCollector, Project... projects) {
10771
projectMediator.saveAllFiles();
10872
for (final Project project : projects) {
109-
System.out.println("Uusi Projekti");
11073
final TmcProjectInfo projectInfo = projectMediator.wrapProject(project);
11174
eventBus.post(new InvokedEvent(projectInfo));
11275
try {
11376
ListenableFuture<RunResult> result = TmcCoreSingleton.getInstance().test(projectInfo.getProjectDirAbsPath(), NBTmcSettings.getDefault());
11477
Futures.addCallback(result, new FutureCallback<RunResult>() {
11578
@Override
11679
public void onSuccess(final RunResult result) {
117-
System.out.println("RunResult onnistui");
11880
explainResults(result, projectInfo, resultCollector);
11981
}
12082

@@ -127,30 +89,25 @@ public void onFailure(final Throwable ex) {
12789
} catch (TmcCoreException ex) {
12890
Exceptions.printStackTrace(ex);
12991
}
130-
13192
}
132-
13393
}
13494

13595
private void explainFailure(final Throwable ex) {
136-
System.out.println("Explain failuressa");
13796
SwingUtilities.invokeLater(new Runnable() {
13897
@Override
13998
public void run() {
14099
log.log(INFO, "performAction of TestRunHandler failed with message: {0}, \ntrace: {1}",
141100
new Object[]{ex.getMessage(), Throwables.getStackTraceAsString(ex)});
142101
dialogDisplayer.displayError("Failed to run the tests: " + ex.getMessage());
143102
}
144-
145103
});
146104
}
147105

148106
private void explainResults(final RunResult result, final TmcProjectInfo projectInfo, final ResultCollector resultCollector) {
149-
System.out.println("Explain resultissa");
150-
/*SwingUtilities.invokeLater(new Runnable() {
107+
SwingUtilities.invokeLater(new Runnable() {
151108

152109
@Override
153-
public void run() {*/
110+
public void run() {
154111
if (result.status == COMPILE_FAILED) {
155112
dialogDisplayer.displayError("The code did not compile.");
156113
return;
@@ -163,11 +120,9 @@ public void run() {*/
163120
public void run() {
164121
exerciseSubmitter.performAction(projectInfo.getProject());
165122
}
166-
}, resultCollector);
167-
/*
123+
}, resultCollector);
168124
}
169-
170-
});*/
125+
});
171126
}
172127

173128
private List<TestCaseResult> testResultsToTestCaseResults(ImmutableList<TestResult> testresults) {
@@ -178,17 +133,4 @@ private List<TestCaseResult> testResultsToTestCaseResults(ImmutableList<TestResu
178133
}
179134
return testCaseResults;
180135
}
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-
}*/
194136
}

0 commit comments

Comments
 (0)