Skip to content

Commit 3691edb

Browse files
committed
Remove IOUtils
1 parent deddb38 commit 3691edb

File tree

4 files changed

+22
-46
lines changed

4 files changed

+22
-46
lines changed

compiler/src/dotty/tools/io/Directory.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ object Directory {
2323
if (userDir == "") None
2424
else Some(apply(userDir).normalize)
2525

26+
def inTempDirectory[T](fn: Directory => T): T = {
27+
val temp = Directory(Files.createTempDirectory("temp"))
28+
try fn(temp)
29+
finally temp.deleteRecursively()
30+
}
31+
2632
def apply(path: String): Directory = apply(Paths.get(path))
2733
def apply(path: JPath): Directory = new Directory(path)
2834
}

compiler/test/dotty/tools/IOUtils.scala

Lines changed: 0 additions & 27 deletions
This file was deleted.

compiler/test/dotty/tools/dotc/core/tasty/CommentPicklingTest.scala

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ import dotty.tools.dotc.core.Mode
1010
import dotty.tools.dotc.core.Names.Name
1111
import dotty.tools.dotc.interfaces.Diagnostic.ERROR
1212
import dotty.tools.dotc.reporting.TestReporter
13-
import dotty.tools.IOUtils
13+
import dotty.tools.io.{Directory, File, Path}
1414

1515
import dotty.tools.vulpix.TestConfiguration
1616

17-
import java.nio.file.{Files, Path}
18-
1917
import org.junit.Test
2018
import org.junit.Assert.{assertEquals, assertFalse, fail}
2119

@@ -81,25 +79,25 @@ class CommentPicklingTest {
8179
}
8280

8381
private def compileAndUnpickle[T](sources: List[String])(fn: (List[tpd.Tree], Context) => T) = {
84-
IOUtils.inTempDirectory { tmp =>
82+
Directory.inTempDirectory { tmp =>
8583
val sourceFiles = sources.zipWithIndex.map {
8684
case (src, id) =>
87-
val path = tmp.resolve(s"Src$id.scala").toAbsolutePath
88-
Files.write(path, src.getBytes("UTF-8"))
85+
val path = tmp./(File("Src$id.scala")).toAbsolute
86+
path.writeAll(src)
8987
path.toString
9088
}
9189

92-
val out = tmp.resolve("out")
93-
Files.createDirectories(out)
90+
val out = tmp./("out")
91+
out.createDirectory()
9492

95-
val options = compileOptions.and("-d", out.toAbsolutePath.toString).and(sourceFiles: _*)
93+
val options = compileOptions.and("-d", out.toAbsolute.toString).and(sourceFiles: _*)
9694
val reporter = TestReporter.reporter(System.out, logLevel = ERROR)
9795
Main.process(options.all, reporter)
9896
assertFalse("Compilation failed.", reporter.hasErrors)
9997

100-
val tastyFiles = IOUtils.getAll(tmp, "glob:**.tasty")
98+
val tastyFiles = Path.onlyFiles(out.walkFilter(_.extension == "tasty")).toList
10199
val unpicklingOptions = unpickleOptions
102-
.withClasspath(out.toAbsolutePath.toString)
100+
.withClasspath(out.toAbsolute.toString)
103101
.and("dummy") // Need to pass a dummy source file name
104102
val unpicklingDriver = new UnpicklingDriver
105103
unpicklingDriver.unpickle(unpicklingOptions.all, tastyFiles)(fn)
@@ -108,12 +106,11 @@ class CommentPicklingTest {
108106

109107
private class UnpicklingDriver extends Driver {
110108
override def initCtx = super.initCtx.addMode(Mode.ReadComments)
111-
def unpickle[T](args: Array[String], paths: List[Path])(fn: (List[tpd.Tree], Context) => T): T = {
109+
def unpickle[T](args: Array[String], files: List[File])(fn: (List[tpd.Tree], Context) => T): T = {
112110
implicit val (_, ctx: Context) = setup(args, initCtx)
113111
ctx.initialize()
114-
val trees = paths.flatMap { p =>
115-
val bytes = Files.readAllBytes(p)
116-
val unpickler = new DottyUnpickler(bytes)
112+
val trees = files.flatMap { f =>
113+
val unpickler = new DottyUnpickler(f.bytes.toArray)
117114
unpickler.enter(roots = Set.empty)
118115
unpickler.trees(ctx)
119116
}

doc-tool/test/DottyDocTest.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import dotty.tools.dottydoc.util.syntax._
1313
import dotty.tools.io.AbstractFile
1414
import dotc.reporting.{ StoreReporter, MessageRendering }
1515
import dotc.interfaces.Diagnostic.ERROR
16+
import io.Directory
1617
import org.junit.Assert.fail
1718

1819
import java.io.{ BufferedWriter, OutputStreamWriter }
19-
import java.nio.file.{Files => JFiles}
2020

2121
trait DottyDocTest extends MessageRendering {
2222
dotty.tools.dotc.parsing.Scanners // initialize keywords
@@ -102,10 +102,10 @@ trait DottyDocTest extends MessageRendering {
102102
}
103103

104104
def checkFromTasty(classNames: List[String], sources: List[SourceFile])(assertion: (Context, Map[String, Package]) => Unit): Unit = {
105-
IOUtils.inTempDirectory { tmp =>
105+
Directory.inTempDirectory { tmp =>
106106
val ctx = "shadow ctx"
107-
val out = tmp.resolve("out")
108-
JFiles.createDirectories(out)
107+
val out = tmp./(Directory("out"))
108+
out.createDirectory()
109109

110110
val dotcCtx = {
111111
val ctx = freshCtx(out.toString :: Nil)

0 commit comments

Comments
 (0)