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

Fix construction of paths for compatibility on Windows #1279 #1283

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -44,7 +46,13 @@ public ContentInFile getContentByUri(String uri) {
}

public boolean openFile(String uri) {
Path path = getPathFromUri(uri);
Path path;
try {
path = getPathFromUri(uri);
} catch (URISyntaxException e) {
LOGGER.error("Malformed uri:" + uri, e);
return false;
}
try {
String content = Files.readString(path);
contentByUri.put(uri, new ContentInFile(content, 0));
Expand Down Expand Up @@ -92,9 +100,8 @@ public void closeFile(String uri) {
}


private Path getPathFromUri(String uri) {
String trimmedUri = uri.substring("file://".length());
return Paths.get(trimmedUri);
private Path getPathFromUri(String uri) throws URISyntaxException {
return Paths.get(new URI(uri));
}

private String applyChange(String content, TextDocumentContentChangeEvent change)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
package org.eclipse.buildship.gradleprop.provider;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
Expand Down Expand Up @@ -43,12 +42,10 @@ public class GradlePropertiesConnectionProvider extends ProcessStreamConnectionP
implements StreamConnectionProvider {

public GradlePropertiesConnectionProvider() {
URL localFileURL;
Bundle bundle = FrameworkUtil.getBundle(GradlePropertiesConnectionProvider.class);
try {
localFileURL = FileLocator.toFileURL(bundle.getEntry("/"));
URI localFileURI = new URI(localFileURL.toExternalForm());
Path pathToPlugin = Paths.get(localFileURI.getPath());
URL localFileURL = FileLocator.toFileURL(bundle.getEntry("/"));
Path pathToPlugin = Paths.get(localFileURL.toURI());

String pathToServer = pathToPlugin.resolve("libs/language-server.jar").toString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.Bundle;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -42,12 +41,10 @@ public class KotlinDSLConnectionProvider extends ProcessStreamConnectionProvider
implements StreamConnectionProvider {

public KotlinDSLConnectionProvider() {
URL localFileURL;
Bundle bundle = FrameworkUtil.getBundle(KotlinDSLConnectionProvider.class);
try {
localFileURL = FileLocator.toFileURL(bundle.getEntry("/"));
URI localFileURI = new URI(localFileURL.toExternalForm());
Path pathToPlugin = Paths.get(localFileURI.getPath());
URL localFileURL = FileLocator.toFileURL(bundle.getEntry("/"));
Path pathToPlugin = Paths.get(localFileURL.toURI());

String pathToServer = pathToPlugin.resolve("libs/server-1.0.0-all.jar").toString();

Expand Down