diff options
Diffstat (limited to 'examples/scala-js/tools/jvm/src/main/scala/scala/scalajs/tools/classpath/builder/PhysicalFileSystem.scala')
-rw-r--r-- | examples/scala-js/tools/jvm/src/main/scala/scala/scalajs/tools/classpath/builder/PhysicalFileSystem.scala | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/examples/scala-js/tools/jvm/src/main/scala/scala/scalajs/tools/classpath/builder/PhysicalFileSystem.scala b/examples/scala-js/tools/jvm/src/main/scala/scala/scalajs/tools/classpath/builder/PhysicalFileSystem.scala new file mode 100644 index 0000000..a0dd7a5 --- /dev/null +++ b/examples/scala-js/tools/jvm/src/main/scala/scala/scalajs/tools/classpath/builder/PhysicalFileSystem.scala @@ -0,0 +1,41 @@ +package scala.scalajs.tools.classpath.builder + +import scala.scalajs.tools.io._ + +import scala.collection.immutable.Traversable + +import java.io._ + +/** FileSystem implementation using java.io._ */ +trait PhysicalFileSystem extends FileSystem { + + type File = java.io.File + + val DummyVersion: String = "DUMMY_FILE" + + def isDirectory(f: File): Boolean = f.isDirectory + def isFile(f: File): Boolean = f.isFile + def isJSFile(f: File): Boolean = f.isFile && f.getName.endsWith(".js") + def isIRFile(f: File): Boolean = f.isFile && f.getName.endsWith(".sjsir") + def isJARFile(f: File): Boolean = f.isFile && f.getName.endsWith(".jar") + def exists(f: File): Boolean = f.exists + + def getName(f: File): String = f.getName + def getAbsolutePath(f: File): String = f.getAbsolutePath + def getVersion(f: File): String = f.lastModified.toString + + def listFiles(d: File): Traversable[File] = { + require(d.isDirectory) + Option(d.listFiles).map(_.toList).getOrElse { + throw new IOException(s"Couldn't list files in $d") + } + } + + def toJSFile(f: File): VirtualJSFile = FileVirtualJSFile(f) + def toIRFile(f: File): VirtualScalaJSIRFile = FileVirtualScalaJSIRFile(f) + def toReader(f: File): Reader = + new BufferedReader(new FileReader(f)) + def toInputStream(f: File): InputStream = + new BufferedInputStream(new FileInputStream(f)) + +} |