Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX #405: Script replacements doesn't work with jdeb packaging #406

Merged
merged 1 commit into from
Nov 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package com.typesafe.sbt
package packager
package debian


import com.typesafe.sbt.packager.archetypes.TemplateWriter
import com.typesafe.sbt.packager.universal.Archives
import sbt._
import sbt.Keys.{ target, normalizedName, version, streams, mappings, packageBin }
import linux.{ LinuxSymlink, LinuxPackageMapping, LinuxFileMetaData }
import linux.LinuxPlugin.autoImport.{ linuxPackageMappings, linuxPackageSymlinks, packageArchitecture }
import linux.LinuxPlugin.autoImport.{ linuxPackageMappings, linuxPackageSymlinks, packageArchitecture, linuxScriptReplacements }
import scala.collection.JavaConversions._
import org.vafer.jdeb.{ DebMaker, DataProducer }
import org.vafer.jdeb.mapping._
Expand Down Expand Up @@ -67,9 +70,14 @@ object JDebPackaging extends AutoPlugin with DebianPluginLike {
val controlDir = targetDir / Names.Debian
val control = debianControlFile.value
val conffile = debianConffilesFile.value
val replacements = debianMakeChownReplacements.value +: linuxScriptReplacements.value

val controlScripts = debianMaintainerScripts.value
controlScripts foreach { case (file, script) => IO.copyFile(file, controlDir / script) }
for ((file, name) <- controlScripts) {
val targetFile = controlDir / name
copyFiles(file, targetFile, LinuxFileMetaData())
filterFiles(targetFile, replacements, LinuxFileMetaData())
}

log.info("Building debian package with java based implementation 'jdeb'")
val console = new JDebConsole(log)
Expand All @@ -89,6 +97,35 @@ object JDebPackaging extends AutoPlugin with DebianPluginLike {
debianFile
})


/**
* The same as [[DebianPluginLike.copyAndFixPerms]] except chmod invocation (for windows compatibility).
* Permissions will be handled by jDeb packager itself.
*/
private[this] def copyFiles(from: File, to: File, perms: LinuxFileMetaData, zipped: Boolean = false): Unit = {
if (zipped) {
IO.withTemporaryDirectory { dir =>
val tmp = dir / from.getName
IO.copyFile(from, tmp)
val zipped = Archives.gzip(tmp)
IO.copyFile(zipped, to, true)
}
} else IO.copyFile(from, to, true)
}


/**
* The same as [[DebianPluginLike.filterAndFixPerms]] except chmod invocation (for windows compatibility).
* Permissions will be handled by jDeb packager itself.
*/
private[this] final def filterFiles(script: File, replacements: Seq[(String, String)], perms: LinuxFileMetaData): File = {
val filtered = TemplateWriter.generateScript(script.toURI.toURL, replacements)
IO.delete(script)
IO.write(script, filtered)
script
}


/**
* Creating file and directory producers. These "produce" the
* files for the debian packaging.
Expand Down
34 changes: 34 additions & 0 deletions src/sbt-test/debian/jdeb-script-replacements/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
enablePlugins(JavaServerAppPackaging, JDebPackaging)

name := "debian-test"

version := "0.1.0"

maintainer := "Josh Suereth <joshua.suereth@typesafe.com>"

packageSummary := "Test debian package"

packageDescription := """A fun package description of our software,
with multiple lines."""

debianPackageDependencies in Debian ++= Seq("java2-runtime", "bash (>= 2.05a-11)")

debianPackageRecommends in Debian += "git"

TaskKey[Unit]("check-control-files") <<= (target, streams) map { (target, out) =>
val header = "#!/bin/sh"
val extracted = target / "extracted"
println(extracted.getAbsolutePath)
Seq("dpkg-deb", "-R", (target / "debian-test_0.1.0_all.deb").absolutePath, extracted.absolutePath).!
val preinst = extracted / "DEBIAN/preinst"
val postinst = extracted / "DEBIAN/postinst"
val prerm = extracted / "DEBIAN/prerm"
val postrm = extracted / "DEBIAN/postrm"
Seq(preinst, postinst, prerm, postrm) foreach { script =>
val content = IO.read(script)
assert(content.startsWith(header), "script doesn't start with #!/bin/sh header:\n" + script)
assert(header.r.findAllIn(content).length == 1, "script contains more than one header line:\n" + script)
}
out.log.success("Successfully tested systemV control files")
()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version"))
5 changes: 5 additions & 0 deletions src/sbt-test/debian/jdeb-script-replacements/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Run the debian packaging.
$ mkdir src/resources/empty
> debian:package-bin
$ exists target/debian-test_0.1.0_all.deb
> check-control-files