Skip to content

Commit 16a3216

Browse files
committed
Publicise PlainNioFile and implement underlyingSource
``` $ ./build/quick/bin/scala Welcome to Scala 2.13.0-20190221-140355-c0a7682 (OpenJDK 64-Bit Server VM, Java 11). Type in expressions for evaluation. Or try :help. scala> :power scala> val path = symbolOf[java.lang.String].associatedFile path: scala.reflect.io.AbstractFile = /modules/java.base/java/lang/String.class scala> .underlyingSource res0: Option[scala.reflect.io.AbstractFile] = Some(/Users/jz/.jabba/jdk/[email protected]/Contents/Home/jmods/java.base.jmod) scala> .get.exists res1: Boolean = true res0: Boolean = true ``` ``` $ ./build/quick/bin/scala -release 8 Welcome to Scala 2.13.0-20190221-140355-c0a7682 (OpenJDK 64-Bit Server VM, Java 11). Type in expressions for evaluation. Or try :help. scala> :power scala> val path = symbolOf[java.lang.String].associatedFile path: scala.reflect.io.AbstractFile = /8/java/lang/String.sig scala> .underlyingSource res3: Option[scala.reflect.io.AbstractFile] = Some(/Users/jz/.jabba/jdk/[email protected]/Contents/Home/lib/ct.sym) scala> .get.exists res4: Boolean = true ``` References sbt/zinc#609
1 parent c0a7682 commit 16a3216

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/reflect/scala/reflect/io/PlainFile.scala

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class PlainFile(val givenPath: Path) extends AbstractFile {
101101
new PlainFile(givenPath / name)
102102
}
103103

104-
private[scala] class PlainNioFile(nioPath: java.nio.file.Path) extends AbstractFile {
104+
final class PlainNioFile(val nioPath: java.nio.file.Path) extends AbstractFile {
105105
import java.nio.file._
106106

107107
assert(nioPath ne null)
@@ -115,7 +115,29 @@ private[scala] class PlainNioFile(nioPath: java.nio.file.Path) extends AbstractF
115115

116116
override lazy val canonicalPath = super.canonicalPath
117117

118-
override def underlyingSource = Some(this)
118+
override def underlyingSource = {
119+
val fileSystem = nioPath.getFileSystem
120+
fileSystem.provider().getScheme match {
121+
case "jar" =>
122+
val fileStores = fileSystem.getFileStores.iterator()
123+
if (fileStores.hasNext) {
124+
val jarPath = fileStores.next().name
125+
try {
126+
Some(new PlainNioFile(Paths.get(jarPath.stripSuffix(fileSystem.getSeparator))))
127+
} catch {
128+
case _: InvalidPathException =>
129+
None
130+
}
131+
} else None
132+
case "jrt" =>
133+
if (nioPath.getNameCount > 2 && nioPath.startsWith("/modules")) {
134+
// TODO limit this to OpenJDK based JVMs?
135+
val moduleName = nioPath.getName(1)
136+
Some(new PlainNioFile(Paths.get(System.getProperty("java.home"), "jmods", moduleName.toString + ".jmod")))
137+
} else None
138+
case _ => None
139+
}
140+
}
119141

120142
private val fpath = nioPath.toAbsolutePath.toString
121143

0 commit comments

Comments
 (0)