-
-
Notifications
You must be signed in to change notification settings - Fork 371
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
Milestone
Comments
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
induced by the
URL#getFile
method.The text was updated successfully, but these errors were encountered: