12
12
13
13
package scala .tools .nsc .classpath
14
14
15
- import java .io .File
15
+ import java .io .{ Closeable , File }
16
16
import java .net .{URI , URL }
17
17
import java .nio .file .{FileSystems , Files , SimpleFileVisitor }
18
18
import java .util .function .IntFunction
@@ -25,6 +25,7 @@ import FileUtils._
25
25
import scala .collection .JavaConverters ._
26
26
import scala .collection .immutable
27
27
import scala .reflect .internal .JDK9Reflectors
28
+ import scala .tools .nsc .CloseableRegistry
28
29
import scala .tools .nsc .classpath .PackageNameUtils .{packageContains , separatePkgAndClassNames }
29
30
30
31
/**
@@ -61,6 +62,7 @@ trait DirectoryLookup[FileEntryType <: ClassRepresentation] extends ClassPath {
61
62
62
63
private [nsc] def packages (inPackage : String ): Seq [PackageEntry ] = {
63
64
val dirForPackage = getDirectory(inPackage)
65
+
64
66
val nestedDirs : Array [F ] = dirForPackage match {
65
67
case None => emptyFiles
66
68
case Some (directory) => listChildren(directory, Some (isPackage))
@@ -137,7 +139,7 @@ trait JFileDirectoryLookup[FileEntryType <: ClassRepresentation] extends Directo
137
139
138
140
object JrtClassPath {
139
141
import java .nio .file ._ , java .net .URI
140
- def apply (release : Option [String ]): Option [ClassPath ] = {
142
+ def apply (release : Option [String ], closeableRegistry : CloseableRegistry ): Option [ClassPath ] = {
141
143
import scala .util .Properties ._
142
144
if (! isJavaAtLeast(" 9" )) None
143
145
else {
@@ -154,7 +156,11 @@ object JrtClassPath {
154
156
try {
155
157
val ctSym = Paths .get(javaHome).resolve(" lib" ).resolve(" ct.sym" )
156
158
if (Files .notExists(ctSym)) None
157
- else Some (new CtSymClassPath (ctSym, v.toInt))
159
+ else {
160
+ val classPath = new CtSymClassPath (ctSym, v.toInt)
161
+ closeableRegistry.registerClosable(classPath)
162
+ Some (classPath)
163
+ }
158
164
} catch {
159
165
case _ : Throwable => None
160
166
}
@@ -230,7 +236,7 @@ final class JrtClassPath(fs: java.nio.file.FileSystem) extends ClassPath with No
230
236
/**
231
237
* Implementation `ClassPath` based on the $JAVA_HOME/lib/ct.sym backing http://openjdk.java.net/jeps/247
232
238
*/
233
- final class CtSymClassPath (ctSym : java.nio.file.Path , release : Int ) extends ClassPath with NoSourcePaths {
239
+ final class CtSymClassPath (ctSym : java.nio.file.Path , release : Int ) extends ClassPath with NoSourcePaths with Closeable {
234
240
import java .nio .file .Path , java .nio .file ._
235
241
236
242
private val fileSystem : FileSystem = FileSystems .newFileSystem(ctSym, null )
@@ -278,7 +284,7 @@ final class CtSymClassPath(ctSym: java.nio.file.Path, release: Int) extends Clas
278
284
279
285
def asURLs : Seq [URL ] = Nil
280
286
def asClassPathStrings : Seq [String ] = Nil
281
-
287
+ override def close () : Unit = fileSystem.close()
282
288
def findClassFile (className : String ): Option [AbstractFile ] = {
283
289
if (! className.contains(" ." )) None
284
290
else {
0 commit comments