Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull request for issue #62 #120

Open
wants to merge 14 commits into
base: core_integration
Choose a base branch
from
2 changes: 1 addition & 1 deletion maven-wrapper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>tmc-checkstyle-runner</artifactId>
<version>2.1.2-SNAPSHOT</version>
<version>2.1.1</version>
<exclusions>
<exclusion>
<groupId>com.puppycrawl.tools</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void bgTaskFailed(Throwable ex) {
public Course call() throws Exception {
logger.info("Downloading course to refresh cache");
currentCourseFuture =
tmcCore.getCourse(currentCourseBeforeUpdate.getDetailsUrlAsUri());
tmcCore.getCourse(currentCourseBeforeUpdate.getDetailsUrl());
return currentCourseFuture.get();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ public void bgTaskCancelled() {}

@Override
public void bgTaskFailed(Throwable ex) {
dialogs.displayError("Failed to send exercise to pastebin", ex);
dialogs.displayError("Failed to send exercise to pastebin. \n"
+ ServerErrorHelper.getServerExceptionMsg(ex));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ public void bgTaskCancelled() {}
@Override
public void bgTaskFailed(Throwable ex) {
dialogs.displayError(
"Failed to submit exercise for code review", ex);
"Failed to submit exercise for code review \n"
+ ServerErrorHelper.getServerExceptionMsg(ex));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.URI;
import java.nio.charset.Charset;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -175,7 +176,7 @@ private void sendLoggableEvent(Review review) {
private static class ReviewOpened {
public final int id;
public final int submissionId;
public final String url;
public final URI url;
public final boolean markedAsRead;

public ReviewOpened(Review review) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void onSuccess(HttpResult v) {

@Override
public void onFailure(Throwable ex) {
String msg = "Failed to send feedback :-(\n" + ex.getMessage();
String msg = "Failed to send feedback :-(\n" + ServerErrorHelper.getServerExceptionMsg(ex);
String msgWithBacktrace = msg + "\n" + ExceptionUtils.backtraceToString(ex);
log.log(Level.INFO, msgWithBacktrace);
dialogs.displayError(msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void bgTaskFailed(Throwable ex) {
log.log(Level.INFO, "Error waiting for results from server.", ex);
String msg = ServerErrorHelper.getServerExceptionMsg(ex);
if (!Strings.isNullOrEmpty(msg)) {
dialogDisplayer.displayError("Error trying to get test results.", ex);
dialogDisplayer.displayError("Error trying to get test results. \n" + msg);
}
dialog.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Paths;
import java.util.Collection;

/**
Expand Down Expand Up @@ -44,7 +45,7 @@ public InputStream openInputStream() {
public UpdateCenterLayerGen() {
synchronized (UpdateCenterLayerGen.class) {
if (!callbackRegistered) {
CallbackURLStreamHandler.registerCallback(CALLBACK_NAME, callback);
CallbackURLStreamHandler.registerCallback(Paths.get(CALLBACK_NAME), callback);
}
callbackRegistered = true;
}
Expand Down
7 changes: 4 additions & 3 deletions tmc-plugin/src/fi/helsinki/cs/tmc/model/CourseDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -142,13 +143,13 @@ public List<Exercise> getCurrentCourseUnlockableExercises() {
List<Exercise> result = new ArrayList<Exercise>();
Course course = getCurrentCourse();
if (course != null) {
List<String> unlockables = course.getUnlockables();
List<URI> unlockables = course.getUnlockables();
if (unlockables == null) {
unlockables = Collections.emptyList();
}
for (String exerciseName : unlockables) {
for (URI exerciseName : unlockables) {
for (Exercise ex : course.getExercises()) {
if (ex.getName().equals(exerciseName)) {
if (ex.getName().equals(exerciseName.toString())) {
result.add(ex);
}
}
Expand Down
10 changes: 7 additions & 3 deletions tmc-plugin/src/fi/helsinki/cs/tmc/model/NbTmcSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import fi.helsinki.cs.tmc.tailoring.Tailoring;
import fi.helsinki.cs.tmc.core.configuration.TmcSettings;
import fi.helsinki.cs.tmc.core.domain.Course;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Locale;

/**
Expand Down Expand Up @@ -153,9 +156,10 @@ public boolean isSavingPassword() {

@Override
public String getTmcMainDirectory() {
String path = settings.get(PREF_PROJECT_ROOT_DIR, null);
if (path != null) {
return path;
String target = settings.get(PREF_PROJECT_ROOT_DIR, null);
//TODO: Change String to Path in TmcSettings
if (target != null) {
return target;
} else {
// Can sometimes take a while. That's why we don't pass it as a default above.
return ProjectMediator.getDefaultProjectRootDir();
Expand Down
9 changes: 6 additions & 3 deletions tmc-plugin/src/fi/helsinki/cs/tmc/model/ProjectMediator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import fi.helsinki.cs.tmc.core.domain.Exercise;
import fi.helsinki.cs.tmc.utilities.ExceptionUtils;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -113,13 +116,13 @@ public File getCourseRootDir(String courseName) {
* The exercise must have a course name set.
*/
public File getProjectDirForExercise(Exercise ex) {
String path =
Path path = Paths.get(
getProjectRootDir()
+ File.separator
+ ex.getCourseName()
+ File.separator
+ ex.getName().replaceAll("-", "/");
File file = new File(path);
+ ex.getName().replaceAll("-", "/"));
File file = path.toFile();
return FileUtil.normalizeFile(file);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import fi.helsinki.cs.tmc.events.TmcEvent;
import fi.helsinki.cs.tmc.events.TmcEventBus;
import fi.helsinki.cs.tmc.events.TmcEventListener;

import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.cometd.bayeux.Channel;
import org.cometd.bayeux.Message;
import org.cometd.bayeux.client.ClientSession;
Expand Down Expand Up @@ -120,12 +123,12 @@ private synchronized void initClientIfPossible() {
return;
}

String cometUrl = course.getCometUrl();
URI cometUrl = course.getCometUrl();
if (cometUrl == null) {
return;
}
ClientTransport transport = createWebSocketTransport(cometUrl);
client = new BayeuxClient(cometUrl, transport);
ClientTransport transport = createWebSocketTransport(cometUrl.toString());
client = new BayeuxClient(cometUrl.toString(), transport);
client.getChannel(Channel.META_HANDSHAKE).addListener(handshakeListener);
client.getChannel(Channel.META_DISCONNECT).addListener(disconnectListener);

Expand Down
22 changes: 11 additions & 11 deletions tmc-plugin/src/fi/helsinki/cs/tmc/model/ServerAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ public boolean cancel() {

@Deprecated
public CancellableCallable<Course> getFullCourseInfoTask(Course courseStub) {
String url = addApiCallQueryParameters(courseStub.getDetailsUrl());
final CancellableCallable<String> download = createHttpTasks().getForText(url);
URI url = URI.create(addApiCallQueryParameters(courseStub.getDetailsUrl().toString()));
final CancellableCallable<String> download = createHttpTasks().getForText(url.toString());
return new CancellableCallable<Course>() {
@Override
public Course call() throws Exception {
Expand Down Expand Up @@ -177,22 +177,22 @@ public boolean cancel() {
}

private String getUnlockUrl(Course course) {
return addApiCallQueryParameters(course.getUnlockUrl());
return addApiCallQueryParameters(course.getUnlockUrl().toString());
}

public CancellableCallable<byte[]> getDownloadingExerciseZipTask(Exercise exercise) {
String zipUrl = exercise.getDownloadUrl();
return createHttpTasks().getForBinary(zipUrl);
URI zipUrl = exercise.getDownloadUrl();
return createHttpTasks().getForBinary(zipUrl.toString());
}

public CancellableCallable<byte[]> getDownloadingExerciseSolutionZipTask(Exercise exercise) {
String zipUrl = exercise.getSolutionDownloadUrl();
return createHttpTasks().getForBinary(zipUrl);
URI zipUrl = exercise.getSolutionDownloadUrl();
return createHttpTasks().getForBinary(zipUrl.toString());
}

public CancellableCallable<SubmissionResponse> getSubmittingExerciseTask(
final Exercise exercise, final byte[] sourceZip, Map<String, String> extraParams) {
final String submitUrl = addApiCallQueryParameters(exercise.getReturnUrl());
final URI submitUrl = URI.create(addApiCallQueryParameters(exercise.getReturnUrl().toString()));

Map<String, String> params = new LinkedHashMap<String, String>();
params.put("client_time", "" + (System.currentTimeMillis() / 1000L));
Expand All @@ -202,7 +202,7 @@ public CancellableCallable<SubmissionResponse> getSubmittingExerciseTask(
final CancellableCallable<String> upload =
createHttpTasks()
.uploadFileForTextDownload(
submitUrl, params, "submission[file]", sourceZip);
submitUrl.toString(), params, "submission[file]", sourceZip);

return new CancellableCallable<SubmissionResponse>() {
@Override
Expand Down Expand Up @@ -254,8 +254,8 @@ public CancellableCallable<String> getSubmissionFetchTask(String submissionUrl)
}

public CancellableCallable<List<Review>> getDownloadingReviewListTask(Course course) {
String url = addApiCallQueryParameters(course.getReviewsUrl());
final CancellableCallable<String> download = createHttpTasks().getForText(url);
URI url = URI.create(addApiCallQueryParameters(course.getReviewsUrl().toString()));
final CancellableCallable<String> download = createHttpTasks().getForText(url.toString());
return new CancellableCallable<List<Review>>() {
@Override
public List<Review> call() throws Exception {
Expand Down
9 changes: 6 additions & 3 deletions tmc-plugin/src/fi/helsinki/cs/tmc/model/SourceFileLookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import fi.helsinki.cs.tmc.core.domain.Exercise;

import java.nio.file.Path;
import java.nio.file.Paths;

import org.netbeans.api.java.classpath.GlobalPathRegistry;
import org.openide.filesystems.FileObject;

Expand All @@ -24,20 +27,20 @@ private SourceFileLookup(

public FileObject findSourceFileFor(Exercise exercise, String className) {
String outerClassName = className.replaceAll("\\$.*$", "");
String path = outerClassName.replace('.', '/') + ".java";
Path path = Paths.get(outerClassName.replace('.', '/') + ".java");

TmcProjectInfo correctProject = projectMediator.tryGetProjectForExercise(exercise);
for (FileObject sr : globalPathRegistry.getSourceRoots()) {
TmcProjectInfo p = projectMediator.tryGetProjectOwningFile(sr);
if (p != null && p.equals(correctProject)) {
FileObject result = sr.getFileObject(path);
FileObject result = sr.getFileObject(path.toString());
if (result != null) {
return result;
}
}
}

// Fall back to findResource picking a source root from any project.
return GlobalPathRegistry.getDefault().findResource(path);
return GlobalPathRegistry.getDefault().findResource(path.toString());
}
}
Loading