Skip to content

Commit bba7043

Browse files
committed
Merge pull request #35 from rage/lint
Cleanup whitespace, reorder imports and some minor maintenance
2 parents 46669b8 + 07716c6 commit bba7043

File tree

67 files changed

+434
-613
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+434
-613
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,4 @@ public void bgTaskFailed(Throwable ex) {
100100
dialogs.displayError("Failed to download exercises.\n" + ServerErrorHelper.getServerExceptionMsg(ex));
101101
}
102102
};
103-
}
103+
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.util.Map;
1919
import java.util.logging.Level;
2020
import java.util.logging.Logger;
21-
import javax.swing.SwingUtilities;
2221

2322
/**
2423
* Stores the list of available courses, the current course and its exercise

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

Lines changed: 0 additions & 46 deletions
This file was deleted.

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import fi.helsinki.cs.tmc.core.domain.Review;
44
import fi.helsinki.cs.tmc.events.TmcEvent;
55
import fi.helsinki.cs.tmc.events.TmcEventBus;
6+
67
import java.util.ArrayList;
78
import java.util.HashSet;
89
import java.util.List;
9-
import java.util.Set;
1010
import java.util.logging.Logger;
1111

1212
/**
1313
* Stores and periodically updates reviews.
14-
*
14+
*
1515
* <p>
1616
* Currently this is an in-memory-only store, so it's always initially empty when the program starts.
1717
*/
@@ -23,23 +23,23 @@ public NewUnreadReviewEvent(Review review) {
2323
this.review = review;
2424
}
2525
}
26-
26+
2727
public static final Logger logger = Logger.getLogger(CourseDb.class.getName());
2828
private static ReviewDb instance;
29-
29+
3030
private TmcEventBus eventBus; //TODO: send out an event on new unread reviews
31-
31+
3232
public static ReviewDb getInstance() {
3333
if (instance == null) {
3434
instance = new ReviewDb();
3535
}
3636
return instance;
3737
}
38-
39-
38+
39+
4040
private ArrayList<Review> reviews;
4141
private HashSet<Integer> reviewIdsNotifiedAbout;
42-
42+
4343
private ReviewDb() {
4444
this(TmcEventBus.getDefault());
4545
this.reviews = new ArrayList<Review>();
@@ -49,10 +49,10 @@ private ReviewDb() {
4949
public ReviewDb(TmcEventBus eventBus) {
5050
this.eventBus = eventBus;
5151
}
52-
52+
5353
/**
5454
* Updates the review store and fires an event if there is a new unread review.
55-
*
55+
*
5656
* @return whether there were any new unread reviews (for which events were fired).
5757
*/
5858
public boolean setReviews(List<Review> newReviews) {
@@ -63,22 +63,22 @@ public boolean setReviews(List<Review> newReviews) {
6363
notifyAboutNewReview(review);
6464
}
6565
}
66-
66+
6767
this.reviews.clear();
6868
this.reviews.addAll(newReviews);
6969
return newUnreadReviewsSeen;
7070
}
71-
71+
7272
/**
7373
* Makes it so that all unread reviews cause a notification again.
7474
* Normally an unread review is not notified about twice.
7575
*/
7676
public void forgetReviewsNotifiedAbout() {
7777
reviewIdsNotifiedAbout.clear();
7878
}
79-
79+
8080
private void notifyAboutNewReview(Review review) {
8181
reviewIdsNotifiedAbout.add(review.getId());
8282
eventBus.post(new NewUnreadReviewEvent(review));
8383
}
84-
}
84+
}

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

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
package fi.helsinki.cs.tmc.model;
22

3-
import com.google.gson.Gson;
4-
import com.google.gson.GsonBuilder;
5-
import com.google.gson.JsonObject;
6-
import com.google.gson.JsonParser;
7-
import com.google.gson.reflect.TypeToken;
83
import fi.helsinki.cs.tmc.core.domain.Course;
94
import fi.helsinki.cs.tmc.core.domain.Exercise;
105
import fi.helsinki.cs.tmc.data.FeedbackAnswer;
@@ -20,6 +15,15 @@
2015
import fi.helsinki.cs.tmc.utilities.http.FailedHttpResponseException;
2116
import fi.helsinki.cs.tmc.utilities.http.HttpTasks;
2217
import fi.helsinki.cs.tmc.core.TmcCore;
18+
19+
import com.google.gson.Gson;
20+
import com.google.gson.GsonBuilder;
21+
import com.google.gson.JsonObject;
22+
import com.google.gson.JsonParser;
23+
import com.google.gson.reflect.TypeToken;
24+
25+
import org.openide.modules.Modules;
26+
2327
import java.io.ByteArrayOutputStream;
2428
import java.io.IOException;
2529
import java.io.OutputStreamWriter;
@@ -31,21 +35,23 @@
3135
import java.util.List;
3236
import java.util.Map;
3337
import java.util.zip.GZIPOutputStream;
34-
import org.openide.modules.Modules;
3538

3639
/**
3740
* A frontend for the server.
41+
*
42+
* @deprecated Users are suggested to rely on the tmc-core instead of this implementation.
3843
*/
44+
@Deprecated
3945
public class ServerAccess {
4046
public static final int API_VERSION = 7;
41-
47+
4248
private NbTmcSettings settings;
4349
private CourseListParser courseListParser;
4450
private CourseInfoParser courseInfoParser;
4551
private ReviewListParser reviewListParser;
4652
private String clientVersion;
4753
private TmcCore tmcCore;
48-
54+
4955
public ServerAccess() {
5056
this(NbTmcSettings.getDefault());
5157
}
@@ -66,30 +72,30 @@ public ServerAccess(
6672
this.reviewListParser = reviewListParser;
6773
this.clientVersion = getClientVersion();
6874
}
69-
75+
7076
private static String getClientVersion() {
7177
return Modules.getDefault().ownerOf(ServerAccess.class).getSpecificationVersion().toString();
7278
}
73-
79+
7480
public void setSettings(NbTmcSettings settings) {
7581
this.settings = settings;
7682
}
77-
83+
7884
private String getCourseListUrl() {
7985
return addApiCallQueryParameters(settings.getServerAddress() + "/courses.json");
8086
}
81-
87+
8288
public String addApiCallQueryParameters(String url) {
8389
url = UriUtils.withQueryParam(url, "api_version", ""+API_VERSION);
8490
url = UriUtils.withQueryParam(url, "client", "netbeans_plugin");
8591
url = UriUtils.withQueryParam(url, "client_version", getClientVersion());
8692
return url;
8793
}
88-
94+
8995
private HttpTasks createHttpTasks() {
9096
return new HttpTasks().setCredentials(settings.getUsername(), settings.getPassword());
9197
}
92-
98+
9399
public boolean hasEnoughSettings() {
94100
return
95101
!settings.getUsername().isEmpty() &&
@@ -103,7 +109,7 @@ public boolean needsOnlyPassword() {
103109
settings.getPassword().isEmpty() &&
104110
!settings.getServerAddress().isEmpty();
105111
}
106-
112+
107113
@Deprecated
108114
public CancellableCallable<List<Course>> getDownloadingCourseListTask() {
109115
final CancellableCallable<String> download = createHttpTasks().getForText(getCourseListUrl());
@@ -146,7 +152,7 @@ public boolean cancel() {
146152
}
147153
};
148154
}
149-
155+
150156
public CancellableCallable<Void> getUnlockingTask(Course course) {
151157
Map<String, String> params = Collections.emptyMap();
152158
final CancellableCallable<String> download = createHttpTasks().postForText(getUnlockUrl(course), params);
@@ -167,16 +173,16 @@ public boolean cancel() {
167173
}
168174
};
169175
}
170-
176+
171177
private String getUnlockUrl(Course course) {
172178
return addApiCallQueryParameters(course.getUnlockUrl());
173179
}
174-
180+
175181
public CancellableCallable<byte[]> getDownloadingExerciseZipTask(Exercise exercise) {
176182
String zipUrl = exercise.getDownloadUrl();
177183
return createHttpTasks().getForBinary(zipUrl);
178184
}
179-
185+
180186
public CancellableCallable<byte[]> getDownloadingExerciseSolutionZipTask(Exercise exercise) {
181187
String zipUrl = exercise.getSolutionDownloadUrl();
182188
return createHttpTasks().getForBinary(zipUrl);
@@ -192,7 +198,7 @@ public CancellableCallable<SubmissionResponse> getSubmittingExerciseTask(final E
192198

193199
final CancellableCallable<String> upload =
194200
createHttpTasks().uploadFileForTextDownload(submitUrl, params, "submission[file]", sourceZip);
195-
201+
196202
return new CancellableCallable<SubmissionResponse>() {
197203
@Override
198204
public SubmissionResponse call() throws Exception {
@@ -202,7 +208,7 @@ public SubmissionResponse call() throws Exception {
202208
} catch (FailedHttpResponseException ex) {
203209
return checkForObsoleteClient(ex);
204210
}
205-
211+
206212
JsonObject respJson = new JsonParser().parse(response).getAsJsonObject();
207213
if (respJson.get("error") != null) {
208214
throw new RuntimeException("Server responded with error: " + respJson.get("error"));
@@ -234,11 +240,11 @@ public SubmissionResponse(URI submissionUrl, URI pasteUrl) {
234240
this.pasteUrl = pasteUrl;
235241
}
236242
}
237-
243+
238244
public CancellableCallable<String> getSubmissionFetchTask(String submissionUrl) {
239245
return createHttpTasks().getForText(submissionUrl);
240246
}
241-
247+
242248
public CancellableCallable<List<Review>> getDownloadingReviewListTask(Course course) {
243249
String url = addApiCallQueryParameters(course.getReviewsUrl());
244250
final CancellableCallable<String> download = createHttpTasks().getForText(url);
@@ -259,7 +265,7 @@ public boolean cancel() {
259265
}
260266
};
261267
}
262-
268+
263269
public CancellableCallable<Void> getMarkingReviewAsReadTask(Review review, boolean read) {
264270
String url = addApiCallQueryParameters(review.getUpdateUrl() + ".json");
265271
Map<String, String> params = new HashMap<String, String>();
@@ -269,7 +275,7 @@ public CancellableCallable<Void> getMarkingReviewAsReadTask(Review review, boole
269275
} else {
270276
params.put("mark_as_unread", "1");
271277
}
272-
278+
273279
final CancellableCallable<String> task = createHttpTasks().postForText(url, params);
274280
return new CancellableCallable<Void>() {
275281
@Override
@@ -284,20 +290,20 @@ public boolean cancel() {
284290
}
285291
};
286292
}
287-
293+
288294
public CancellableCallable<String> getFeedbackAnsweringJob(String answerUrl, List<FeedbackAnswer> answers) {
289295
final String submitUrl = addApiCallQueryParameters(answerUrl);
290-
296+
291297
Map<String, String> params = new HashMap<String, String>();
292298
for (int i = 0; i < answers.size(); ++i) {
293299
String keyPrefix = "answers[" + i + "]";
294300
FeedbackAnswer answer = answers.get(i);
295301
params.put(keyPrefix + "[question_id]", "" + answer.getQuestion().getId());
296302
params.put(keyPrefix + "[answer]", answer.getAnswer());
297303
}
298-
304+
299305
final CancellableCallable<String> upload = createHttpTasks().postForText(submitUrl, params);
300-
306+
301307
return new CancellableCallable<String>() {
302308
@Override
303309
public String call() throws Exception {
@@ -314,7 +320,7 @@ public boolean cancel() {
314320
}
315321
};
316322
}
317-
323+
318324
public CancellableCallable<Object> getSendEventLogJob(String spywareServerUrl, List<LoggableEvent> events) {
319325
String url = addApiCallQueryParameters(spywareServerUrl);
320326

@@ -361,7 +367,7 @@ public byte[] eventListToPostBody(List<LoggableEvent> events) throws IOException
361367

362368
return bufferBos.toByteArray();
363369
}
364-
370+
365371
private <T> T checkForObsoleteClient(FailedHttpResponseException ex) throws ObsoleteClientException, FailedHttpResponseException {
366372
if (ex.getStatusCode() == 404) {
367373
boolean obsolete;
@@ -377,4 +383,4 @@ private <T> T checkForObsoleteClient(FailedHttpResponseException ex) throws Obso
377383

378384
throw ex;
379385
}
380-
}
386+
}

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

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

33
import fi.helsinki.cs.tmc.core.domain.Exercise;
4+
45
import org.netbeans.api.java.classpath.GlobalPathRegistry;
56
import org.openide.filesystems.FileObject;
67

@@ -38,4 +39,4 @@ public FileObject findSourceFileFor(Exercise exercise, String className) {
3839
// Fall back to findResource picking a source root from any project.
3940
return GlobalPathRegistry.getDefault().findResource(path);
4041
}
41-
}
42+
}

0 commit comments

Comments
 (0)