Permalink
Browse files

Print message at regular intervals when proguard is running

So that Travis CI doesn't think the build is stalled
  • Loading branch information...
alexarchambault committed Nov 5, 2018
1 parent 4904669 commit 0496abf4a14ce4efa44217fbbf710ce96bf0e036
Showing with 95 additions and 53 deletions.
  1. +41 −39 build.sbt
  2. +54 −14 project/Settings.scala
@@ -350,41 +350,39 @@ lazy val addBootstrapJarAsResource = {
}
}
lazy val addBootstrapInProguardedJar = {
lazy val proguardedJarWithBootstrap = Def.task {
import java.nio.charset.StandardCharsets
import java.nio.file.Files
proguard.in(Proguard) := {
val bootstrapJar = packageBin.in(bootstrap).in(Compile).value
val source = proguardedJar.value
val dest = source.getParentFile / (source.getName.stripSuffix(".jar") + "-with-bootstrap.jar")
val dest0 = source.getParentFile / (source.getName.stripSuffix(".jar") + "-with-bootstrap-and-prelude.jar")
// TODO Get from cli original JAR
val manifest =
s"""Manifest-Version: 1.0
|Implementation-Title: ${name.value}
|Implementation-Version: ${version.value}
|Specification-Vendor: ${organization.value}
|Specification-Title: ${name.value}
|Implementation-Vendor-Id: ${organization.value}
|Specification-Version: ${version.value}
|Implementation-URL: ${homepage.value.getOrElse("")}
|Implementation-Vendor: ${organization.value}
|Main-Class: ${mainClass.in(Compile).value.getOrElse(sys.error("Main class not found"))}
|""".stripMargin
ZipUtil.addToZip(source, dest, Seq(
"bootstrap.jar" -> Files.readAllBytes(bootstrapJar.toPath),
"META-INF/MANIFEST.MF" -> manifest.getBytes(StandardCharsets.UTF_8)
))
ZipUtil.addPrelude(dest, dest0)
Seq(dest0)
}
val bootstrapJar = packageBin.in(bootstrap).in(Compile).value
val source = proguardedJar.value
val dest = source.getParentFile / (source.getName.stripSuffix(".jar") + "-with-bootstrap.jar")
val dest0 = source.getParentFile / (source.getName.stripSuffix(".jar") + "-with-bootstrap-and-prelude.jar")
// TODO Get from cli original JAR
val manifest =
s"""Manifest-Version: 1.0
|Implementation-Title: ${name.value}
|Implementation-Version: ${version.value}
|Specification-Vendor: ${organization.value}
|Specification-Title: ${name.value}
|Implementation-Vendor-Id: ${organization.value}
|Specification-Version: ${version.value}
|Implementation-URL: ${homepage.value.getOrElse("")}
|Implementation-Vendor: ${organization.value}
|Main-Class: ${mainClass.in(Compile).value.getOrElse(sys.error("Main class not found"))}
|""".stripMargin
ZipUtil.addToZip(source, dest, Seq(
"bootstrap.jar" -> Files.readAllBytes(bootstrapJar.toPath),
"META-INF/MANIFEST.MF" -> manifest.getBytes(StandardCharsets.UTF_8)
))
ZipUtil.addPrelude(dest, dest0)
dest0
}
lazy val proguardedCli = Seq(
@@ -398,13 +396,6 @@ lazy val proguardedCli = Seq(
// keeping only scala.Symbol doesn't seem to be enough since the switch to proguard 6.0.x
"""-keep class scala.** { *; }"""
),
proguardOptions.in(Proguard) ++= {
if (sys.env.exists(_._1.startsWith("TRAVIS_")))
// still printing plenty of stuff in Travis, so that the build isn't assumed to be stalled
Nil
else
Seq("-dontnote")
},
javaOptions.in(Proguard, proguard) := Seq("-Xmx3172M"),
artifactPath.in(Proguard) := proguardDirectory.in(Proguard).value / "coursier-standalone.jar",
artifacts ++= {
@@ -413,10 +404,21 @@ lazy val proguardedCli = Seq(
else
Nil
},
addBootstrapInProguardedJar,
addProguardedJar
)
lazy val addProguardedJar = {
val extra = Def.taskDyn[Map[Artifact, File]] {
if (scalaBinaryVersion.value == "2.12")
Def.task(Map(proguardedArtifact.value -> proguardedJarWithBootstrap.value))
else
Def.task(Map())
}
packagedArtifacts ++= extra.value
}
lazy val sharedTestResources = {
unmanagedResourceDirectories.in(Test) ++= {
val baseDir = baseDirectory.in(LocalRootProject).value
@@ -3,8 +3,9 @@ import java.nio.file.Files
import sbt._
import sbt.Keys._
import sbt.ScriptedPlugin.autoImport.{sbtLauncher, scriptedBufferLog, ScriptedLaunchConf, scriptedLaunchOpts}
import sbt.ScriptedPlugin.autoImport.{scriptedBufferLog, scriptedLaunchOpts}
import com.lightbend.sbt.SbtProguard
import com.lightbend.sbt.SbtProguard.autoImport._
import com.typesafe.sbt.pgp._
import coursier.ShadingPlugin.autoImport._
@@ -237,9 +238,60 @@ object Settings {
)
}
// adapted from https://github.com/sbt/sbt-proguard/blob/2c502f961245a18677ef2af4220a39e7edf2f996/src/main/scala/com/typesafe/sbt/SbtProguard.scala#L83-L100
lazy val proguardTask: Def.Initialize[Task[Seq[File]]] = Def.task {
SbtProguard.writeConfiguration(proguardConfiguration.in(Proguard).value, proguardOptions.in(Proguard).value)
val proguardConfigurationValue = proguardConfiguration.in(Proguard).value
val javaOptionsInProguardValue = (javaOptions in proguard).value
val managedClasspathValue = managedClasspath.in(Proguard).value
val streamsValue = streams.value
val outputsValue = proguardOutputs.in(Proguard).value
val cachedProguard = FileFunction.cached(streams.value.cacheDirectory / "proguard", FilesInfo.hash) { _ =>
outputsValue foreach IO.delete
streamsValue.log.debug("Proguard configuration:")
proguardOptions.in(Proguard).value foreach (streamsValue.log.debug(_))
runProguard(proguardConfigurationValue, javaOptionsInProguardValue, managedClasspathValue.files, streamsValue.log)
outputsValue.toSet
}
val inputs = (proguardConfiguration.in(Proguard).value +: SbtProguard.inputFiles(proguardFilteredInputs.in(Proguard).value)).toSet
cachedProguard(inputs)
proguardOutputs.in(Proguard).value
}
def runProguard(config: File, javaOptions: Seq[String], classpath: Seq[File], log: Logger): Unit = {
require(classpath.nonEmpty, "Proguard classpath cannot be empty!")
val options = javaOptions ++ Seq("-cp", Path.makeString(classpath), "proguard.ProGuard", "-include", config.getAbsolutePath)
log.debug("Proguard command:")
log.debug("java " + options.mkString(" "))
val t = new Thread("proguard-sentinel") {
setDaemon(true)
override def run() =
try {
while (true) {
Thread.sleep(10000L)
scala.Console.err.println("Proguard still running")
}
} catch {
case _: InterruptedException =>
scala.Console.err.println("Proguard not running anymore")
// normal exit
}
}
try {
t.start()
val exitCode = sys.process.Process("java", options) ! log
if (exitCode != 0) sys.error("Proguard failed with exit code [%s]" format exitCode)
} finally {
if (t.isAlive)
t.interrupt()
}
}
lazy val proguardedJar = Def.task {
val results = proguard.in(Proguard).value
val results = proguardTask.value
results match {
case Seq(f) => f
@@ -250,18 +302,6 @@ object Settings {
}
}
lazy val addProguardedJar = {
val extra = Def.taskDyn[Map[Artifact, File]] {
if (scalaBinaryVersion.value == "2.12")
Def.task(Map(proguardedArtifact.value -> proguardedJar.value))
else
Def.task(Map())
}
packagedArtifacts ++= extra.value
}
lazy val Integration = config("it").extend(Test)
def runCommand(cmd: Seq[String], dir: File): Unit = {

0 comments on commit 0496abf

Please sign in to comment.