Skip to content

Commit 8991c69

Browse files
committed
Merge pull request #29 from rage/core-update
Updated tmc-netbeans to match changed tmc-core api
2 parents 85cda09 + 8e6df41 commit 8991c69

File tree

7 files changed

+46
-23
lines changed

7 files changed

+46
-23
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.awt.event.ActionEvent;
2222
import java.awt.event.ActionListener;
2323
import java.net.URI;
24+
import java.net.URISyntaxException;
2425
import java.util.ArrayList;
2526
import javax.swing.AbstractAction;
2627
import javax.swing.Icon;
@@ -80,8 +81,8 @@ public void actionPerformed(ActionEvent e) {
8081
}
8182

8283
public void run() {
84+
final Course currentCourseBeforeUpdate = courseDb.getCurrentCourse();
8385
try {
84-
final Course currentCourseBeforeUpdate = courseDb.getCurrentCourse();
8586
if (backgroundProcessingOrNoCurrentCourse(currentCourseBeforeUpdate)) {
8687
return;
8788
}
@@ -94,12 +95,16 @@ public void run() {
9495
Futures.addCallback(currentCourseFuture, new UpdateCourseForExerciseUpdate(exerciseRefresh));
9596
} catch (TmcCoreException ex) {
9697
Exceptions.printStackTrace(ex);
98+
dialogs.displayError("An exception occurred in tmc core", ex);
99+
} catch (URISyntaxException ex) {
100+
String illegalUri = currentCourseBeforeUpdate.getDetailsUrl();
101+
dialogs.displayError("Illegal uri from server: " + illegalUri, ex);
102+
Exceptions.printStackTrace(ex);
97103
}
98104
}
99105

100-
private URI detailUrl(final Course currentCourseBeforeUpdate) {
101-
return URI.create(new ServerAccess().addApiCallQueryParameters(
102-
currentCourseBeforeUpdate.getDetailsUrl()));
106+
private URI detailUrl(final Course currentCourseBeforeUpdate) throws URISyntaxException {
107+
return new URI(currentCourseBeforeUpdate.getDetailsUrl());
103108
}
104109

105110
/**

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import java.awt.event.ActionEvent;
1717
import java.awt.event.ActionListener;
1818
import java.net.URI;
19+
import java.nio.file.Path;
20+
import java.nio.file.Paths;
1921
import java.util.List;
2022
import java.util.logging.Level;
2123
import java.util.logging.Logger;
@@ -108,7 +110,9 @@ private void submitPaste(final TmcProjectInfo projectInfo, final Exercise exerci
108110
projectMediator.saveAllFiles();
109111
final String errorMsgLocale = settings.getErrorMsgLocale().toString();
110112
try {
111-
ListenableFuture<URI> result = TmcCoreSingleton.getInstance().pasteWithComment(projectInfo.getProjectDirAsPath(), messageForReviewer);
113+
Path path = Paths.get(projectInfo.getProjectDirAbsPath());
114+
ListenableFuture<URI> result = TmcCoreSingleton.getInstance()
115+
.pasteWithComment(path, messageForReviewer);
112116
Futures.addCallback(result, new PasteResult());
113117
} catch (TmcCoreException ex) {
114118
Exceptions.printStackTrace(ex);

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import fi.helsinki.cs.tmc.utilities.FutureCallbackList;
1414
import fi.helsinki.cs.tmc.core.TmcCore;
1515
import fi.helsinki.cs.tmc.core.exceptions.TmcCoreException;
16+
import java.net.URI;
17+
import java.net.URISyntaxException;
1618
import java.util.ArrayList;
1719
import java.util.List;
1820
import java.util.logging.Level;
@@ -80,8 +82,9 @@ public void run() {
8082
try {
8183
if (settingsAreSet()) {
8284
ProgressHandle courseRefresh = ProgressHandleFactory.createSystemHandle(
83-
"Refreshing course list");
85+
"Refreshing course list");
8486
courseRefresh.start();
87+
8588
ListenableFuture<List<Course>> listCourses = this.tmcCore.listCourses();
8689
Futures.addCallback(listCourses, new LoadCourses(courseRefresh));
8790
}
@@ -102,7 +105,7 @@ class LoadCourses implements FutureCallback<List<Course>> {
102105
private ProgressHandle lastAction;
103106

104107
/**
105-
* This callBack is run when ListenableFuture (to witch this is
108+
* This callBack is run when ListenableFuture (to which this is
106109
* attached) is done. On success method takes list of Course-objects,
107110
* searches the current course and starts uploading the details of the
108111
* course. If no currentCourse found, no need to update details.
@@ -124,13 +127,16 @@ public void onSuccess(final List<Course> courses) {
124127
ProgressHandle loadingCourse = ProgressHandleFactory.
125128
createSystemHandle("Loading course");
126129
loadingCourse.start();
127-
ListenableFuture<Course> courseFuture = tmcCore.getCourse(
128-
currentCourse.getDetailsUrlAsUri()
129-
);
130+
URI uri = new URI(currentCourse.getDetailsUrl());
131+
ListenableFuture<Course> courseFuture = tmcCore.getCourse(uri);
132+
130133
Futures.addCallback(courseFuture, new UpdateCourse(courses, loadingCourse));
131134
} catch (TmcCoreException ex) {
132135
Exceptions.printStackTrace(ex);
133136
callbacks.onFailure(ex);
137+
} catch (URISyntaxException ex) {
138+
Exceptions.printStackTrace(ex);
139+
callbacks.onFailure(ex);
134140
}
135141
} else {
136142
callbacks.onSuccess(courses);

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import fi.helsinki.cs.tmc.core.exceptions.TmcCoreException;
1616
import java.io.IOException;
1717
import java.net.URI;
18+
import java.net.URISyntaxException;
1819
import java.util.HashMap;
1920
import java.util.List;
2021
import java.util.Map;
@@ -42,21 +43,23 @@ public void run() {
4243
try {
4344
ListenableFuture<HttpResult> feedbackFuture;
4445
feedbackFuture = core.sendFeedback(
45-
getFeedbackAnswers(), URI.create(result.getFeedbackAnswerUrl())
46+
getFeedbackAnswers(), new URI(result.getFeedbackAnswerUrl())
4647
);
4748
Futures.addCallback(feedbackFuture, new FeedbackReplyCallback());
4849
} catch (TmcCoreException ex) {
4950
Exceptions.printStackTrace(ex);
51+
} catch (URISyntaxException ex) {
52+
Exceptions.printStackTrace(ex);
5053
}
5154
}
5255

5356
private Map<String, String> getFeedbackAnswers() {
5457
Map<String, String> answerMap = new HashMap<String, String>();
55-
58+
5659
for (FeedbackAnswer answer : answers) {
5760
answerMap.put("" + answer.getQuestion().getId(), answer.getAnswer());
5861
}
59-
62+
6063
return answerMap;
6164
}
6265

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import fi.helsinki.cs.tmc.core.domain.Exercise;
2020
import fi.helsinki.cs.tmc.core.domain.submission.SubmissionResult;
2121
import fi.helsinki.cs.tmc.core.exceptions.TmcCoreException;
22+
import java.nio.file.Path;
23+
import java.nio.file.Paths;
2224
import java.util.logging.Level;
2325
import java.util.logging.Logger;
2426
import javax.swing.SwingUtilities;
@@ -38,7 +40,9 @@ public final class SubmitExerciseAction extends AbstractExerciseSensitiveAction
3840
private ConvenientDialogDisplayer dialogs;
3941

4042
public static class InvokedEvent implements TmcEvent {
43+
4144
public final TmcProjectInfo projectInfo;
45+
4246
public InvokedEvent(TmcProjectInfo projectInfo) {
4347
this.projectInfo = projectInfo;
4448
}
@@ -83,7 +87,8 @@ private void submitProject(TmcProjectInfo info) {
8387
final SubmissionResultWaitingDialog dialog = SubmissionResultWaitingDialog.createAndShow();
8488
try {
8589
ListenableFuture<SubmissionResult> result;
86-
result = core.submit(info.getProjectDirAsPath());
90+
Path path = Paths.get(info.getProjectDirAbsPath());
91+
result = core.submit(path);
8792
Futures.addCallback(result, new SubmissionCallback(exercise, dialog));
8893
} catch (TmcCoreException ex) {
8994
String message = "There was an error submitting project " + info.getProjectName();
@@ -116,7 +121,7 @@ private SubmissionCallback(Exercise exercise, SubmissionResultWaitingDialog dial
116121

117122
@Override
118123
public void onSuccess(final SubmissionResult result) {
119-
if(result == null){
124+
if (result == null) {
120125
System.err.println("Result is null.");
121126
}
122127
SwingUtilities.invokeLater(new Runnable() {
@@ -126,7 +131,7 @@ public void run() {
126131
dialog.close();
127132
final ResultCollector resultCollector = new ResultCollector(exercise);
128133
resultCollector.setValidationResult(result.getValidationResult());
129-
134+
130135
resultDisplayer.showSubmissionResult(exercise, result, resultCollector);
131136
exercise.setAttempted(true);
132137
if (result.isAllTestsPassed()) {
@@ -158,4 +163,3 @@ public void run() {
158163
}
159164

160165
}
161-

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ public void performAction(final ResultCollector resultCollector, final Project p
3636
final TmcProjectInfo projectInfo = ProjectMediator.getInstance().wrapProject(project);
3737
final String projectType = projectInfo.getProjectType().name();
3838
ProjectMediator.getInstance().saveAllFiles();
39-
4039
try {
41-
ListenableFuture<ValidationResult> result = TmcCoreSingleton.getInstance().runCheckstyle(projectInfo.getProjectDirAsPath());
40+
ListenableFuture<ValidationResult> result = TmcCoreSingleton.getInstance().runCheckstyle(
41+
Paths.get(
42+
projectInfo.getProjectDirAsFile().getAbsolutePath()
43+
));
4244
Futures.addCallback(result, new ExplainValidationResult(resultCollector, dialogDisplayer));
43-
4445
} catch (TmcCoreException ex) {
4546
ConvenientDialogDisplayer.getDefault().displayError("Checkstyle audit failed.");
4647
Exceptions.printStackTrace(ex);
4748
}
48-
4949
}
5050

5151
}
@@ -54,7 +54,7 @@ class ExplainValidationResult implements FutureCallback<ValidationResult> {
5454

5555
ResultCollector resultCollector;
5656
ConvenientDialogDisplayer dialogDisplayer;
57-
57+
5858
public ExplainValidationResult(ResultCollector resultCollector, ConvenientDialogDisplayer dialogDisplayer) {
5959
this.resultCollector = resultCollector;
6060
this.dialogDisplayer = dialogDisplayer;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public void performAction(final ResultCollector resultCollector, Project... proj
7373
"Running tests.");
7474
runningTestsLocally.start();
7575
try {
76-
ListenableFuture<RunResult> result = TmcCoreSingleton.getInstance().test(projectInfo.getProjectDirAsPath());
76+
ListenableFuture<RunResult> result = TmcCoreSingleton.getInstance()
77+
.test(Paths.get(projectInfo.getProjectDirAbsPath()));
7778
Futures.addCallback(result, new FutureCallback<RunResult>() {
7879
@Override
7980
public void onSuccess(final RunResult result) {

0 commit comments

Comments
 (0)