diff --git a/os/src-jvm/ProcessOps.scala b/os/src-jvm/ProcessOps.scala index 981b6521..3766bb78 100644 --- a/os/src-jvm/ProcessOps.scala +++ b/os/src-jvm/ProcessOps.scala @@ -81,8 +81,8 @@ case class proc(command: Shellable*) { sub.join(timeout) - val chunksArr = chunks.iterator.asScala.toArray - val res = CommandResult(commandChunks, sub.exitCode(), chunksArr) + val chunksSeq = chunks.iterator.asScala.toIndexedSeq + val res = CommandResult(commandChunks, sub.exitCode(), chunksSeq) if (res.exitCode == 0 || !check) res else throw SubprocessException(res) } diff --git a/os/src-jvm/ResourcePath.scala b/os/src-jvm/ResourcePath.scala index cb97dde2..9a42de5f 100644 --- a/os/src-jvm/ResourcePath.scala +++ b/os/src-jvm/ResourcePath.scala @@ -2,6 +2,7 @@ package os import java.io.InputStream +import scala.language.implicitConversions object ResourcePath{ def resource(resRoot: ResourceRoot) = { @@ -21,7 +22,7 @@ class ResourcePath private[os](val resRoot: ResourceRoot, segments0: Array[Strin case stream => stream } def toSource = new Source.WritableSource(getInputStream) - val segments: IndexedSeq[String] = segments0 + val segments: IndexedSeq[String] = segments0.toIndexedSeq type ThisType = ResourcePath def lastOpt = segments0.lastOption override def toString = resRoot.errorName + "/" + segments0.mkString("/") diff --git a/os/src-jvm/SubProcess.scala b/os/src-jvm/SubProcess.scala index ac28d1c7..f8f36ffb 100644 --- a/os/src-jvm/SubProcess.scala +++ b/os/src-jvm/SubProcess.scala @@ -3,6 +3,8 @@ package os import java.io._ import java.util.concurrent.TimeUnit +import scala.language.implicitConversions + /** * Represents a spawn subprocess that has started and may or may not have * completed. diff --git a/os/src-jvm/package.scala b/os/src-jvm/package.scala index 08553a24..479ecd84 100644 --- a/os/src-jvm/package.scala +++ b/os/src-jvm/package.scala @@ -1,4 +1,6 @@ +import scala.language.implicitConversions + package object os{ type Generator[+T] = geny.Generator[T] val Generator = geny.Generator diff --git a/os/src/ListOps.scala b/os/src/ListOps.scala index 7268d234..e14fa084 100644 --- a/os/src/ListOps.scala +++ b/os/src/ListOps.scala @@ -15,12 +15,12 @@ import java.nio.file.attribute.BasicFileAttributes * them. You can disable sorted by passing in the flag `sort = false`. */ object list extends Function1[Path, IndexedSeq[Path]] { - def apply(src: Path, sort: Boolean = true) = { + def apply(src: Path, sort: Boolean = true): IndexedSeq[Path] = { val arr = stream(src).toArray[Path] if (sort) arr.sorted else arr } - def apply(src: Path) = apply(src, true) + def apply(src: Path): IndexedSeq[Path] = apply(src, true).toIndexedSeq /** * Similar to [[os.list]]], except provides a [[os.Generator]] of results @@ -90,7 +90,7 @@ object walk { followLinks: Boolean = false, maxDepth: Int = Int.MaxValue, includeTarget: Boolean = false): IndexedSeq[Path] = { - stream(path, skip, preOrder, followLinks, maxDepth, includeTarget).toArray[Path] + stream(path, skip, preOrder, followLinks, maxDepth, includeTarget).toArray[Path].toIndexedSeq } /** @@ -122,7 +122,7 @@ object walk { maxDepth: Int = Int.MaxValue, includeTarget: Boolean = false): IndexedSeq[(Path, os.StatInfo)] = { stream.attrs(path, skip, preOrder, followLinks, maxDepth, includeTarget) - .toArray[(Path, os.StatInfo)] + .toArray[(Path, os.StatInfo)].toIndexedSeq } object stream { diff --git a/os/src/Model.scala b/os/src/Model.scala index 0a35d19a..9601fce4 100644 --- a/os/src/Model.scala +++ b/os/src/Model.scala @@ -221,7 +221,7 @@ object Shellable{ Shellable(s.toSeq.flatMap(f(_).value)) implicit def ArrayShellable[T](s: Array[T])(implicit f: T => Shellable): Shellable = - Shellable(s.flatMap(f(_).value)) + Shellable(s.toIndexedSeq.flatMap(f(_).value)) } /** diff --git a/os/src/Path.scala b/os/src/Path.scala index ecc8a1ed..9580c798 100644 --- a/os/src/Path.scala +++ b/os/src/Path.scala @@ -1,6 +1,7 @@ package os import collection.JavaConverters._ +import scala.language.implicitConversions trait PathChunk{ def segments: Seq[String] @@ -30,7 +31,7 @@ object PathChunk{ override def toString() = s.name } implicit class ArrayPathChunk[T](a: Array[T])(implicit f: T => PathChunk) extends PathChunk { - val inner = SeqPathChunk(a)(f) + val inner = SeqPathChunk(a.toIndexedSeq)(f) def segments = inner.segments def ups = inner.ups @@ -250,7 +251,7 @@ object FilePath { class RelPath private[os](segments0: Array[String], val ups: Int) extends FilePath with BasePathImpl with SegmentedPath { def lastOpt = segments.lastOption - val segments: IndexedSeq[String] = segments0 + val segments: IndexedSeq[String] = segments0.toIndexedSeq type ThisType = RelPath require(ups >= 0) protected[this] def make(p: Seq[String], ups: Int) = { @@ -316,14 +317,15 @@ object RelPath { class SubPath private[os](val segments0: Array[String]) extends FilePath with BasePathImpl with SegmentedPath { def lastOpt = segments.lastOption - val segments: IndexedSeq[String] = segments0 + val segments: IndexedSeq[String] = segments0.toIndexedSeq type ThisType = SubPath protected[this] def make(p: Seq[String], ups: Int) = { require(ups == 0) new SubPath(p.toArray[String]) } - def relativeTo(base: SubPath): RelPath = SubPath.relativeTo0(segments0, base.segments0) + def relativeTo(base: SubPath): RelPath = + SubPath.relativeTo0(segments0, base.segments0.toIndexedSeq) def startsWith(target: SubPath) = this.segments0.startsWith(target.segments) diff --git a/os/src/ReadWriteOps.scala b/os/src/ReadWriteOps.scala index e2f7c168..0db00746 100644 --- a/os/src/ReadWriteOps.scala +++ b/os/src/ReadWriteOps.scala @@ -327,9 +327,9 @@ object read extends Function1[ReadablePath, String]{ * can override by specifying a `charSet`. */ object lines extends Function1[ReadablePath, IndexedSeq[String]]{ - def apply(src: ReadablePath) = stream(src).toArray[String] + def apply(src: ReadablePath): IndexedSeq[String] = stream(src).toArray[String].toIndexedSeq def apply(arg: ReadablePath, charSet: Codec): IndexedSeq[String] = - stream(arg, charSet).toArray[String] + stream(arg, charSet).toArray[String].toIndexedSeq /** * Identical to [[os.read.lines]], but streams the results back to you diff --git a/os/src/Source.scala b/os/src/Source.scala index 96feade7..641b521a 100644 --- a/os/src/Source.scala +++ b/os/src/Source.scala @@ -15,6 +15,7 @@ import java.nio.channels.{ WritableByteChannel } +import scala.language.implicitConversions /** * A source of bytes; must provide either an [[InputStream]] or a diff --git a/os/test/src-jvm/ExampleTests.scala b/os/test/src-jvm/ExampleTests.scala index 70e41c83..0ae13b34 100644 --- a/os/test/src-jvm/ExampleTests.scala +++ b/os/test/src-jvm/ExampleTests.scala @@ -271,7 +271,7 @@ object ExampleTests extends TestSuite{ .filter(_._2.length > 0) .filter(!_._1.segments.contains("src_managed")) - assert(filesWithTooLongLines.length == 0) + Predef.assert(filesWithTooLongLines.length == 0, filesWithTooLongLines) } test("rename"){ // val d1/"omg"/x1 = wd diff --git a/os/test/src-jvm/SubprocessTests.scala b/os/test/src-jvm/SubprocessTests.scala index d5f50fb5..298be804 100644 --- a/os/test/src-jvm/SubprocessTests.scala +++ b/os/test/src-jvm/SubprocessTests.scala @@ -11,11 +11,11 @@ import scala.collection.mutable object SubprocessTests extends TestSuite{ val scriptFolder = pwd/"os"/"test"/"resources"/"test" - val lsCmd = if(scala.util.Properties.isWin) "dir" else "ls" + val lsCmd = if (scala.util.Properties.isWin) "dir" else "ls" val tests = Tests { test("lines"){ - val res = proc(lsCmd, scriptFolder).call() + val res = TestUtil.proc(lsCmd, scriptFolder).call() assert( res.out.lines().exists(_.contains("File.txt")), res.out.lines().exists(_.contains("folder1")), @@ -23,11 +23,11 @@ object SubprocessTests extends TestSuite{ ) } test("string"){ - val res = proc(lsCmd, scriptFolder).call() + val res = TestUtil.proc(lsCmd, scriptFolder).call() assert( - res.out.string().contains("File.txt"), - res.out.string().contains("folder1"), - res.out.string().contains("folder2") + res.out.text().contains("File.txt"), + res.out.text().contains("folder1"), + res.out.text().contains("folder2") ) } test("bytes"){ @@ -39,33 +39,33 @@ object SubprocessTests extends TestSuite{ } test("chained"){ assert( - proc("git", "init").call().out.string().contains("Reinitialized existing Git repository"), - proc("git", "init").call().out.string().contains("Reinitialized existing Git repository"), - proc(lsCmd, pwd).call().out.string().contains("readme.md") + proc("git", "init").call().out.text().contains("Reinitialized existing Git repository"), + proc("git", "init").call().out.text().contains("Reinitialized existing Git repository"), + TestUtil.proc(lsCmd, pwd).call().out.text().contains("readme.md") ) } test("basicList"){ val files = List("readme.md", "build.sc") - val output = proc(lsCmd, files).call().out.string() + val output = TestUtil.proc(lsCmd, files).call().out.text() assert(files.forall(output.contains)) } test("listMixAndMatch"){ val stuff = List("I", "am", "bovine") val result = TestUtil.proc("echo", "Hello,", stuff, "hear me roar").call() if(Unix()) - assert(result.out.string().contains("Hello, " + stuff.mkString(" ") + " hear me roar")) + assert(result.out.text().contains("Hello, " + stuff.mkString(" ") + " hear me roar")) else // win quotes multiword args - assert(result.out.string().contains("Hello, " + stuff.mkString(" ") + " \"hear me roar\"")) + assert(result.out.text().contains("Hello, " + stuff.mkString(" ") + " \"hear me roar\"")) } test("failures"){ val ex = intercept[os.SubprocessException]{ - proc(lsCmd, "does-not-exist").call(check = true, stderr = os.Pipe) + TestUtil.proc(lsCmd, "does-not-exist").call(check = true, stderr = os.Pipe) } val res: CommandResult = ex.result assert( res.exitCode != 0, - res.err.string().contains("No such file or directory") || // unix - res.err.string().contains("File Not Found") // win + res.err.text().contains("No such file or directory") || // unix + res.err.text().contains("File Not Found") // win ) } @@ -78,7 +78,7 @@ object SubprocessTests extends TestSuite{ env = Map("ENV_ARG" -> "123") ) - assert(res.out.string().trim()== "Hello123") + assert(res.out.text().trim()== "Hello123") } } test("filebased2"){ @@ -86,7 +86,7 @@ object SubprocessTests extends TestSuite{ val possiblePaths = Seq(root / "bin", root / "usr" / "bin").map { pfx => pfx / "echo" } val res = proc("which", "echo").call() - val echoRoot = Path(res.out.string().trim()) + val echoRoot = Path(res.out.text().trim()) assert(possiblePaths.contains(echoRoot)) assert(proc(echoRoot, "HELLO").call().out.lines() == Seq("HELLO")) @@ -121,14 +121,14 @@ object SubprocessTests extends TestSuite{ | # Vary how close they are together to try and trigger race conditions | time.sleep(0.00001 * i) | sys.stdout.flush() - """.stripMargin).call().out.string() ==> + """.stripMargin).call().out.text() ==> "01234567890123456789012345678901234567890123456789" }} test("jarTf"){ // This was the original repro for the multi-chunk concurrency bugs val jarFile = os.pwd / "os" / "test" / "resources" / "misc" / "out.jar" assert(TestUtil.eqIgnoreNewlineStyle( - os.proc("jar", "-tf", jarFile).call().out.string(), + os.proc("jar", "-tf", jarFile).call().out.text(), """META-INF/MANIFEST.MF |test/FooTwo.class |test/Bar.class @@ -141,15 +141,15 @@ object SubprocessTests extends TestSuite{ } } test("workingDirectory"){ - val listed1 = proc(lsCmd).call(cwd = pwd) - val listed2 = proc(lsCmd).call(cwd = pwd / up) + val listed1 = TestUtil.proc(lsCmd).call(cwd = pwd) + val listed2 = TestUtil.proc(lsCmd).call(cwd = pwd / up) assert(listed2 != listed1) } test("customWorkingDir"){ - val res1 = proc(lsCmd).call(cwd = pwd) // explicitly + val res1 = TestUtil.proc(lsCmd).call(cwd = pwd) // explicitly // or implicitly - val res2 = proc(lsCmd).call() + val res2 = TestUtil.proc(lsCmd).call() } test("fileCustomWorkingDir"){ diff --git a/os/watch/src/CarbonApi.scala b/os/watch/src/CarbonApi.scala index be67fa9a..1a607813 100644 --- a/os/watch/src/CarbonApi.scala +++ b/os/watch/src/CarbonApi.scala @@ -5,7 +5,7 @@ import com.sun.jna._ import com.sun.jna.ptr.PointerByReference object CarbonApi { - val INSTANCE = Native.loadLibrary("Carbon", classOf[CarbonApi]).asInstanceOf[CarbonApi] + val INSTANCE = Native.load("Carbon", classOf[CarbonApi]).asInstanceOf[CarbonApi] } trait FSEventStreamCallback extends Callback {