From 8d9a305ae444bd5d5019de2b2f2fba7ecb976443 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Thu, 15 May 2014 10:55:21 -0400 Subject: [PATCH] Clean up name delegation in the plugin. A few rules: * 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 --- .../typesafe/sbt/packager/archetypes/JavaApp.scala | 2 +- .../archetypes/JavaServerApplication.scala | 14 +++++++------- .../sbt/packager/debian/DebianPlugin.scala | 1 + .../com/typesafe/sbt/packager/linux/Keys.scala | 2 ++ .../typesafe/sbt/packager/linux/LinuxPlugin.scala | 6 ++++-- .../scala/com/typesafe/sbt/packager/rpm/Keys.scala | 1 + .../com/typesafe/sbt/packager/rpm/RpmPlugin.scala | 7 +++++-- .../com/typesafe/sbt/packager/universal/Keys.scala | 1 + .../sbt/packager/universal/UniversalPlugin.scala | 9 +++++++-- .../sbt/packager/windows/WindowsPlugin.scala | 1 + src/sbt-test/debian/test-mapping/build.sbt | 2 ++ src/sbt-test/debian/test-mapping/test | 2 +- src/sbt-test/debian/upstart-deb/build.sbt | 2 ++ src/sbt-test/universal/test-mapping-helpers/test | 2 +- 14 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaApp.scala b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaApp.scala index 91778f6e4..db3913761 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaApp.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaApp.scala @@ -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 diff --git a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala index f3d789c8e..ec4fe96c9 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala @@ -76,20 +76,20 @@ 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)), @@ -97,7 +97,7 @@ object JavaServerAppPackaging { }, // === /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" }) @@ -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), @@ -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 diff --git a/src/main/scala/com/typesafe/sbt/packager/debian/DebianPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/debian/DebianPlugin.scala index 4e91c249f..b49621654 100644 --- a/src/main/scala/com/typesafe/sbt/packager/debian/DebianPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/debian/DebianPlugin.scala @@ -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 <<= diff --git a/src/main/scala/com/typesafe/sbt/packager/linux/Keys.scala b/src/main/scala/com/typesafe/sbt/packager/linux/Keys.scala index 2cb395631..aea75d66b 100644 --- a/src/main/scala/com/typesafe/sbt/packager/linux/Keys.scala +++ b/src/main/scala/com/typesafe/sbt/packager/linux/Keys.scala @@ -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 } \ No newline at end of file diff --git a/src/main/scala/com/typesafe/sbt/packager/linux/LinuxPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/linux/LinuxPlugin.scala index 1a10fd52f..df416add8 100644 --- a/src/main/scala/com/typesafe/sbt/packager/linux/LinuxPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/linux/LinuxPlugin.scala @@ -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", @@ -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 diff --git a/src/main/scala/com/typesafe/sbt/packager/rpm/Keys.scala b/src/main/scala/com/typesafe/sbt/packager/rpm/Keys.scala index 9c5377990..cbfe66ac8 100644 --- a/src/main/scala/com/typesafe/sbt/packager/rpm/Keys.scala +++ b/src/main/scala/com/typesafe/sbt/packager/rpm/Keys.scala @@ -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 diff --git a/src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala index 3c250e724..358a70704 100644 --- a/src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala @@ -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 <<= diff --git a/src/main/scala/com/typesafe/sbt/packager/universal/Keys.scala b/src/main/scala/com/typesafe/sbt/packager/universal/Keys.scala index 8e74cdd97..f5c2a764e 100644 --- a/src/main/scala/com/typesafe/sbt/packager/universal/Keys.scala +++ b/src/main/scala/com/typesafe/sbt/packager/universal/Keys.scala @@ -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).") diff --git a/src/main/scala/com/typesafe/sbt/packager/universal/UniversalPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/universal/UniversalPlugin.scala index a8deab515..50d902c07 100644 --- a/src/main/scala/com/typesafe/sbt/packager/universal/UniversalPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/universal/UniversalPlugin.scala @@ -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) ++ @@ -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"), @@ -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 */ diff --git a/src/main/scala/com/typesafe/sbt/packager/windows/WindowsPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/windows/WindowsPlugin.scala index 44521bb11..48eb0f288 100644 --- a/src/main/scala/com/typesafe/sbt/packager/windows/WindowsPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/windows/WindowsPlugin.scala @@ -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"), diff --git a/src/sbt-test/debian/test-mapping/build.sbt b/src/sbt-test/debian/test-mapping/build.sbt index a856482cd..f14da04bb 100644 --- a/src/sbt-test/debian/test-mapping/build.sbt +++ b/src/sbt-test/debian/test-mapping/build.sbt @@ -6,6 +6,8 @@ mapGenericFilesToLinux name := "debian-test" +name in Debian := "debian-test-override" + version := "0.1.0" maintainer := "Josh Suereth " diff --git a/src/sbt-test/debian/test-mapping/test b/src/sbt-test/debian/test-mapping/test index edb38a825..6861c1374 100644 --- a/src/sbt-test/debian/test-mapping/test +++ b/src/sbt-test/debian/test-mapping/test @@ -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. diff --git a/src/sbt-test/debian/upstart-deb/build.sbt b/src/sbt-test/debian/upstart-deb/build.sbt index 4b7d65c91..73b838da1 100644 --- a/src/sbt-test/debian/upstart-deb/build.sbt +++ b/src/sbt-test/debian/upstart-deb/build.sbt @@ -11,6 +11,8 @@ mainClass in Compile := Some("empty") name := "debian-test" +name in Debian := "debian-test" + version := "0.1.0" maintainer := "Josh Suereth " diff --git a/src/sbt-test/universal/test-mapping-helpers/test b/src/sbt-test/universal/test-mapping-helpers/test index 8d919da8a..f6cfad758 100644 --- a/src/sbt-test/universal/test-mapping-helpers/test +++ b/src/sbt-test/universal/test-mapping-helpers/test @@ -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