<commit_before>package com.earldouglas.xwp

import sbt._
import Keys._
import java.io.File
import java.util.concurrent.atomic.AtomicReference

trait ContainerPlugin { self: WebappPlugin =>

  lazy val container  = config("container").hide
  lazy val start      = TaskKey[Process]("start")
  lazy val stop       = TaskKey[Unit]("stop")
  lazy val launchCmd  = TaskKey[Seq[String]]("launch-cmd")
  lazy val options    = TaskKey[ForkOptions]("options")

  private def shutdown(l: Logger, atomicRef: AtomicReference[Option[Process]]): Unit = {
    val oldProcess = atomicRef.getAndSet(None)
    oldProcess.foreach(stopProcess(l))
  }

  private def stopProcess(l: Logger)(p: Process): Unit = {
    l.info("waiting for server to shut down...")
    p.destroy
    p.exitValue
  }

  private def startup(
    l: Logger, libs: Seq[File], args: Seq[String], forkOptions: ForkOptions
  ): Process = {
    l.info("starting server ...")
    val cp = libs mkString File.pathSeparator
    Fork.java.fork(forkOptions, Seq("-cp", cp) ++ args)
  }

  def startTask(atomicRef: AtomicReference[Option[Process]]): Def.Initialize[Task[Process]] =
    (  launchCmd in container
     , javaOptions in container
     , classpathTypes in container
     , update in container
     , options in container
     , streams
    ) map {
      (  launchCmd<commit_msg>Suppress sbt's stderr when waiting for exit<commit_after>package com.earldouglas.xwp

import sbt._
import Keys._
import java.io.File
import java.util.concurrent.atomic.AtomicReference

trait ContainerPlugin { self: WebappPlugin =>

  lazy val container  = config("container").hide
  lazy val start      = TaskKey[Process]("start")
  lazy val stop       = TaskKey[Unit]("stop")
  lazy val launchCmd  = TaskKey[Seq[String]]("launch-cmd")
  lazy val options    = TaskKey[ForkOptions]("options")

  private def shutdown(l: Logger, atomicRef: AtomicReference[Option[Process]]): Unit = {
    val oldProcess = atomicRef.getAndSet(None)
    oldProcess.foreach(stopProcess(l))
  }

  private def stopProcess(l: Logger)(p: Process): Unit = {
    l.info("waiting for server to shut down...")
    p.destroy()
    val err = System.err
    val devNull: java.io.PrintStream =
      new java.io.PrintStream(
        new java.io.OutputStream {
          def write(b: Int): Unit = {}
        }
      )
    System.setErr(devNull)
    p.exitValue()
    System.setErr(err)
  }

  private def startup(
    l: Logger, libs: Seq[File], args: Seq[String], forkOptions: ForkOptions
  ): Process = {
    l.info("starting server ...")
    val cp = libs mkString File.pathSeparator
    new Fork("java", None).fork(forkOptions, Seq("-cp", cp) ++ args)
  }

  def startTask(atomicRef: AtomicReference[Option[Process]]): Def.Initialize[Task[Process]] =
    (  launchCmd in container
     , javaOptions in container
     , classpathTypes in container
     , update in container
     , options in container
     , streams
    ) map {
      (  launchCmd
{'fraction_non_alphanumeric': 0.11991869918699187, 'fraction_numerical': 0.0, 'mean_word_length': 3.394345238095238, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4416000', 'n_tokens_mistral': 927, 'n_tokens_neox': 918, 'n_words': 231}