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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a new copy-file-with-options scripted test command #6657

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ package sbt
package internal
package scripted

import java.io.File
import sbt.io.{ IO, Path }
import sbt.io.Path._
import sbt.io.syntax._
import Path._
import sbt.io.{ CopyOptions, IO }

import java.io.File

class FileCommands(baseDirectory: File) extends BasicStatementHandler {
lazy val commands = commandMap
def commandMap =
lazy val commands: Map[String, List[String] => Unit] = commandMap
def commandMap: Map[String, List[String] => Unit] =
Map(
"touch" nonEmpty touch _,
"delete" nonEmpty delete _,
Expand All @@ -35,7 +36,17 @@ class FileCommands(baseDirectory: File) extends BasicStatementHandler {
"sleep".oneArg("Time in milliseconds", time => Thread.sleep(time.toLong)),
"exec" nonEmpty (execute _),
"copy" copy (to => rebase(baseDirectory, to)),
"copy-file".twoArg("Two paths", copyFile _),
"copy-file".twoArg("Two paths", (from, to) => copyFile(from, to)),
"copy-file-with-options".fiveArg(
"Copy files options and file paths",
(
overwrite,
preserveLastModified,
preserveExecutable,
from,
to
) => copyFileWithOptions(from, to)(overwrite, preserveLastModified, preserveExecutable)
),
"must-mirror".twoArg("Two paths", diffFiles _),
"copy-flat" copy flat
)
Expand All @@ -54,8 +65,22 @@ class FileCommands(baseDirectory: File) extends BasicStatementHandler {
def delete(paths: List[String]): Unit = IO.delete(fromStrings(paths))
/*def sync(from: String, to: String) =
IO.sync(fromString(from), fromString(to), log)*/
def copyFile(from: String, to: String): Unit =
IO.copyFile(fromString(from), fromString(to))
def copyFile(from: String, to: String, options: CopyOptions = CopyOptions()): Unit =
IO.copyFile(fromString(from), fromString(to), options)
def copyFileWithOptions(from: String, to: String)(
overwrite: String,
preserveLastModified: String,
preserveExecutable: String,
) =
copyFile(
from,
to,
CopyOptions(
overwrite = overwrite.toBoolean,
preserveLastModified = preserveLastModified.toBoolean,
preserveExecutable = preserveExecutable.toBoolean
)
)
def makeDirectories(paths: List[String]) =
IO.createDirectories(fromStrings(paths))
def diffFiles(file1: String, file2: String): Unit = {
Expand Down Expand Up @@ -109,6 +134,14 @@ class FileCommands(baseDirectory: File) extends BasicStatementHandler {
else
action(paths)
}
def fiveArg(
requiredArgs: String,
action: (String, String, String, String, String) => Unit
): NamedCommand =
commandName -> {
case List(a, b, c, d, e) => action(a, b, c, d, e)
case other => wrongArguments(requiredArgs, other)
}
def twoArg(requiredArgs: String, action: (String, String) => Unit): NamedCommand =
commandName -> {
case List(from, to) => action(from, to)
Expand Down