File tree 3 files changed +44
-42
lines changed
3 files changed +44
-42
lines changed Original file line number Diff line number Diff line change @@ -49,18 +49,16 @@ class GenBCode extends Phase {
49
49
superCallsMap.put(sym, old + calls)
50
50
}
51
51
52
- private [this ] var jarFS : JarFS = _
53
-
54
- def outputDir (implicit ctx : Context ): AbstractFile = {
55
- val path = Directory (ctx.settings.outputDir.value)
56
- if (path.extension == " jar" ) {
57
- if (jarFS == null ) {
58
- path.delete()
59
- jarFS = JarFS .create(path)
60
- }
61
- jarFS.getRoot()
52
+ private [this ] var myOutput : AbstractFile = _
53
+
54
+ protected def outputDir (implicit ctx : Context ): AbstractFile = {
55
+ if (myOutput eq null ) {
56
+ val path = Directory (ctx.settings.outputDir.value)
57
+ myOutput =
58
+ if (path.extension == " jar" ) JarArchive .create(path)
59
+ else new PlainDirectory (path)
62
60
}
63
- else new PlainDirectory (path)
61
+ myOutput
64
62
}
65
63
66
64
def run (implicit ctx : Context ): Unit = {
@@ -71,9 +69,10 @@ class GenBCode extends Phase {
71
69
72
70
override def runOn (units : List [CompilationUnit ])(implicit ctx : Context ) = {
73
71
try super .runOn(units)
74
- finally if (jarFS ne null ) {
75
- jarFS.close()
76
- jarFS = null
72
+ finally myOutput match {
73
+ case jar : JarArchive =>
74
+ jar.close()
75
+ case _ =>
77
76
}
78
77
}
79
78
}
Original file line number Diff line number Diff line change
1
+ package dotty .tools .io
2
+
3
+ import java .nio .file .{Files , FileSystem , FileSystems }
4
+
5
+ import scala .collection .JavaConverters ._
6
+
7
+ /**
8
+ * This class implements an [[AbstractFile ]] backed by a jar
9
+ * that be can used as the compiler's output directory.
10
+ */
11
+ class JarArchive private (root : Directory ) extends PlainDirectory (root) {
12
+ def close () = jpath.getFileSystem().close()
13
+ }
14
+
15
+ object JarArchive {
16
+ /** Create a new jar file. Overwrite if file already exists */
17
+ def create (path : Path ): JarArchive = {
18
+ require(path.extension == " jar" )
19
+
20
+ path.delete()
21
+
22
+ // creating a new zip file system by using the JAR URL syntax:
23
+ // https://docs.oracle.com/javase/7/docs/technotes/guides/io/fsp/zipfilesystemprovider.html
24
+ val env = Map (" create" -> " true" ).asJava
25
+ val uri = java.net.URI .create(" jar:file:" + path.toAbsolute.path)
26
+ val fs = FileSystems .newFileSystem(uri, env)
27
+
28
+ val root = fs.getRootDirectories().iterator.next()
29
+ new JarArchive (Directory (root))
30
+ }
31
+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments