Skip to content

Pull request for issue #62 #120

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

Open
wants to merge 14 commits into
base: core_integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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 @@ -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());
}
}
32 changes: 19 additions & 13 deletions tmc-plugin/src/fi/helsinki/cs/tmc/runners/TestRunHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static fi.helsinki.cs.tmc.langs.domain.RunResult.Status.COMPILE_FAILED;
import static java.util.logging.Level.INFO;

import fi.helsinki.cs.tmc.actions.ServerErrorHelper;
import fi.helsinki.cs.tmc.core.domain.Exercise;
import fi.helsinki.cs.tmc.data.ResultCollector;
import fi.helsinki.cs.tmc.data.TestCaseResult;
Expand All @@ -21,6 +22,7 @@
import fi.helsinki.cs.tmc.utilities.BgTaskListener;
import fi.helsinki.cs.tmc.utilities.CancellableCallable;

import com.google.common.base.Strings;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.ListenableFuture;
Expand Down Expand Up @@ -65,16 +67,16 @@ public void performAction(final ResultCollector resultCollector, Project... proj
for (final Project project : projects) {
final TmcProjectInfo projectInfo = projectMediator.wrapProject(project);
eventBus.post(new InvokedEvent(projectInfo));
BgTaskListener bgTaskListener =
new BgTaskListener<RunResult>() {
BgTaskListener bgTaskListener
= new BgTaskListener<RunResult>() {
@Override
public void bgTaskReady(RunResult result) {
if (result.status == COMPILE_FAILED) {
dialogDisplayer.displayError("The code did not compile.");
return;
}
Exercise ex =
projectMediator.tryGetExerciseForProject(projectInfo, courseDb);
Exercise ex
= projectMediator.tryGetExerciseForProject(projectInfo, courseDb);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like indentation is not right here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow netbeans put indentation automatically like that when I fomatted it....

boolean canSubmit = ex.isReturnable();
resultDisplayer.showLocalRunResult(
testResultsToTestCaseResults(result.testResults),
Expand All @@ -94,15 +96,19 @@ public void bgTaskFailed(Throwable ex) {
log.log(
INFO,
"performAction of TestRunHandler failed with message: {0}, \ntrace: {1}",
new Object[] {
new Object[]{
ex.getMessage(), Throwables.getStackTraceAsString(ex)
});
dialogDisplayer.displayError(
"Failed to run the tests: " + ex.getMessage());
String msg = ServerErrorHelper.getServerExceptionMsg(ex);
if (!Strings.isNullOrEmpty(msg)) {
dialogDisplayer.displayError(
"Failed to run the tests: " + ex.getMessage());
}
}

@Override
public void bgTaskCancelled() {}
public void bgTaskCancelled() {
}
};
BgTask.start(
"Running tests",
Expand All @@ -112,9 +118,9 @@ public void bgTaskCancelled() {}

@Override
public RunResult call() throws Exception {
result =
TmcCoreSingleton.getInstance()
.test(projectInfo.getProjectDirAsPath());
result
= TmcCoreSingleton.getInstance()
.test(projectInfo.getProjectDirAsPath());
return result.get();
}

Expand All @@ -131,8 +137,8 @@ private List<TestCaseResult> testResultsToTestCaseResults(
ImmutableList<TestResult> testresults) {
List<TestCaseResult> testCaseResults = new ArrayList<TestCaseResult>();
for (TestResult result : testresults) {
TestCaseResult testCase =
new TestCaseResult(result.name, result.passed, result.errorMessage);
TestCaseResult testCase
= new TestCaseResult(result.name, result.passed, result.errorMessage);
testCaseResults.add(testCase);
}
return testCaseResults;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.openide.util.Exceptions;

import java.io.IOException;
import java.net.URI;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -248,15 +249,15 @@ private String pickDestinationUrl() {
return null;
}

List<String> urls = course.getSpywareUrls();
List<URI> urls = course.getSpywareUrls();
if (urls == null || urls.isEmpty()) {
log.log(
Level.INFO,
"Not sending events because no URL provided by server");
return null;
}

String url = urls.get(random.nextInt(urls.size()));
String url = urls.get(random.nextInt(urls.size())).toString();

return url;
}
Expand Down Expand Up @@ -316,8 +317,8 @@ private void clearAfterSend(List<HttpResult> success) {

private void addCorrectSpywareUrl(
final String url, Optional<Course> currentCourse) {
List<String> spywareUrls = new ArrayList<String>();
String finalUrl = serverAccess.addApiCallQueryParameters(url);
List<URI> spywareUrls = new ArrayList<URI>();
URI finalUrl = URI.create(serverAccess.addApiCallQueryParameters(url));
spywareUrls.add(finalUrl);
currentCourse.get().setSpywareUrls(spywareUrls);
}
Expand Down
Loading