Skip to content

Commit

Permalink
support sbt 1.5.x FixedTimestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Apr 1, 2021
1 parent 67df9ad commit a8e2913
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/main/scala/sbtassembly/Assembly.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,55 @@ object Assembly {
def makeJar(outPath: File): Unit = {
import Package._
import collection.JavaConverters._
import scala.language.reflectiveCalls
val manifest = new Manifest
val main = manifest.getMainAttributes.asScala
var time: Option[Long] = None
for(option <- po) {
option match {
case JarManifest(mergeManifest) => Package.mergeManifests(manifest, mergeManifest)
case MainClass(mainClassName) => main.put(Attributes.Name.MAIN_CLASS, mainClassName)
case ManifestAttributes(attrs @ _*) => main ++= attrs
case _ => log.warn("Ignored unknown package option " + option)
case _ =>
// use reflection for compatibility
if (option.getClass.getName == "sbt.Package$FixedTimestamp") {
try {
// https://github.com/sbt/sbt/blob/59130d4703e9238e/main-actions/src/main/scala/sbt/Package.scala#L50
time = option.asInstanceOf[{def value: Option[Long]}].value
} catch {
case e: Throwable =>
log.debug(e.toString)
}
} else {
log.warn("Ignored unknown package option " + option)
}
}
}
if (time.isEmpty) {
Package.makeJar(ms, outPath, manifest, log)
} else {
try {
// https://github.com/sbt/sbt/blob/59130d4703e9238e/main-actions/src/main/scala/sbt/Package.scala#L213-L219
Package.asInstanceOf[ {
def makeJar(
sources: Seq[(File, String)],
jar: File,
manifest: Manifest,
log: Logger,
time: Option[Long]
): Unit
}].makeJar(
sources = ms,
jar = outPath,
manifest = manifest,
log = log,
time = time
)
} catch {
case e: Throwable =>
log.debug(e.toString)
}
}
Package.makeJar(ms, outPath, manifest, log)
ao.prependShellScript foreach { shellScript: Seq[String] =>
val tmpFile = cacheDir / "assemblyExec.tmp"
if (tmpFile.exists()) tmpFile.delete()
Expand Down
13 changes: 13 additions & 0 deletions src/sbt-test/sbt-assembly/timestamp/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def fixedTimestamp: Long = 1234567000L

assembly / packageOptions += Package.FixedTimestamp(Some(fixedTimestamp))

TaskKey[Unit]("check") := {
val jar = crossTarget.value / (assembly / assemblyJarName).value
IO.withTemporaryDirectory{ tmp =>
val files = IO.unzip(jar, tmp)
val expected = fixedTimestamp - java.util.TimeZone.getDefault().getOffset(fixedTimestamp)
assert(files.nonEmpty)
assert(files.forall(_.lastModified == expected))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.5.0-RC2
7 changes: 7 additions & 0 deletions src/sbt-test/sbt-assembly/timestamp/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
val pluginVersion = System.getProperty("plugin.version")
if(pluginVersion == null)
throw new RuntimeException("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
else addSbtPlugin("com.eed3si9n" % "sbt-assembly" % pluginVersion)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object Main {
def main(args: Array[String]): Unit = {
println("hello")
}
}
2 changes: 2 additions & 0 deletions src/sbt-test/sbt-assembly/timestamp/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> assembly
> check

0 comments on commit a8e2913

Please sign in to comment.