Skip to content

Commit ef87000

Browse files
committed
Merge branch 'core_integration' of github.com:rage/tmc-netbeans into core_integration
2 parents 36459b7 + c019e8b commit ef87000

File tree

8 files changed

+80
-209
lines changed

8 files changed

+80
-209
lines changed
Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
package fi.helsinki.cs.tmc.actions;
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 hy.tmc.core.domain.Course;
4-
import fi.helsinki.cs.tmc.data.Review;
7+
import hy.tmc.core.domain.Review;
58
import fi.helsinki.cs.tmc.model.CourseDb;
9+
import fi.helsinki.cs.tmc.model.NBTmcSettings;
610
import fi.helsinki.cs.tmc.model.ReviewDb;
711
import fi.helsinki.cs.tmc.model.ServerAccess;
12+
import fi.helsinki.cs.tmc.model.TmcCoreSingleton;
813
import fi.helsinki.cs.tmc.ui.ConvenientDialogDisplayer;
914
import fi.helsinki.cs.tmc.utilities.BgTask;
1015
import fi.helsinki.cs.tmc.utilities.BgTaskListener;
16+
import hy.tmc.core.exceptions.TmcCoreException;
1117
import java.awt.event.ActionEvent;
1218
import java.awt.event.ActionListener;
1319
import java.util.List;
@@ -18,24 +24,26 @@
1824
import org.openide.awt.ActionReference;
1925
import org.openide.awt.ActionReferences;
2026
import org.openide.awt.ActionRegistration;
27+
import org.openide.util.Exceptions;
2128
import org.openide.util.NbBundle;
2229

2330
@ActionID(category = "TMC",
24-
id = "fi.helsinki.cs.tmc.actions.CheckForNewReviews")
31+
id = "fi.helsinki.cs.tmc.actions.CheckForNewReviews")
2532
@ActionRegistration(displayName = "#CTL_CheckForNewReviews")
2633
@ActionReferences({
2734
@ActionReference(path = "Menu/TM&C", position = -40)
2835
})
2936
@NbBundle.Messages("CTL_CheckForNewReviews=Check for new code &reviews")
3037
public class CheckForNewReviews implements ActionListener, Runnable {
38+
3139
private static final Logger log = Logger.getLogger(CheckForNewReviews.class.getName());
32-
40+
3341
private static CheckForNewReviews instance;
34-
42+
3543
public static void startTimer() {
3644
if (instance == null) {
3745
instance = new CheckForNewReviews(true, false, false);
38-
int interval = 20*60*1000; // 20 minutes
46+
int interval = 20 * 60 * 1000; // 20 minutes
3947
javax.swing.Timer timer = new javax.swing.Timer(interval, instance);
4048
timer.setRepeats(true);
4149
timer.start();
@@ -44,15 +52,15 @@ public static void startTimer() {
4452
log.warning("CheckForNewReviews.startTimer() called twice");
4553
}
4654
}
47-
55+
4856
private ServerAccess serverAccess;
4957
private CourseDb courseDb;
5058
private ReviewDb reviewDb;
5159
private ConvenientDialogDisplayer dialogs;
5260
private boolean beQuiet;
5361
private boolean resetNotifications;
5462
private boolean notifyAboutNoNewReviews;
55-
63+
5664
CheckForNewReviews() {
5765
this(false, true, true);
5866
}
@@ -71,13 +79,13 @@ public static void startTimer() {
7179
public void actionPerformed(ActionEvent e) {
7280
run();
7381
}
74-
82+
7583
@Override
7684
public void run() {
7785
if (resetNotifications) {
7886
reviewDb.forgetReviewsNotifiedAbout();
7987
}
80-
88+
8189
Course course = courseDb.getCurrentCourse();
8290
if (course == null) {
8391
if (!beQuiet) {
@@ -88,28 +96,43 @@ public void run() {
8896
if (course.getReviewsUrl() == null) {
8997
return;
9098
}
91-
92-
BgTask.start("Checking for code reviews", serverAccess.getDownloadingReviewListTask(course), new BgTaskListener<List<Review>>() {
93-
@Override
94-
public void bgTaskReady(List<Review> result) {
95-
boolean newReviews = reviewDb.setReviews(result);
96-
if (!newReviews && notifyAboutNoNewReviews) {
97-
dialogs.displayMessage("You have no unread code reviews.");
99+
getReviews(course);
100+
101+
}
102+
103+
private void getReviews(Course course){
104+
try {
105+
ListenableFuture<List<Review>> reviews = TmcCoreSingleton.getInstance().getNewReviews(course, NBTmcSettings.getDefault());
106+
Futures.addCallback(reviews, new FutureCallback<List<Review>>() {
107+
108+
@Override
109+
public void onSuccess(List<Review> v) {
110+
success(v);
98111
}
99-
}
100112

101-
@Override
102-
public void bgTaskFailed(final Throwable ex) {
103-
final String msg = "Failed to check for code reviews";
104-
log.log(Level.INFO, msg, ex);
105-
if (!beQuiet) {
106-
dialogs.displayError(msg, ex);
113+
@Override
114+
public void onFailure(Throwable thrwbl) {
115+
fail(thrwbl);
107116
}
108-
}
109117

110-
@Override
111-
public void bgTaskCancelled() {
112-
}
113-
});
118+
});
119+
} catch (TmcCoreException ex) {
120+
Exceptions.printStackTrace(ex);
121+
}
122+
}
123+
124+
private void success(List<Review> list) {
125+
boolean newReviews = reviewDb.setReviews(list);
126+
if (!newReviews && notifyAboutNoNewReviews) {
127+
dialogs.displayMessage("You have no unread code reviews.");
128+
}
129+
}
130+
131+
private void fail(Throwable thrwbl) {
132+
final String msg = "Failed to check for code reviews";
133+
log.log(Level.INFO, msg, thrwbl);
134+
if (!beQuiet) {
135+
dialogs.displayError(msg, thrwbl);
136+
}
114137
}
115138
}

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

Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
package fi.helsinki.cs.tmc.actions;
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 hy.tmc.core.domain.Exercise;
47
import fi.helsinki.cs.tmc.model.CourseDb;
58
import fi.helsinki.cs.tmc.model.ProjectMediator;
69
import fi.helsinki.cs.tmc.model.ServerAccess;
710
import fi.helsinki.cs.tmc.model.TmcProjectInfo;
811
import fi.helsinki.cs.tmc.model.NBTmcSettings;
12+
import fi.helsinki.cs.tmc.model.TmcCoreSingleton;
913
import fi.helsinki.cs.tmc.ui.ConvenientDialogDisplayer;
1014
import fi.helsinki.cs.tmc.ui.PastebinDialog;
1115
import fi.helsinki.cs.tmc.ui.PastebinResponseDialog;
1216
import fi.helsinki.cs.tmc.utilities.BgTask;
1317
import fi.helsinki.cs.tmc.utilities.BgTaskListener;
1418
import fi.helsinki.cs.tmc.utilities.CancellableCallable;
1519
import fi.helsinki.cs.tmc.utilities.zip.RecursiveZipper;
20+
import hy.tmc.core.exceptions.TmcCoreException;
1621
import java.awt.event.ActionEvent;
1722
import java.awt.event.ActionListener;
1823
import java.net.URI;
@@ -28,6 +33,7 @@
2833
import org.openide.awt.ActionReferences;
2934
import org.openide.awt.ActionRegistration;
3035
import org.openide.nodes.Node;
36+
import org.openide.util.Exceptions;
3137
import org.openide.util.NbBundle.Messages;
3238

3339
@ActionID(
@@ -38,7 +44,7 @@
3844
@ActionReferences({
3945
@ActionReference(path = "Menu/TM&C", position = -17),
4046
@ActionReference(path = "Projects/Actions", position = 1340, separatorBefore = 1330,
41-
separatorAfter = 1360)
47+
separatorAfter = 1360)
4248
})
4349
@Messages("CTL_PastebinAction=Send code to Pastebin")
4450
//TODO: This is a horribly copypasted, then mangled version of RequestReviewAction
@@ -108,59 +114,30 @@ public void actionPerformed(ActionEvent e) {
108114
private void submitPaste(final TmcProjectInfo projectInfo, final Exercise exercise,
109115
final String messageForReviewer) {
110116
projectMediator.saveAllFiles();
111-
112117
final String errorMsgLocale = settings.getErrorMsgLocale().toString();
118+
try {
119+
ListenableFuture<URI> result = TmcCoreSingleton.getInstance().pasteWithComment(projectInfo.getProjectDirAbsPath(), settings, messageForReviewer);
120+
Futures.addCallback(result, new PasteResult());
121+
} catch (TmcCoreException ex) {
122+
Exceptions.printStackTrace(ex);
123+
}
124+
}
113125

114-
BgTask.start("Zipping up " + exercise.getName(), new Callable<byte[]>() {
115-
@Override
116-
public byte[] call() throws Exception {
117-
RecursiveZipper zipper = new RecursiveZipper(projectInfo.getProjectDirAsFile(), projectInfo.getZippingDecider());
118-
return zipper.zipProjectSources();
119-
}
120-
}, new BgTaskListener<byte[]>() {
121-
@Override
122-
public void bgTaskReady(byte[] zipData) {
123-
Map<String, String> extraParams = new HashMap<String, String>();
124-
extraParams.put("error_msg_locale", errorMsgLocale);
125-
extraParams.put("paste", "1");
126-
if (!messageForReviewer.isEmpty()) {
127-
extraParams.put("message_for_paste", messageForReviewer);
128-
}
129-
130-
final ServerAccess sa = new ServerAccess();
131-
CancellableCallable<ServerAccess.SubmissionResponse> submitTask = sa
132-
.getSubmittingExerciseTask(exercise, zipData, extraParams);
133-
134-
BgTask.start("Sending " + exercise.getName(), submitTask, new BgTaskListener<ServerAccess.SubmissionResponse>() {
135-
@Override
136-
public void bgTaskReady(ServerAccess.SubmissionResponse result) {
137-
new PastebinResponseDialog(result.pasteUrl.toString()).setVisible(true);
138-
}
139-
140-
@Override
141-
public void bgTaskCancelled() {
142-
}
143-
144-
@Override
145-
public void bgTaskFailed(Throwable ex) {
146-
dialogs.displayError("Failed to send exercise to pastebin", ex);
147-
}
148-
});
149-
}
126+
class PasteResult implements FutureCallback<URI> {
150127

151-
@Override
152-
public void bgTaskCancelled() {
153-
}
128+
@Override
129+
public void onSuccess(URI ur) {
130+
new PastebinResponseDialog(ur.toString()).setVisible(true);
131+
}
154132

155-
@Override
156-
public void bgTaskFailed(Throwable ex) {
157-
dialogs.displayError("Failed to zip up exercise", ex);
158-
}
159-
});
133+
@Override
134+
public void onFailure(Throwable thrwbl) {
135+
dialogs.displayError("Failed to send exercise to pastebin", thrwbl);
136+
}
160137
}
161138

162139
@Override
163140
public String getName() {
164141
return "Send code to TMC Pastebin";
165142
}
166-
}
143+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package fi.helsinki.cs.tmc.actions;
22

33
import com.google.gson.Gson;
4-
import fi.helsinki.cs.tmc.data.Review;
4+
import hy.tmc.core.domain.Review;
55
import fi.helsinki.cs.tmc.events.TmcEventBus;
66
import fi.helsinki.cs.tmc.events.TmcEventListener;
77
import fi.helsinki.cs.tmc.model.CourseDb;

0 commit comments

Comments
 (0)