Skip to content

Commit

Permalink
Merge cb77206 into b3a9500
Browse files Browse the repository at this point in the history
  • Loading branch information
RCMartins committed Mar 2, 2021
2 parents b3a9500 + cb77206 commit 81c73e3
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 15 deletions.
16 changes: 15 additions & 1 deletion blinky-cli/src/main/scala/blinky/run/Instruction.scala
@@ -1,6 +1,6 @@
package blinky.run

import ammonite.ops.Path
import ammonite.ops.{Path, RelPath}

sealed trait Instruction[+A]

Expand Down Expand Up @@ -63,6 +63,13 @@ object Instruction {

final case class IsFile[A](path: Path, next: Boolean => Instruction[A]) extends Instruction[A]

final case class CopyRelativeFiles[A](
filesToCopy: Seq[RelPath],
fromPath: Path,
toPath: Path,
next: Instruction[A]
) extends Instruction[A]

final case class Timeout[+A](
runFunction: Instruction[Boolean],
millis: Long,
Expand Down Expand Up @@ -141,6 +148,13 @@ object Instruction {
def readFile(path: Path): ReadFile[Either[Throwable, String]] =
ReadFile(path, succeed(_: Either[Throwable, String]))

def copyRelativeFiles(
filesToCopy: Seq[RelPath],
fromPath: Path,
toPath: Path
): CopyRelativeFiles[Unit] =
CopyRelativeFiles(filesToCopy, fromPath, toPath, succeed(()))

def runWithTimeout(
runFunction: Instruction[Boolean],
millis: Long
Expand Down
3 changes: 3 additions & 0 deletions blinky-cli/src/main/scala/blinky/run/Interpreter.scala
Expand Up @@ -84,6 +84,9 @@ object Interpreter {
case IsFile(path, next) =>
val isFile = externalCalls.isFile(path)
interpreterNext(next(isFile))
case CopyRelativeFiles(filesToCopy, fromPath, toPath, next) =>
externalCalls.copyRelativeFiles(filesToCopy, fromPath, toPath)
interpreterNext(next)
case timeout @ Timeout(_, _, _) =>
Left(timeout)
}
Expand Down
15 changes: 2 additions & 13 deletions blinky-cli/src/main/scala/blinky/run/Run.scala
@@ -1,6 +1,6 @@
package blinky.run

import ammonite.ops.{Path, RelPath, up}
import ammonite.ops.{Path, RelPath}
import blinky.BuildInfo
import blinky.run.Instruction._
import blinky.run.config.{MutationsConfigValidated, SimpleBlinkyConfig}
Expand Down Expand Up @@ -55,18 +55,7 @@ object Run {
path = originalProjectPath
).map(_.right.get)
filesToCopy = gitResult.split(System.lineSeparator()).map(RelPath(_))
_ <- filesToCopy.foldLeft(succeed(()): Instruction[Unit]) {
(before, fileToCopy) =>
before.flatMap(_ =>
MakeDirectory(
projectRealPath / fileToCopy / up,
copyInto(
originalProjectRoot / fileToCopy,
projectRealPath / fileToCopy / up
)
)
)
}
_ <- copyRelativeFiles(filesToCopy, originalProjectRoot, projectRealPath)
} yield ()

// Setup files to mutate ('scalafix --diff' does not work like I want...)
Expand Down
Expand Up @@ -52,4 +52,14 @@ object AmmoniteExternalCalls extends ExternalCalls {
def isFile(path: Path): Boolean =
path.isFile

def copyRelativeFiles(
filesToCopy: Seq[RelPath],
fromPath: Path,
toPath: Path
): Unit =
filesToCopy.foreach { fileToCopy =>
makeDirectory(toPath / fileToCopy / up)
copyInto(fromPath / fileToCopy, toPath / fileToCopy / up)
}

}
@@ -1,6 +1,6 @@
package blinky.run.external

import ammonite.ops.Path
import ammonite.ops.{Path, RelPath}

trait ExternalCalls {

Expand Down Expand Up @@ -30,4 +30,10 @@ trait ExternalCalls {

def isFile(path: Path): Boolean

def copyRelativeFiles(
filesToCopy: Seq[RelPath],
fromPath: Path,
toPath: Path
): Unit

}
2 changes: 2 additions & 0 deletions blinky-cli/src/main/scala/blinky/run/package.scala
Expand Up @@ -43,6 +43,8 @@ package object run {
ReadFile(path, next(_: Either[Throwable, String]).flatMap(f))
case IsFile(path, next) =>
IsFile(path, next(_: Boolean).flatMap(f))
case CopyRelativeFiles(filesToCopy, fromPath, toPath, next) =>
CopyRelativeFiles(filesToCopy, fromPath, toPath, next.flatMap(f))
case Timeout(runFunction, millis, next) =>
Timeout(runFunction, millis, next(_: Option[Boolean]).flatMap(f))
}
Expand Down

0 comments on commit 81c73e3

Please sign in to comment.