diff --git a/src/reflect/scala/reflect/io/PlainFile.scala b/src/reflect/scala/reflect/io/PlainFile.scala index 91bb7380bff9..25dcdee09a81 100644 --- a/src/reflect/scala/reflect/io/PlainFile.scala +++ b/src/reflect/scala/reflect/io/PlainFile.scala @@ -101,7 +101,7 @@ class PlainFile(val givenPath: Path) extends AbstractFile { new PlainFile(givenPath / name) } -private[scala] class PlainNioFile(nioPath: java.nio.file.Path) extends AbstractFile { +final class PlainNioFile(val nioPath: java.nio.file.Path) extends AbstractFile { import java.nio.file._ assert(nioPath ne null) @@ -115,7 +115,29 @@ private[scala] class PlainNioFile(nioPath: java.nio.file.Path) extends AbstractF override lazy val canonicalPath = super.canonicalPath - override def underlyingSource = Some(this) + override def underlyingSource = { + val fileSystem = nioPath.getFileSystem + fileSystem.provider().getScheme match { + case "jar" => + val fileStores = fileSystem.getFileStores.iterator() + if (fileStores.hasNext) { + val jarPath = fileStores.next().name + try { + Some(new PlainNioFile(Paths.get(jarPath.stripSuffix(fileSystem.getSeparator)))) + } catch { + case _: InvalidPathException => + None + } + } else None + case "jrt" => + if (nioPath.getNameCount > 2 && nioPath.startsWith("/modules")) { + // TODO limit this to OpenJDK based JVMs? + val moduleName = nioPath.getName(1) + Some(new PlainNioFile(Paths.get(System.getProperty("java.home"), "jmods", moduleName.toString + ".jmod"))) + } else None + case _ => None + } + } private val fpath = nioPath.toAbsolutePath.toString