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

[BSP] InvalidPathException on Windows #1021

Closed
Iltotore opened this issue Dec 1, 2020 · 0 comments
Closed

[BSP] InvalidPathException on Windows #1021

Iltotore opened this issue Dec 1, 2020 · 0 comments
Milestone

Comments

@Iltotore
Copy link
Contributor

Iltotore commented Dec 1, 2020

Version: Latest (0.9.3)
OS: Windows 10 (older versions should encounter the same issue)

InvalidPathException thrown at ModuleUtils L124 due to unwanted slash at the path's start:

/C:/a/random/path/

induced by the URL#getFile method.

ScalaWilliam added a commit to ScalaWilliam/mill that referenced this issue Apr 18, 2021
…buildTarget/dependencySources - cannot import into IDE

There is a PR already (com-lihaoyi#1092) but I am wary of dealing with Strings directly. Here is my approach.

On Windows, File URLs follow an peculiar representation in Java

```
scala> java.nio.file.Paths.get(".").toAbsolutePath.toUri.toURL
java.net.URL = file:/C:/Users/Developer/mill/./
```

From this, we wish to get a `Path` back, and the way to do this is:

```
scala> java.nio.file.Paths.get((java.nio.file.Paths.get(".").toAbsolutePath.toUri.toURL).toURI)
java.nio.file.Path = C:\Users\Developer\mill\.
```

Unit testing for this is more challenging because the `WindowsFileSystem` instance is a `sun.nio.fs` package, rather than a standard package.

The solution here, compared to the previous code, is to reduce the number of conversions; the key loss happens when you do `(URL).getFile`.

```
scala> java.nio.file.Paths.get(".").toAbsolutePath.toUri.toURL
java.net.URL = file:/C:/Users/Developer/mill/./
scala> java.nio.file.Paths.get(".").toAbsolutePath.toUri.toURL.getFile
String = /C:/Users/Developer/mill/./
```
lefou pushed a commit that referenced this issue Apr 20, 2021
…Sources - cannot import into IDE (#1285)

There is a PR already (#1092) but I am wary of dealing with Strings directly. Here is my approach.

On Windows, File URLs follow an peculiar representation in Java

```
scala> java.nio.file.Paths.get(".").toAbsolutePath.toUri.toURL
java.net.URL = file:/C:/Users/Developer/mill/./
```

From this, we wish to get a `Path` back, and the way to do this is:

```
scala> java.nio.file.Paths.get((java.nio.file.Paths.get(".").toAbsolutePath.toUri.toURL).toURI)
java.nio.file.Path = C:\Users\Developer\mill\.
```

Unit testing for this is more challenging because the `WindowsFileSystem` instance is a `sun.nio.fs` package, rather than a standard package.

The solution here, compared to the previous code, is to reduce the number of conversions; the key loss happens when you do `(URL).getFile`.

```
scala> java.nio.file.Paths.get(".").toAbsolutePath.toUri.toURL
java.net.URL = file:/C:/Users/Developer/mill/./
scala> java.nio.file.Paths.get(".").toAbsolutePath.toUri.toURL.getFile
String = /C:/Users/Developer/mill/./
```

Pull request: #1285
@lefou lefou added this to the after 0.9.6 milestone Apr 20, 2021
@lefou lefou closed this as completed Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants