Ensure correct scripted plugin implementation exists

When running the scripted tests on my vm, I noticed that one of the
watch tests warned that the InstrumentScripted.scala file had changed
after the project had initialized. The test then hung and I had to kill
it. To try and prevent this from happening, I moved the creation of the
plugin file to right before the call to ";reload;setUpScripted".
This commit is contained in:
Ethan Atkins 2019-08-15 17:07:24 -07:00
parent 3b0171a50a
commit e621ebe678
1 changed files with 8 additions and 2 deletions

View File

@ -19,12 +19,14 @@ import scala.collection.parallel.ForkJoinTaskSupport
import scala.util.control.NonFatal import scala.util.control.NonFatal
import sbt.internal.scripted._ import sbt.internal.scripted._
import sbt.internal.io.Resources import sbt.internal.io.Resources
import sbt.internal.util.{ BufferedLogger, FullLogger, ConsoleOut } import sbt.internal.util.{ BufferedLogger, ConsoleOut, FullLogger }
import sbt.io.syntax._ import sbt.io.syntax._
import sbt.io.{ DirectoryFilter, HiddenFileFilter, IO } import sbt.io.{ DirectoryFilter, HiddenFileFilter, IO }
import sbt.io.FileFilter._ import sbt.io.FileFilter._
import sbt.util.{ AbstractLogger, Level, Logger } import sbt.util.{ AbstractLogger, Level, Logger }
import scala.util.Try
final class ScriptedTests( final class ScriptedTests(
resourceBaseDirectory: File, resourceBaseDirectory: File,
bufferLog: Boolean, bufferLog: Boolean,
@ -325,7 +327,8 @@ final class ScriptedTests(
val runTest = () => { val runTest = () => {
// Reload and initialize (to reload contents of .sbtrc files) // Reload and initialize (to reload contents of .sbtrc files)
val pluginImplementation = createAutoPlugin(name) val pluginImplementation = createAutoPlugin(name)
IO.write(tempTestDir / "project" / "InstrumentScripted.scala", pluginImplementation) val pluginFile = tempTestDir / "project" / "InstrumentScripted.scala"
IO.write(pluginFile, pluginImplementation)
def sbtHandlerError = sys error "Missing sbt handler. Scripted is misconfigured." def sbtHandlerError = sys error "Missing sbt handler. Scripted is misconfigured."
val sbtHandler = handlers.getOrElse('>', sbtHandlerError) val sbtHandler = handlers.getOrElse('>', sbtHandlerError)
val commandsToRun = ";reload;setUpScripted" val commandsToRun = ";reload;setUpScripted"
@ -334,6 +337,9 @@ final class ScriptedTests(
// Run reload inside the hook to reuse error handling for pending tests // Run reload inside the hook to reuse error handling for pending tests
val wrapHook = (file: File) => { val wrapHook = (file: File) => {
preHook(file) preHook(file)
while (!Try(IO.read(pluginFile)).toOption.contains(pluginImplementation)) {
IO.write(pluginFile, pluginImplementation)
}
try runner.processStatement(sbtHandler, statement, states) try runner.processStatement(sbtHandler, statement, states)
catch { catch {
case t: Throwable => case t: Throwable =>