Skip to content

Commit

Permalink
Merge branch 'master' into fix/bashscript-location
Browse files Browse the repository at this point in the history
Conflicts:
	src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala
  • Loading branch information
muuki88 committed Nov 6, 2014
2 parents 8496fae + dc24421 commit 8b0f4ae
Show file tree
Hide file tree
Showing 24 changed files with 164 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
startService() {
app_name=$1
if hash update-rc.d 2>/dev/null; then
if hash update-rc.d >/dev/null 2>&1; then
echo "Adding $app_name to autostart using update-rc.d"
update-rc.d $app_name defaults
service $app_name start
Expand All @@ -24,7 +24,7 @@ startService() {
#
stopService() {
app_name=$1
if hash update-rc.d 2>/dev/null; then
if hash update-rc.d >/dev/null 2>&1; then
echo "Removing $app_name from autostart using update-rc.d"
update-rc.d -f $app_name remove
service $app_name stop
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/com/typesafe/sbt/PackagerPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ object SbtNativePackager extends AutoPlugin {

import SettingsHelper._

@deprecated("Use enablePlugins(xxxDeployPlugin)", "1.x")
def deploymentSettings = makeDeploymentSettings(Debian, packageBin in Debian, "deb") ++
makeDeploymentSettings(Rpm, packageBin in Rpm, "rpm") ++
makeDeploymentSettings(Windows, packageBin in Windows, "msi") ++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,16 @@ object JavaAppPackaging extends AutoPlugin with JavaAppStartScript {
else "../" + name
}

// Constructs a jar name from components...(ModuleID/Artifact)
private def makeJarName(org: String, name: String, revision: String, artifactName: String, artifactClassifier: Option[String]): String =
(org + "." +
/**
* Constructs a jar name from components...(ModuleID/Artifact)
*/
def makeJarName(org: String, name: String, revision: String, artifactName: String, artifactClassifier: Option[String]): String =
org + "." +
name + "-" +
Option(artifactName.replace(name, "")).filterNot(_.isEmpty).map(_ + "-").getOrElse("") +
revision +
artifactClassifier.filterNot(_.isEmpty).map("-" + _).getOrElse("") +
".jar")
".jar"

// Determines a nicer filename for an attributed jar file, using the
// ivy metadata if available.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ object JavaServerAppPackaging extends AutoPlugin {
configLocation.flatMap { path =>
conf.map(c => LinuxPackageMapping(Seq(c -> path), LinuxFileMetaData(Users.Root, Users.Root, "644")).withConfig())
}.toSeq
},

// === /var/run/app pid folder ===
linuxPackageMappings <+= (packageName in Linux, daemonUser in Linux, daemonGroup in Linux) map { (name, user, group) =>
packageTemplateMapping("/var/run/" + name)() withUser user withGroup group withPerms "755"
}

)
Expand Down Expand Up @@ -101,6 +96,9 @@ object JavaServerAppPackaging extends AutoPlugin {
serverLoading in Debian) map makeStartScript,
linuxPackageMappings <++= (packageName, linuxMakeStartScript, serverLoading, defaultLinuxStartScriptLocation) map startScriptMapping
)) ++ Seq(
// === Daemon User and Group ===
daemonUser in Debian <<= daemonUser in Linux,
daemonGroup in Debian <<= daemonGroup in Linux,
// === Maintainer scripts ===
debianMakePreinstScript <<= (target in Universal, serverLoading in Debian, linuxScriptReplacements) map makeMaintainerScript(Preinst),
debianMakePostinstScript <<= (target in Universal, serverLoading in Debian, linuxScriptReplacements) map makeMaintainerScript(Postinst),
Expand All @@ -118,8 +116,16 @@ object JavaServerAppPackaging extends AutoPlugin {
requiredStopFacilities in Rpm <<= (serverLoading) apply defaultFacilities,
linuxScriptReplacements <++= (requiredStartFacilities, requiredStopFacilities, startRunlevels, stopRunlevels, serverLoading) apply
makeStartScriptReplacements,
linuxScriptReplacements += JavaServerLoaderScript.loaderFunctionsReplacement(serverLoading.value, ARCHETYPE)
linuxScriptReplacements += JavaServerLoaderScript.loaderFunctionsReplacement(serverLoading.value, ARCHETYPE),

// === /var/run/app pid folder ===
linuxPackageMappings <+= (packageName, daemonUser, daemonGroup) map { (name, user, group) =>
packageTemplateMapping("/var/run/" + name)() withUser user withGroup group withPerms "755"
}
)) ++ Seq(
// === Daemon User and Group ===
daemonUser in Rpm <<= daemonUser in Linux,
daemonGroup in Rpm <<= daemonGroup in Linux,
// === Startscript creation ===
linuxStartScriptTemplate := JavaServerLoaderScript(
script = startScriptName((serverLoading in Rpm).value, Rpm),
Expand Down
14 changes: 12 additions & 2 deletions src/main/scala/com/typesafe/sbt/packager/debian/DebianPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import SbtNativePackager.{ Universal, Linux }
object DebianPlugin extends AutoPlugin with DebianNativePackaging {

override def requires = linux.LinuxPlugin
override def trigger = allRequirements

object autoImport extends DebianKeys {
val Debian = config("debian") extend Linux
Expand Down Expand Up @@ -213,7 +212,7 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging {
t
},
// Replacement for ${{header}} as debian control scripts are bash scripts
linuxScriptReplacements += ("header" -> "#!/bin/sh\n")
linuxScriptReplacements += ("header" -> "#!/bin/sh\nset -e")

// Adding package specific implementation settings
))
Expand Down Expand Up @@ -341,3 +340,14 @@ trait DebianPluginLike {
appName + "_" + version + "_" + arch + ".changes"
}
}

object DebianDeployPlugin extends AutoPlugin {

import DebianPlugin.autoImport._

override def requires = DebianPlugin

override def projectSettings =
SettingsHelper.makeDeploymentSettings(Debian, packageBin in Debian, "deb") ++
SettingsHelper.makeDeploymentSettings(Debian, genChanges in Debian, "changes")
}
126 changes: 86 additions & 40 deletions src/main/scala/com/typesafe/sbt/packager/debian/JDebPackaging.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ package debian

import sbt._
import sbt.Keys.{ target, normalizedName, version, streams, mappings, packageBin }
import linux.{ LinuxSymlink, LinuxPackageMapping }
import linux.{ LinuxSymlink, LinuxPackageMapping, LinuxFileMetaData }
import linux.LinuxPlugin.autoImport.{ linuxPackageMappings, linuxPackageSymlinks, packageArchitecture }
import scala.collection.JavaConversions._

import org.vafer.jdeb.{ DebMaker, DataProducer }
import org.vafer.jdeb.mapping._
import org.vafer.jdeb.producers._
Expand All @@ -18,7 +17,7 @@ import DebianPlugin.autoImport._
* == JDeb Plugin ==
* This provides a java based debian packaging implementation based
* on the jdeb maven-plugin. To use this, put this into your build.sbt
*
*
* @example Enable the plugin in the `build.sbt`
* {{{
* enablePlugins(JDebPackaging)
Expand All @@ -36,63 +35,110 @@ object JDebPackaging extends AutoPlugin with DebianPluginLike {

def jdebSettings = Seq(

// FIXME do nothing. Java7 posix needed
debianConffilesFile := {
target.value / Names.Debian / Names.Conffiles
},

// FIXME copied from the debian plugin. Java7 posix needed
debianControlFile <<= (debianPackageMetadata, debianPackageInstallSize, target) map {
(data, size, dir) =>
if (data.info.description == null || data.info.description.isEmpty) {
sys.error(
"""packageDescription in Debian cannot be empty. Use
packageDescription in Debian := "My package Description"""")
}
val cfile = dir / Names.Debian / Names.Control
IO.write(cfile, data.makeContent(size), java.nio.charset.Charset.defaultCharset)
cfile
},

/**
* Depends on the 'debianExplodedPackage' task as this creates all the files
* which are defined in the mappings.
*/
packageBin <<= (debianExplodedPackage, linuxPackageMappings, linuxPackageSymlinks,
debianControlFile, debianMaintainerScripts, debianConffilesFile,
normalizedName, version, packageArchitecture, target, streams) map {
(_, mappings, symlinks, controlfile, controlscripts, conffile,
name, version, arch, target, s) =>
s.log.info("Building debian package with java based implementation 'jdeb'")
val console = new JDebConsole(s.log)
val archive = archiveFilename(name, version, arch)
val debianFile = target.getParentFile / archive
val debMaker = new DebMaker(console,
fileAndDirectoryProducers(mappings, target) ++ linkProducers(symlinks),
conffileProducers()
)
debMaker setDeb debianFile
debMaker setControl (target / Names.Debian)

// TODO set compression, gzip is default
// TODO add signing with setKeyring, setKey, setPassphrase, setSignPackage, setSignMethod, setSignRole
debMaker validate ()
debMaker makeDeb ()
debianFile
})
packageBin := {
val targetDir = target.value
val log = streams.value.log
val mappings = linuxPackageMappings.value
val symlinks = linuxPackageSymlinks.value

// unused, but needed as dependency
val controlDir = targetDir / Names.Debian
val control = debianControlFile.value
val conffile = debianConffilesFile.value

val controlScripts = debianMaintainerScripts.value
controlScripts foreach { case (file, script) => IO.copyFile(file, controlDir / script) }

log.info("Building debian package with java based implementation 'jdeb'")
val console = new JDebConsole(log)
val archive = archiveFilename(normalizedName.value, version.value, packageArchitecture.value)
val debianFile = targetDir.getParentFile / archive
val debMaker = new DebMaker(console,
fileAndDirectoryProducers(mappings, targetDir) ++ linkProducers(symlinks),
conffileProducers(mappings, targetDir)
)
debMaker setDeb debianFile
debMaker setControl (targetDir / Names.Debian)

// TODO set compression, gzip is default
// TODO add signing with setKeyring, setKey, setPassphrase, setSignPackage, setSignMethod, setSignRole
debMaker validate ()
debMaker makeDeb ()
debianFile
})

/**
* Creating file and directory producers. These "produce" the
* files for the debian packaging
* files for the debian packaging.
*
* May create duplicates together with the conffileProducers.
* This will be an performance improvement (reducing IO)
*/
private[debian] def fileAndDirectoryProducers(mappings: Seq[LinuxPackageMapping], target: File): Seq[DataProducer] = mappings.map {
case LinuxPackageMapping(paths, perms, zipped) =>
paths map {
case (path, name) if path.isDirectory =>
val permMapper = new PermMapper(-1, -1, perms.user, perms.group, null, perms.permissions, -1, null)
val dirName = if (name.startsWith("/")) name.drop(1) else name
new DataProducerDirectory(target, Array(dirName), null, Array(permMapper))
case (path, name) =>
val permMapper = new PermMapper(-1, -1, perms.user, perms.group, perms.permissions, null, -1, null)
new DataProducerFile(target / name, name, null, null, Array(permMapper))
}
case LinuxPackageMapping(paths, perms, zipped) => paths map {
// Directories need to be created so jdeb can pick them up
case (path, name) if path.isDirectory =>
val permMapper = new PermMapper(-1, -1, perms.user, perms.group, null, perms.permissions, -1, null)
(target / cleanPath(name)) mkdirs ()
new DataProducerDirectory(target, Array(cleanPath(name)), null, Array(permMapper))

// Files are just referenced
case (path, name) => new DataProducerFile(path, cleanPath(name), null, null, Array(filePermissions(perms)))
}
}.flatten

/**
* Creating link producers for symlinks.
*/
private[debian] def linkProducers(symlinks: Seq[LinuxSymlink]): Seq[DataProducer] = symlinks map {
case LinuxSymlink(link, destination) =>
new DataProducerLink(link, destination, true, null, null, null)
case LinuxSymlink(link, destination) => new DataProducerLink(link, destination, true, null, null, null)
}

/**
* Creating the files which should be added as conffiles.
* This is currently handled by the debian plugin itself.
*/
private[debian] def conffileProducers(): Seq[DataProducer] = Seq.empty
private[debian] def conffileProducers(linuxMappings: Seq[LinuxPackageMapping], target: File): Seq[DataProducer] = {

val producers = linuxMappings map {
case mapping @ LinuxPackageMapping(mappings, perms, _) if perms.config == "true" =>
mappings collect {
case (path, name) if path.isFile =>
val permMapper = filePermissions(perms.withPerms("0644"))
new DataProducerFile(path, cleanPath(name), null, null, Array(permMapper))
}
case _ => Seq.empty
}

producers.flatten
}

private[debian] def cleanPath(path: String): String =
if (path startsWith "/") path drop 1 else path

private[this] def filePermissions(perms: LinuxFileMetaData): PermMapper =
new PermMapper(-1, -1, perms.user, perms.group, perms.permissions, null, -1, null)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ object DockerPlugin extends AutoPlugin {

override def requires = universal.UniversalPlugin

override def trigger = allRequirements

override lazy val projectSettings = Seq(
dockerBaseImage := "dockerfile/java:latest",
dockerExposedPorts := Seq(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import SbtNativePackager.Universal
object LinuxPlugin extends AutoPlugin {

override def requires = universal.UniversalPlugin
override def trigger = allRequirements
override lazy val projectSettings = linuxSettings ++ mapGenericFilesToLinux

object autoImport extends LinuxKeys with LinuxMappingDSL {
Expand Down
10 changes: 9 additions & 1 deletion src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import packager.Keys._
object RpmPlugin extends AutoPlugin {

override def requires = LinuxPlugin
override def trigger = allRequirements

object autoImport extends RpmKeys {
val Rpm = config("rpm") extend Linux
Expand Down Expand Up @@ -109,3 +108,12 @@ object RpmPlugin extends AutoPlugin {
))
}

object RpmDeployPlugin extends AutoPlugin {

import RpmPlugin.autoImport._

override def requires = RpmPlugin

override def projectSettings =
SettingsHelper.makeDeploymentSettings(Rpm, packageBin in Rpm, "rpm")
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ object UniversalPlugin extends AutoPlugin {
import autoImport._

override def requires = SbtNativePackager
override def trigger = allRequirements

/** The basic settings for the various packaging types. */
override lazy val projectSettings = Seq[Setting[_]](
Expand Down Expand Up @@ -114,3 +113,16 @@ object UniversalPlugin extends AutoPlugin {
sourceDir.*** --- sourceDir pair relativeTo(sourceDir)

}

object UniversalDeployPlugin extends AutoPlugin {

import UniversalPlugin.autoImport._

override def requires = UniversalPlugin

override def projectSettings =
SettingsHelper.makeDeploymentSettings(Universal, packageBin in Universal, "zip") ++
SettingsHelper.addPackage(Universal, packageZipTarball in Universal, "tgz") ++
SettingsHelper.makeDeploymentSettings(UniversalDocs, packageBin in UniversalDocs, "zip") ++
SettingsHelper.addPackage(UniversalDocs, packageXzTarball in UniversalDocs, "txz")
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ object WindowsPlugin extends AutoPlugin {

override lazy val projectSettings = windowsSettings ++ mapGenericFilesToWindows
override def requires = universal.UniversalPlugin
override def trigger = allRequirements

/**
* default windows settings
Expand Down Expand Up @@ -175,4 +174,14 @@ object WindowsPlugin extends AutoPlugin {
// TODO - Add feature for shortcuts to binary scripts.
Seq(corePackage, addBinToPath, menuLinks)
}
}
}

object WindowsDeployPlugin extends AutoPlugin {

import WindowsPlugin.autoImport._

override def requires = WindowsPlugin

override def projectSettings =
SettingsHelper.makeDeploymentSettings(Windows, packageBin in Windows, "msi")
}
1 change: 0 additions & 1 deletion src/sbt-test/debian/daemon-user-deb/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ TaskKey[Unit]("check-control-files") <<= (target, streams) map { (target, out) =
assert(postinst contains "addGroup daemongroup", "postinst misses addgroup for daemongroup: " + postinst)
assert(postinst contains """addUser daemonuser daemongroup "debian-test user-daemon" "/bin/false"""", "postinst misses useradd for daemonuser: " + postinst)
assert(postinst contains "chown daemonuser:daemongroup /var/log/debian-test", "postinst misses chown daemonuser /var/log/debian-test: " + postinst)
assert(postinst contains "chown daemonuser:daemongroup /var/run/debian-test", "postinst misses chown daemonuser /var/run/debian-test: " + postinst)
assert(!(postinst contains "addgroup --system daemonuser"), "postinst has addgroup for daemonuser: " + postinst)
assert(!(postinst contains "useradd --system --no-create-home --gid daemonuser --shell /bin/false daemonuser"), "postinst has useradd for daemongroup: " + postinst)
assert(postrm contains "deleteUser daemonuser", "postrm misses purging daemonuser user: " + postrm)
Expand Down
4 changes: 2 additions & 2 deletions src/sbt-test/debian/gen-changes/build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
enablePlugins(SbtNativePackager)
enablePlugins(DebianPlugin)

name := "debian-test"

Expand All @@ -15,4 +15,4 @@ debianPackageDependencies in Debian ++= Seq("java2-runtime", "bash (>= 2.05a-11)

debianPackageRecommends in Debian += "git"

debianChangelog in Debian := Some(file("debian/changelog"))
debianChangelog in Debian := Some(file("debian/changelog"))
Loading

0 comments on commit 8b0f4ae

Please sign in to comment.