@@ -8,7 +8,7 @@ import java.net.{URI, URL}
88import java .nio .file .{FileSystems , Files }
99
1010import dotty .tools .dotc .classpath .PackageNameUtils .{packageContains , separatePkgAndClassNames }
11- import dotty .tools .io .{AbstractFile , PlainFile , ClassPath , ClassRepresentation , EfficientClassPath , JDK9Reflectors }
11+ import dotty .tools .io .{AbstractFile , PlainFile , ClassPath , ClassRepresentation , EfficientClassPath }
1212import FileUtils .*
1313import PlainFile .toPlainFile
1414
@@ -124,34 +124,21 @@ trait JFileDirectoryLookup[FileEntryType <: ClassRepresentation] extends Directo
124124}
125125
126126object JrtClassPath {
127- import java .nio .file .* , java .net .URI
128- def apply (release : Option [String ]): Option [ClassPath ] = {
129- import scala .util .Properties .*
130- if (! isJavaAtLeast(" 9" )) None
131- else {
132- // Longer term we'd like an official API for this in the JDK
133- // Discussion: http://mail.openjdk.java.net/pipermail/compiler-dev/2018-March/thread.html#11738
134-
135- val currentMajorVersion : Int = JDK9Reflectors .runtimeVersionMajor(JDK9Reflectors .runtimeVersion()).intValue()
136- release match {
137- case Some (v) if v.toInt < currentMajorVersion =>
138- try {
139- val ctSym = Paths .get(javaHome).resolve(" lib" ).resolve(" ct.sym" )
140- if (Files .notExists(ctSym)) None
141- else Some (new CtSymClassPath (ctSym, v.toInt))
142- } catch {
143- case NonFatal (_) => None
144- }
145- case _ =>
146- try {
147- val fs = FileSystems .getFileSystem(URI .create(" jrt:/" ))
148- Some (new JrtClassPath (fs))
149- } catch {
150- case _ : ProviderNotFoundException | _ : FileSystemNotFoundException => None
151- }
152- }
153- }
154- }
127+ import java .nio .file .* , java .net .URI , scala .util .Properties
128+ def apply (release : Option [String ]): Option [ClassPath ] =
129+ // Longer term we'd like an official API for this in the JDK
130+ // Discussion: http://mail.openjdk.java.net/pipermail/compiler-dev/2018-March/thread.html#11738
131+ release match
132+ case Some (v) if v.toInt < Runtime .version().feature() =>
133+ try
134+ val ctSym = Paths .get(Properties .javaHome).resolve(" lib" ).resolve(" ct.sym" )
135+ if (Files .notExists(ctSym)) None
136+ else Some (new CtSymClassPath (ctSym, v.toInt))
137+ catch case NonFatal (_) => None
138+ case _ =>
139+ try Some (new JrtClassPath (FileSystems .getFileSystem(URI .create(" jrt:/" ))))
140+ catch case _ : ProviderNotFoundException | _ : FileSystemNotFoundException => None
141+ end apply
155142}
156143
157144/**
@@ -228,11 +215,9 @@ final class CtSymClassPath(ctSym: java.nio.file.Path, release: Int) extends Clas
228215 // e.g. "java.lang" -> Seq(/876/java/lang, /87/java/lang, /8/java/lang))
229216 private val packageIndex : scala.collection.Map [String , scala.collection.Seq [Path ]] = {
230217 val index = collection.mutable.HashMap [String , collection.mutable.ListBuffer [Path ]]()
231- val isJava12OrHigher = scala.util.Properties .isJavaAtLeast(" 12" )
232218 rootsForRelease.foreach(root => Files .walk(root).iterator().asScala.filter(Files .isDirectory(_)).foreach { p =>
233- val moduleNamePathElementCount = if (isJava12OrHigher) 1 else 0
234- if (p.getNameCount > root.getNameCount + moduleNamePathElementCount) {
235- val packageDotted = p.subpath(moduleNamePathElementCount + root.getNameCount, p.getNameCount).toString.replace('/' , '.' )
219+ if (p.getNameCount > root.getNameCount + 1 ) {
220+ val packageDotted = p.subpath(1 + root.getNameCount, p.getNameCount).toString.replace('/' , '.' )
236221 index.getOrElseUpdate(packageDotted, new collection.mutable.ListBuffer ) += p
237222 }
238223 })
0 commit comments