Skip to content

Commit

Permalink
Fix bsp: getMillBuildClasspath return URI string (#1325)
Browse files Browse the repository at this point in the history
getMillBuildClasspath is expect to return URI, otherwise IDEA bsp import will have
`java.lang.IllegalArgumentException: Missing scheme` error on MacOS and
`Java.net.URISyntaxException: Illegal character in opaque part at index 2: ...` on Windows

Add a scaladoc to describe that strings returned by getMillBuildClasspath is URIs.

Pull request: #1325
  • Loading branch information
camper42 authored May 19, 2021
1 parent 2e45883 commit dc1cea1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions bsp/src/mill/bsp/ModuleUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ object ModuleUtils {
target
}

/**
* Compute the BuildClasspath for the Mill build (build.sc files)
*
* @param evaluator mill evaluator that can resolve build information
* @param sources classpath for source jars or not
* @return Mill build Classpath(URI)
*/
def getMillBuildClasspath(evaluator: Evaluator,
sources: Boolean): Seq[String] = {

Expand All @@ -144,7 +151,9 @@ object ModuleUtils {
* java.net.URL = file:/C:/Users/Developer/mill/./
* scala> java.nio.file.Paths.get(".").toAbsolutePath.toUri.toURL.getFile
* String = /C:/Users/Developer/mill/./
* */
*
* It works for @camper42 on MacOS & Windows IDEA, works for @fabianhjr on Linux(NixOS)
*/
val classpath: Seq[Path] = Try(
evaluator.rootModule.getClass.getClassLoader
.asInstanceOf[SpecialClassLoader])
Expand All @@ -162,7 +171,7 @@ object ModuleUtils {
val binarySource =
if (sources) all.filter(url => isPathSourceJar(url))
else all.filter(url => !isPathSourceJar(url))
binarySource.filter(path => exists(path)).map(_.wrapped.toString)
binarySource.filter(path => exists(path)).map(_.toNIO.toUri.toString)
}

/**
Expand Down

0 comments on commit dc1cea1

Please sign in to comment.