Skip to content

Commit

Permalink
Clean up name delegation in the plugin. A few rules:
Browse files Browse the repository at this point in the history
* Each configuration should have its own `name` and `normalizedName` instance
* Debian/Rpm delegate to Linux which delegates to project name.
* Universal has its own name, which is used for generating BASH/BAT files
* Separate key for the package filename now
* Windows has its own name/normalized name which delegates to raw.

Fixes #188
  • Loading branch information
jsuereth committed May 15, 2014
1 parent 7fe7eb2 commit 8d9a305
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ object JavaAppPackaging {
s <- script.toSeq
} yield s -> ("bin/" + name + ".bat")
},
linuxPackageMappings in Debian <+= (normalizedName, defaultLinuxInstallLocation, target in Debian) map {
linuxPackageMappings in Debian <+= (normalizedName in Debian, defaultLinuxInstallLocation, target in Debian) map {
(name, installLocation, target) =>
// create empty var/log directory
val d = target / installLocation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,28 @@ object JavaServerAppPackaging {
*/
def linuxSettings: Seq[Setting[_]] = Seq(
// === logging directory mapping ===
linuxPackageMappings <+= (normalizedName, defaultLinuxLogsLocation, daemonUser in Linux, daemonGroup in Linux) map {
linuxPackageMappings <+= (normalizedName in Linux, defaultLinuxLogsLocation, daemonUser in Linux, daemonGroup in Linux) map {
(name, logsDir, user, group) => packageTemplateMapping(logsDir + "/" + name)() withUser user withGroup group withPerms "755"
},
linuxPackageSymlinks <+= (normalizedName, defaultLinuxInstallLocation, defaultLinuxLogsLocation) map {
linuxPackageSymlinks <+= (normalizedName in Linux, defaultLinuxInstallLocation, defaultLinuxLogsLocation) map {
(name, install, logsDir) => LinuxSymlink(install + "/" + name + "/logs", logsDir + "/" + name)
},
// === etc config mapping ===
bashScriptConfigLocation <<= normalizedName map (name => Some("/etc/default/" + name)),
bashScriptConfigLocation <<= (normalizedName in Linux) map (name => Some("/etc/default/" + name)),
linuxEtcDefaultTemplate <<= sourceDirectory map { dir =>
val overrideScript = dir / "templates" / "etc-default"
if (overrideScript.exists) overrideScript.toURI.toURL
else etcDefaultTemplateSource
},
makeEtcDefault <<= (normalizedName, target in Universal, linuxEtcDefaultTemplate, linuxScriptReplacements)
makeEtcDefault <<= (normalizedName in Linux, target in Universal, linuxEtcDefaultTemplate, linuxScriptReplacements)
map makeEtcDefaultScript,
linuxPackageMappings <++= (makeEtcDefault, normalizedName) map { (conf, name) =>
conf.map(c => LinuxPackageMapping(Seq(c -> ("/etc/default/" + name)),
LinuxFileMetaData(Users.Root, Users.Root)).withConfig()).toSeq
},

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

Expand All @@ -121,7 +121,7 @@ object JavaServerAppPackaging {
println(replacements)
makeMaintainerScript(builder.startScript, Some(template))(tmpDir, loader, replacements, builder)
},
linuxPackageMappings in Debian <++= (normalizedName, linuxMakeStartScript in Debian, serverLoading in Debian) map startScriptMapping,
linuxPackageMappings in Debian <++= (normalizedName in Linux, linuxMakeStartScript in Debian, serverLoading in Debian) map startScriptMapping,

// === Maintainer scripts ===
debianMakePreinstScript <<= (target in Universal, serverLoading in Debian, linuxScriptReplacements, linuxJavaAppStartScriptBuilder in Debian) map makeMaintainerScript(Preinst),
Expand Down Expand Up @@ -150,7 +150,7 @@ object JavaServerAppPackaging {
map { (tmpDir, loader, replacements, template, builder) =>
makeMaintainerScript(builder.startScript, Some(template))(tmpDir, loader, replacements, builder)
},
linuxPackageMappings in Rpm <++= (normalizedName, linuxMakeStartScript in Rpm, serverLoading in Rpm) map startScriptMapping,
linuxPackageMappings in Rpm <++= (normalizedName in Linux, linuxMakeStartScript in Rpm, serverLoading in Rpm) map startScriptMapping,

// == Maintainer scripts ===
// TODO this is very basic - align debian and rpm plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ trait DebianPlugin extends Plugin with linux.LinuxPlugin {
debianMaintainerScripts <++= (debianMakePostinstScript, debianControlScriptsDirectory) map scriptMapping(Names.Postinst),
debianMaintainerScripts <++= (debianMakePostrmScript, debianControlScriptsDirectory) map scriptMapping(Names.Postrm)) ++ inConfig(Debian)(Seq(
packageArchitecture := "all",
normalizedName <<= name apply Project.normalizeModuleID,
debianPackageInfo <<=
(normalizedName, version, maintainer, packageSummary, packageDescription) apply PackageInfo,
debianPackageMetadata <<=
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/com/typesafe/sbt/packager/linux/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ trait Keys {
}

object Keys extends Keys {
def name = sbt.Keys.name
def normalizedName = sbt.Keys.normalizedName
def sourceDirectory = sbt.Keys.sourceDirectory
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ trait LinuxPlugin extends Plugin {
},
packageSummary in Linux <<= packageSummary,
packageDescription in Linux <<= packageDescription,
daemonUser in Linux <<= normalizedName,
name in Linux <<= name,
normalizedName in Linux <<= (name in Linux) apply Project.normalizeModuleID,
daemonUser in Linux <<= normalizedName in Linux,
daemonGroup in Linux <<= daemonUser in Linux,
daemonShell in Linux := "/bin/false",
defaultLinuxInstallLocation := "/usr/share",
Expand All @@ -44,7 +46,7 @@ trait LinuxPlugin extends Plugin {
linuxJavaAppStartScriptBuilder := JavaAppStartScript.Debian,
// This one is begging for sbt 0.13 syntax...
linuxScriptReplacements <<= (
maintainer in Linux, packageSummary in Linux, daemonUser in Linux, daemonGroup in Linux, daemonShell in Linux, normalizedName,
maintainer in Linux, packageSummary in Linux, daemonUser in Linux, daemonGroup in Linux, daemonShell in Linux, normalizedName in Linux,
sbt.Keys.version, defaultLinuxInstallLocation, linuxJavaAppStartScriptBuilder)
apply { (author, descr, daemonUser, daemonGroup, daemonShell, name, version, installLocation, builder) =>
val appDir = installLocation + "/" + name
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/com/typesafe/sbt/packager/rpm/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ trait RpmKeys {
object Keys extends RpmKeys {
// METADATA keys.
def name = sbt.Keys.name
def normalizedName = sbt.Keys.normalizedName
def version = sbt.Keys.version
def maintainer = linux.Keys.maintainer
def packageArchitecture = linux.Keys.packageArchitecture
Expand Down
7 changes: 5 additions & 2 deletions src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ trait RpmPlugin extends Plugin with LinuxPlugin {
rpmPostun := None,
rpmBrpJavaRepackJars := false,
rpmScriptsDirectory <<= sourceDirectory apply (_ / "rpm" / Names.Scriptlets),
// Explicitly defer default settings to generic Linux Settings.
packageSummary in Rpm <<= packageSummary in Linux,
packageDescription in Rpm <<= packageDescription in Linux,
target in Rpm <<= target(_ / "rpm")
target in Rpm <<= target(_ / "rpm"),
name in Rpm <<= name in Linux
) ++ inConfig(Rpm)(Seq(
normalizedName <<= name apply Project.normalizeModuleID,
packageArchitecture := "noarch",
rpmMetadata <<=
(name, version, rpmRelease, packageArchitecture, rpmVendor, rpmOs, packageSummary, packageDescription, rpmAutoprov, rpmAutoreq) apply (RpmMetadata.apply),
(normalizedName, version, rpmRelease, packageArchitecture, rpmVendor, rpmOs, packageSummary, packageDescription, rpmAutoprov, rpmAutoreq) apply (RpmMetadata.apply),
rpmDescription <<=
(rpmLicense, rpmDistribution, rpmUrl, rpmGroup, rpmPackager, rpmIcon) apply RpmDescription,
rpmDependencies <<=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package universal
import sbt._

trait UniversalKeys {
val packageFilename = SettingKey[String]("package-filename", "The base filename for the universal packages.")
val packageZipTarball = TaskKey[File]("package-zip-tarball", "Creates a tgz package.")
val packageXzTarball = TaskKey[File]("package-xz-tarball", "Creates a txz package.")
val packageOsxDmg = TaskKey[File]("package-osx-dmg", "Creates a dmg package for OSX (only on osx).")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ trait UniversalPlugin extends Plugin {
dist <<= dist in Universal,
stage <<= stage in Universal,
// TODO - New default to naming, is this right?
name in Universal <<= (normalizedName, version) apply (_ + "-" + _)
// TODO - We may need to do this for UniversalSrcs + UnviersalDocs
name in Universal <<= name,
name in UniversalDocs <<= name in Universal,
name in UniversalSrc <<= name in Universal
) ++
makePackageSettingsForConfig(Universal) ++
makePackageSettingsForConfig(UniversalDocs) ++
Expand All @@ -34,6 +37,8 @@ trait UniversalPlugin extends Plugin {
makePackageSettings(packageZipTarball, config)(makeTgz) ++
makePackageSettings(packageXzTarball, config)(makeTxz) ++
inConfig(config)(Seq(
normalizedName <<= name apply Project.normalizeModuleID,
packageFilename <<= (normalizedName, version) apply (_ + "-" + _),
mappings <<= sourceDirectory map findSources,
dist <<= (packageBin, streams) map printDist,
stagingDirectory <<= target apply (_ / "stage"),
Expand Down Expand Up @@ -74,7 +79,7 @@ trait UniversalPlugin extends Plugin {
private[this] def makePackageSettings(packageKey: TaskKey[File], config: Configuration)(packager: Packager): Seq[Setting[_]] =
inConfig(config)(Seq(
mappings in packageKey <<= mappings map checkMappings,
packageKey <<= (target, name, mappings in packageKey) map packager
packageKey <<= (target, packageFilename, mappings in packageKey) map packager
))

/** check that all mapped files actually exist */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ trait WindowsPlugin extends Plugin {
def windowsSettings: Seq[Setting[_]] = Seq(
sourceDirectory in Windows <<= sourceDirectory(_ / "windows"),
target in Windows <<= target apply (_ / "windows"),
// TODO - Should this use normalized name like the linux guys?
name in Windows <<= name,
// Defaults so that our simplified building works
candleOptions := Seq("-ext", "WixUtilExtension"),
Expand Down
2 changes: 2 additions & 0 deletions src/sbt-test/debian/test-mapping/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ mapGenericFilesToLinux

name := "debian-test"

name in Debian := "debian-test-override"

version := "0.1.0"

maintainer := "Josh Suereth <[email protected]>"
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/debian/test-mapping/test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Run the debian packaging.
> debian:package-bin
$ exists target/debian-test-0.1.0.deb
$ exists target/debian-test-override-0.1.0.deb


# TODO - Test that the generic mapping did the right thing.
2 changes: 2 additions & 0 deletions src/sbt-test/debian/upstart-deb/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ mainClass in Compile := Some("empty")

name := "debian-test"

name in Debian := "debian-test"

version := "0.1.0"

maintainer := "Josh Suereth <[email protected]>"
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/universal/test-mapping-helpers/test
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Run the universal packaging.
> universal:package-bin
> show universal:package-bin
$ exists target/universal/simple-test-0.1.0.zip

> unzip
Expand Down

0 comments on commit 8d9a305

Please sign in to comment.