Skip to content

Commit fc634ed

Browse files
committed
Show ant compilation errors
1 parent 38b997a commit fc634ed

File tree

5 files changed

+78
-15
lines changed

5 files changed

+78
-15
lines changed

maven-wrapper/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<dependency>
4747
<groupId>${project.groupId}</groupId>
4848
<artifactId>core</artifactId>
49-
<version>0.8.0-SNAPSHOT</version>
49+
<version>0.8.2-SNAPSHOT</version>
5050
</dependency>
5151
<dependency>
5252
<groupId>${project.groupId}</groupId>

tmc-plugin/src/fi/helsinki/cs/tmc/actions/RunTestsLocallyAction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
import fi.helsinki.cs.tmc.langs.domain.RunResult;
1010
import fi.helsinki.cs.tmc.model.CourseDb;
1111
import fi.helsinki.cs.tmc.model.ProjectMediator;
12+
import fi.helsinki.cs.tmc.model.SourceFileLookup;
1213
import fi.helsinki.cs.tmc.utilities.BgTask;
1314
import fi.helsinki.cs.tmc.utilities.BgTaskListener;
1415

1516
import java.util.concurrent.Callable;
1617
import java.util.logging.Level;
1718
import java.util.logging.Logger;
1819
import org.netbeans.api.project.Project;
20+
import org.openide.filesystems.FileObject;
1921
import org.openide.nodes.Node;
2022
import org.openide.util.NbBundle.Messages;
2123
import org.openide.windows.WindowManager;

tmc-plugin/src/fi/helsinki/cs/tmc/data/ResultCollector.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44
import fi.helsinki.cs.tmc.langs.abstraction.Strategy;
55
import fi.helsinki.cs.tmc.langs.abstraction.ValidationResult;
66
import fi.helsinki.cs.tmc.langs.domain.RunResult;
7+
import fi.helsinki.cs.tmc.langs.domain.RunResult.Status;
78
import fi.helsinki.cs.tmc.langs.domain.TestResult;
89
import fi.helsinki.cs.tmc.ui.TestResultWindow;
910

11+
import com.google.common.base.Splitter;
1012
import com.google.common.collect.ImmutableList;
13+
import java.nio.charset.Charset;
14+
import java.util.ArrayList;
15+
import java.util.List;
16+
import java.util.Map;
1117

1218
/**
1319
* Waits for test and validation results and shows the result view only when
@@ -21,6 +27,7 @@ public final class ResultCollector {
2127

2228
private boolean testCaseResultsSet = false;
2329
private boolean validationResultsSet = false;
30+
private boolean dontWaitForValidations = false; // For e.g showing compilation errors.
2431

2532
private boolean isReturnable;
2633
private Runnable submissionCallback;
@@ -46,12 +53,37 @@ public void setTestCaseResults(final ImmutableList<TestResult> results) {
4653
}
4754

4855
public void setLocalTestResults(RunResult runResult) {
49-
setTestCaseResults(runResult.testResults);
56+
57+
if (runResult.status == Status.COMPILE_FAILED) {
58+
59+
String STDOUT = "stdout";
60+
String STDERR = "stderr";
61+
List<String> log = new ArrayList<String>();
62+
Splitter s = Splitter.on("\n");
63+
Map<String,byte[]> logs = runResult.logs;
64+
65+
if (logs.containsKey(STDOUT)) {
66+
String str1 = new String(logs.get(STDOUT), Charset.forName("utf-8"));
67+
log.addAll(s.splitToList(str1));
68+
}
69+
if (logs.containsKey(STDERR)) {
70+
log.addAll(s.splitToList(new String(logs.get(STDERR), Charset.forName("utf-8"))));
71+
}
72+
73+
log = tryToCleanLog(log);
74+
75+
TestResult buildFailed = new TestResult("Compilation failed", false, ImmutableList.<String>of(), "Compilation failed", ImmutableList.copyOf(log));
76+
77+
setTestCaseResults(ImmutableList.of(buildFailed));
78+
dontWaitForValidations = true;
79+
} else {
80+
setTestCaseResults(runResult.testResults);
81+
}
5082
}
5183

5284
private synchronized void showResultsIfReady() {
5385

54-
boolean ready = testCaseResultsSet && validationResultsSet;
86+
boolean ready = dontWaitForValidations || (testCaseResultsSet && validationResultsSet);
5587
if (ready) {
5688
TestResultWindow.get().showResults(exercise, testCaseResults, validationResults, submissionCallback, isSubmittable());
5789
}
@@ -86,5 +118,14 @@ private boolean isSubmittable() {
86118
return isReturnable;
87119
}
88120

121+
private List<String> tryToCleanLog(List<String> log) {
122+
for (int i = 0; i < log.size(); i++) {
123+
if (log.get(i).contains("-do-compile:")) {
124+
return log.subList(i, log.size());
125+
}
126+
}
127+
return log;
128+
}
129+
89130

90131
}

tmc-plugin/src/fi/helsinki/cs/tmc/model/SourceFileLookup.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Looks up the source FileObject of a given fully qualified class name.
1010
*/
1111
public class SourceFileLookup {
12+
1213
public static SourceFileLookup getDefault() {
1314
return new SourceFileLookup(ProjectMediator.getInstance(), GlobalPathRegistry.getDefault());
1415
}
@@ -24,12 +25,12 @@ private SourceFileLookup(ProjectMediator projectMediator, GlobalPathRegistry glo
2425
public FileObject findSourceFileFor(Exercise exercise, String className) {
2526
String outerClassName = className.replaceAll("\\$.*$", "");
2627
String path = outerClassName.replace('.', '/') + ".java";
27-
28+
2829
TmcProjectInfo correctProject = projectMediator.tryGetProjectForExercise(exercise);
2930
for (FileObject sr : globalPathRegistry.getSourceRoots()) {
3031
TmcProjectInfo p = projectMediator.tryGetProjectOwningFile(sr);
3132
if (p != null && p.equals(correctProject)) {
32-
33+
3334
FileObject result = sr.getFileObject(path);
3435
if (result != null) {
3536
return result;

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

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@ public final class TestCaseResultCell {
5353
private final GridBagConstraints gbc = new GridBagConstraints();
5454
private final JPanel detailView;
5555
private final ResultCell resultCell;
56-
57-
private static final Pattern JAVA_STACKTRACE_ELEMENT_PATTERN = Pattern.compile("([\\w.]+)(\\.\\w+|\\$([\\w\\.]+))\\((\\w+.java):(\\d+)\\)");
58-
5956

57+
private static final Pattern JAVA_STACKTRACE_ELEMENT_PATTERN = Pattern.compile("([\\w.]+)(\\.\\w+|\\$([\\w\\.]+))\\((\\w+.java):(\\d+)\\)");
58+
private static final Pattern FILE_PATH_PATTERN = Pattern.compile(".*(?:src|test|lib)[/\\\\]((?:[^/\\\\]\\S*[/\\\\]?)):(\\d+).*");// "((?:[^/\\\\]\\S*[/\\\\])\\S+[/\\\\]\\S+):(\\d+)");
6059
public TestCaseResultCell(final Exercise exercise, final TestResult result, final SourceFileLookup sourceFileLookup) {
6160

6261
gbc.anchor = GridBagConstraints.NORTHWEST;
@@ -215,7 +214,6 @@ public void finish() {
215214
// }
216215
//
217216
// };
218-
219217
private Action detailedMessageAction = new AbstractAction("Show detailed message") {
220218

221219
@Override
@@ -225,13 +223,13 @@ public void actionPerformed(ActionEvent event) {
225223

226224
ExceptionDisplay display = new ExceptionDisplay();
227225
ImmutableList<String> ex;
228-
226+
229227
if (result.getException() != null && result.getException().size() > 0) {
230228
ex = result.getException();
231229
} else {
232230
ex = result.getDetailedMessage();
233-
}
234-
231+
}
232+
235233
addException(display, ex, false);
236234
display.finish();
237235

@@ -244,14 +242,17 @@ public void actionPerformed(ActionEvent event) {
244242
private void addException(ExceptionDisplay display, ImmutableList<String> ex, boolean isCause) {
245243
if (ex.size() > 0) {
246244
display.addBoldTextLine(ex.get(0));
245+
ex = ex.subList(1, ex.size()); // Remove first of ImmutableList
247246
}
248247

249248
addStackTraceLines(display, ex);
250249
}
251250

252251
private void addStackTraceLines(ExceptionDisplay display, ImmutableList<String> stackTrace) {
253252
for (final String ste : stackTrace) {
253+
254254
Matcher matcher = JAVA_STACKTRACE_ELEMENT_PATTERN.matcher(ste);
255+
Matcher pathMatcher = FILE_PATH_PATTERN.matcher(ste);
255256
boolean added = false;
256257
if (matcher.matches()) {
257258
String packageAndClass = matcher.group(1);
@@ -268,13 +269,31 @@ public void actionPerformed(ActionEvent e) {
268269
added = true;
269270

270271
}
271-
if (!added) {
272-
display.addTextLine(ste);
272+
} else if (!added && pathMatcher.matches()) {
273+
String path = pathMatcher.group(1);
274+
final int row = Integer.parseInt(pathMatcher.group(2));
275+
if (path.endsWith(".java")) {
276+
path = path.substring(0, path.length() - 5);
277+
}
278+
final FileObject sourceFile = sourceFileLookup.findSourceFileFor(exercise, path);
279+
System.out.println("Source: " + path + "File: " + sourceFile);
280+
if (sourceFile != null && row > 0) {
281+
display.addLink(ste, new ActionListener() {
282+
@Override
283+
public void actionPerformed(ActionEvent e) {
284+
openAtLine(sourceFile, row);
285+
}
286+
});
287+
added = true;
288+
273289
}
290+
291+
}
292+
if (!added) {
293+
display.addTextLine(ste);
274294
}
275295
}
276296
}
277-
278297

279298
private void openAtLine(FileObject sourceFile, final int lineNum) {
280299
try {

0 commit comments

Comments
 (0)