Skip to content

Commit 41efbf1

Browse files
committed
converted strings to Path and URI bojects for tmc-core
1 parent efb00a2 commit 41efbf1

File tree

7 files changed

+49
-26
lines changed

7 files changed

+49
-26
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import fi.helsinki.cs.tmc.core.exceptions.TmcCoreException;
2121
import java.awt.event.ActionEvent;
2222
import java.awt.event.ActionListener;
23+
import java.net.URI;
24+
import java.net.URISyntaxException;
2325
import java.util.ArrayList;
2426
import javax.swing.AbstractAction;
2527
import javax.swing.Icon;
@@ -79,8 +81,8 @@ public void actionPerformed(ActionEvent e) {
7981
}
8082

8183
public void run() {
84+
final Course currentCourseBeforeUpdate = courseDb.getCurrentCourse();
8285
try {
83-
final Course currentCourseBeforeUpdate = courseDb.getCurrentCourse();
8486
if (backgroundProcessingOrNoCurrentCourse(currentCourseBeforeUpdate)) {
8587
return;
8688
}
@@ -93,13 +95,16 @@ public void run() {
9395
Futures.addCallback(currentCourseFuture, new UpdateCourseForExerciseUpdate(exerciseRefresh));
9496
} catch (TmcCoreException ex) {
9597
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);
96103
}
97104
}
98105

99-
private String detailUrl(final Course currentCourseBeforeUpdate) {
100-
return new ServerAccess().addApiCallQueryParameters(
101-
currentCourseBeforeUpdate.getDetailsUrl()
102-
);
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: 4 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,8 @@ 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.getProjectDirAbsPath(), messageForReviewer);
113+
Path path = Paths.get(projectInfo.getProjectDirAbsPath());
114+
ListenableFuture<URI> result = TmcCoreSingleton.getInstance().pasteWithComment(path, messageForReviewer);
112115
Futures.addCallback(result, new PasteResult());
113116
} catch (TmcCoreException ex) {
114117
Exceptions.printStackTrace(ex);

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

Lines changed: 12 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,17 @@ 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.getDetailsUrl()
129-
);
130+
URI uri = new URI(currentCourse.getDetailsUrl());
131+
System.out.println(uri + " here we go!\n\n\n\n\n\n\n\n\n\n");
132+
ListenableFuture<Course> courseFuture = tmcCore.getCourse(uri);
133+
130134
Futures.addCallback(courseFuture, new UpdateCourse(courses, loadingCourse));
131135
} catch (TmcCoreException ex) {
132136
Exceptions.printStackTrace(ex);
133137
callbacks.onFailure(ex);
138+
} catch (URISyntaxException ex) {
139+
Exceptions.printStackTrace(ex);
140+
callbacks.onFailure(ex);
134141
}
135142
} else {
136143
callbacks.onSuccess(courses);

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import fi.helsinki.cs.tmc.core.domain.submission.SubmissionResult;
1515
import fi.helsinki.cs.tmc.core.exceptions.TmcCoreException;
1616
import java.io.IOException;
17+
import java.net.URI;
18+
import java.net.URISyntaxException;
1719
import java.util.HashMap;
1820
import java.util.List;
1921
import java.util.Map;
@@ -41,23 +43,23 @@ public void run() {
4143
try {
4244
ListenableFuture<HttpResult> feedbackFuture;
4345
feedbackFuture = core.sendFeedback(
44-
getFeedbackAnswers(), result.getFeedbackAnswerUrl()
46+
getFeedbackAnswers(), new URI(result.getFeedbackAnswerUrl())
4547
);
4648
Futures.addCallback(feedbackFuture, new FeedbackReplyCallback());
4749
} catch (TmcCoreException ex) {
4850
Exceptions.printStackTrace(ex);
49-
} catch (IOException ex) {
51+
} catch (URISyntaxException ex) {
5052
Exceptions.printStackTrace(ex);
5153
}
5254
}
5355

5456
private Map<String, String> getFeedbackAnswers() {
5557
Map<String, String> answerMap = new HashMap<String, String>();
56-
58+
5759
for (FeedbackAnswer answer : answers) {
5860
answerMap.put("" + answer.getQuestion().getId(), answer.getAnswer());
5961
}
60-
62+
6163
return answerMap;
6264
}
6365

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.getProjectDirAbsPath());
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: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import fi.helsinki.cs.tmc.stylerunner.validation.ValidationResult;
1313
import fi.helsinki.cs.tmc.ui.ConvenientDialogDisplayer;
1414
import fi.helsinki.cs.tmc.core.exceptions.TmcCoreException;
15+
import java.nio.file.Paths;
1516

1617
import javax.swing.SwingUtilities;
1718

@@ -30,16 +31,16 @@ public void performAction(final ResultCollector resultCollector, final Project p
3031
final TmcProjectInfo projectInfo = ProjectMediator.getInstance().wrapProject(project);
3132
final String projectType = projectInfo.getProjectType().name();
3233
ProjectMediator.getInstance().saveAllFiles();
33-
3434
try {
35-
ListenableFuture<ValidationResult> result = TmcCoreSingleton.getInstance().runCheckstyle(projectInfo.getProjectDirAsFile().getAbsolutePath());
36-
Futures.addCallback(result, new ExplainValidationResult(resultCollector, dialogDisplayer));
37-
35+
ListenableFuture<ValidationResult> result = TmcCoreSingleton.getInstance().runCheckstyle(
36+
Paths.get(
37+
projectInfo.getProjectDirAsFile().getAbsolutePath()
38+
));
39+
Futures.addCallback(result, new ExplainValidationResult(resultCollector, dialogDisplayer));
3840
} catch (TmcCoreException ex) {
3941
ConvenientDialogDisplayer.getDefault().displayError("Checkstyle audit failed.");
4042
Exceptions.printStackTrace(ex);
4143
}
42-
4344
}
4445

4546
}
@@ -48,7 +49,7 @@ class ExplainValidationResult implements FutureCallback<ValidationResult> {
4849

4950
ResultCollector resultCollector;
5051
ConvenientDialogDisplayer dialogDisplayer;
51-
52+
5253
public ExplainValidationResult(ResultCollector resultCollector, ConvenientDialogDisplayer dialogDisplayer) {
5354
this.resultCollector = resultCollector;
5455
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
@@ -24,6 +24,7 @@
2424
import fi.helsinki.cs.tmc.ui.ConvenientDialogDisplayer;
2525
import fi.helsinki.cs.tmc.ui.TestResultDisplayer;
2626
import fi.helsinki.cs.tmc.core.exceptions.TmcCoreException;
27+
import java.nio.file.Paths;
2728
import java.util.ArrayList;
2829
import java.util.List;
2930
import static java.util.logging.Level.INFO;
@@ -72,7 +73,7 @@ public void performAction(final ResultCollector resultCollector, Project... proj
7273
"Running tests.");
7374
runningTestsLocally.start();
7475
try {
75-
ListenableFuture<RunResult> result = TmcCoreSingleton.getInstance().test(projectInfo.getProjectDirAbsPath());
76+
ListenableFuture<RunResult> result = TmcCoreSingleton.getInstance().test(Paths.get(projectInfo.getProjectDirAbsPath()));
7677
Futures.addCallback(result, new FutureCallback<RunResult>() {
7778
@Override
7879
public void onSuccess(final RunResult result) {

0 commit comments

Comments
 (0)