Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compilation warnings #104

Merged
merged 5 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions os/src-jvm/ProcessOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion os/src-jvm/ResourcePath.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package os

import java.io.InputStream

import scala.language.implicitConversions

object ResourcePath{
def resource(resRoot: ResourceRoot) = {
Expand All @@ -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("/")
Expand Down
2 changes: 2 additions & 0 deletions os/src-jvm/SubProcess.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions os/src-jvm/package.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

import scala.language.implicitConversions

package object os{
type Generator[+T] = geny.Generator[T]
val Generator = geny.Generator
Expand Down
8 changes: 4 additions & 4 deletions os/src/ListOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

/**
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion os/src/Model.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

/**
Expand Down
10 changes: 6 additions & 4 deletions os/src/Path.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package os

import collection.JavaConverters._
import scala.language.implicitConversions

trait PathChunk{
def segments: Seq[String]
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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) = {
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions os/src/ReadWriteOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions os/src/Source.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import java.nio.channels.{
WritableByteChannel
}

import scala.language.implicitConversions

/**
* A source of bytes; must provide either an [[InputStream]] or a
Expand Down
2 changes: 1 addition & 1 deletion os/test/src-jvm/ExampleTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
lefou marked this conversation as resolved.
Show resolved Hide resolved
}
test("rename"){
// val d1/"omg"/x1 = wd
Expand Down
46 changes: 23 additions & 23 deletions os/test/src-jvm/SubprocessTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ 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")),
res.out.lines().exists(_.contains("folder2"))
)
}
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"){
Expand All @@ -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
)
}

Expand All @@ -78,15 +78,15 @@ object SubprocessTests extends TestSuite{
env = Map("ENV_ARG" -> "123")
)

assert(res.out.string().trim()== "Hello123")
assert(res.out.text().trim()== "Hello123")
}
}
test("filebased2"){
if(Unix()){
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"))
Expand Down Expand Up @@ -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
Expand All @@ -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"){
Expand Down
2 changes: 1 addition & 1 deletion os/watch/src/CarbonApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down