From 22a691a582506b444e794b0657c9382e7e8ca236 Mon Sep 17 00:00:00 2001 From: Nepomuk Seiler Date: Thu, 24 Jul 2014 16:50:08 +0200 Subject: [PATCH] FIX #217 Introduced executableScriptName setting --- .../archetypes/systemd/start-debian-template | 2 +- .../archetypes/systemd/start-rpm-template | 2 +- .../archetypes/systemv/start-debian-template | 2 +- .../archetypes/systemv/start-rpm-template | 2 +- .../com/typesafe/sbt/PackagerPlugin.scala | 3 +- .../com/typesafe/sbt/packager/Keys.scala | 1 + .../sbt/packager/archetypes/JavaApp.scala | 14 +++--- .../sbt/packager/debian/DebianPlugin.scala | 3 +- .../typesafe/sbt/packager/debian/Keys.scala | 1 + .../sbt/packager/docker/DockerPlugin.scala | 11 +++-- .../typesafe/sbt/packager/docker/Keys.scala | 2 +- .../typesafe/sbt/packager/linux/Keys.scala | 2 +- .../sbt/packager/linux/LinuxPlugin.scala | 11 +++-- .../com/typesafe/sbt/packager/rpm/Keys.scala | 2 +- .../typesafe/sbt/packager/rpm/RpmPlugin.scala | 4 +- .../sbt/packager/universal/Keys.scala | 2 +- .../packager/universal/UniversalPlugin.scala | 4 +- .../typesafe/sbt/packager/windows/Keys.scala | 11 +++-- .../sbt/packager/windows/WindowsPlugin.scala | 2 + .../test-executableScriptName/build.sbt | 29 +++++++++++ .../project/plugins.sbt | 1 + .../src/main/scala/test/Main.scala | 10 ++++ .../debian/test-executableScriptName/test | 18 +++++++ .../test-executableScriptName/build.sbt | 21 ++++++++ .../project/plugins.sbt | 1 + .../src/main/scala/Main.scala | 3 ++ .../docker/test-executableScriptName/test | 6 +++ .../rpm/test-executableScriptName/build.sbt | 49 +++++++++++++++++++ .../project/plugins.sbt | 1 + .../src/main/scala/test/Main.scala | 10 ++++ .../rpm/test-executableScriptName/test | 14 ++++++ src/sbt-test/rpm/test-packageName/build.sbt | 11 ++--- .../test-executableScriptName/build.sbt | 14 ++++++ .../project/plugins.sbt | 1 + .../src/main/scala/Main.scala | 3 ++ .../universal/test-executableScriptName/test | 6 +++ test-project/build.sbt | 4 ++ 37 files changed, 241 insertions(+), 42 deletions(-) create mode 100644 src/sbt-test/debian/test-executableScriptName/build.sbt create mode 100644 src/sbt-test/debian/test-executableScriptName/project/plugins.sbt create mode 100644 src/sbt-test/debian/test-executableScriptName/src/main/scala/test/Main.scala create mode 100644 src/sbt-test/debian/test-executableScriptName/test create mode 100644 src/sbt-test/docker/test-executableScriptName/build.sbt create mode 100644 src/sbt-test/docker/test-executableScriptName/project/plugins.sbt create mode 100644 src/sbt-test/docker/test-executableScriptName/src/main/scala/Main.scala create mode 100644 src/sbt-test/docker/test-executableScriptName/test create mode 100644 src/sbt-test/rpm/test-executableScriptName/build.sbt create mode 100644 src/sbt-test/rpm/test-executableScriptName/project/plugins.sbt create mode 100644 src/sbt-test/rpm/test-executableScriptName/src/main/scala/test/Main.scala create mode 100644 src/sbt-test/rpm/test-executableScriptName/test create mode 100644 src/sbt-test/universal/test-executableScriptName/build.sbt create mode 100644 src/sbt-test/universal/test-executableScriptName/project/plugins.sbt create mode 100644 src/sbt-test/universal/test-executableScriptName/src/main/scala/Main.scala create mode 100644 src/sbt-test/universal/test-executableScriptName/test diff --git a/src/main/resources/com/typesafe/sbt/packager/archetypes/systemd/start-debian-template b/src/main/resources/com/typesafe/sbt/packager/archetypes/systemd/start-debian-template index 69a74f9b0..291c5618c 100644 --- a/src/main/resources/com/typesafe/sbt/packager/archetypes/systemd/start-debian-template +++ b/src/main/resources/com/typesafe/sbt/packager/archetypes/systemd/start-debian-template @@ -5,7 +5,7 @@ Requires=${{start_facilities}} [Service] Type=simple WorkingDirectory=${{chdir}} -ExecStart=${{chdir}}/bin/${{app_name}} +ExecStart=${{chdir}}/bin/${{exec}} Restart=always RestartSec=${{retryTimeout}} diff --git a/src/main/resources/com/typesafe/sbt/packager/archetypes/systemd/start-rpm-template b/src/main/resources/com/typesafe/sbt/packager/archetypes/systemd/start-rpm-template index 69a74f9b0..291c5618c 100644 --- a/src/main/resources/com/typesafe/sbt/packager/archetypes/systemd/start-rpm-template +++ b/src/main/resources/com/typesafe/sbt/packager/archetypes/systemd/start-rpm-template @@ -5,7 +5,7 @@ Requires=${{start_facilities}} [Service] Type=simple WorkingDirectory=${{chdir}} -ExecStart=${{chdir}}/bin/${{app_name}} +ExecStart=${{chdir}}/bin/${{exec}} Restart=always RestartSec=${{retryTimeout}} diff --git a/src/main/resources/com/typesafe/sbt/packager/archetypes/systemv/start-debian-template b/src/main/resources/com/typesafe/sbt/packager/archetypes/systemv/start-debian-template index cbc075029..718bd8638 100644 --- a/src/main/resources/com/typesafe/sbt/packager/archetypes/systemv/start-debian-template +++ b/src/main/resources/com/typesafe/sbt/packager/archetypes/systemv/start-debian-template @@ -20,7 +20,7 @@ if [ -z "$DAEMON_USER" ]; then fi -RUN_CMD="${{chdir}}/bin/${{app_name}}" +RUN_CMD="${{chdir}}/bin/${{exec}}" start_daemon() { diff --git a/src/main/resources/com/typesafe/sbt/packager/archetypes/systemv/start-rpm-template b/src/main/resources/com/typesafe/sbt/packager/archetypes/systemv/start-rpm-template index 491125a03..3082f8b54 100644 --- a/src/main/resources/com/typesafe/sbt/packager/archetypes/systemv/start-rpm-template +++ b/src/main/resources/com/typesafe/sbt/packager/archetypes/systemv/start-rpm-template @@ -28,7 +28,7 @@ # Source function library. . /etc/rc.d/init.d/functions -prog="${{app_name}}" +prog="${{exec}}" # FIXME The pid file should be handled by the executed script # The pid can be filled in in this script diff --git a/src/main/scala/com/typesafe/sbt/PackagerPlugin.scala b/src/main/scala/com/typesafe/sbt/PackagerPlugin.scala index 85de0eb90..d7b610d78 100644 --- a/src/main/scala/com/typesafe/sbt/PackagerPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/PackagerPlugin.scala @@ -30,7 +30,8 @@ object SbtNativePackager extends Plugin NativePackagerKeys.maintainer := "", NativePackagerKeys.packageDescription := "", NativePackagerKeys.packageSummary := "", - packageName <<= normalizedName + NativePackagerKeys.packageName <<= normalizedName, + NativePackagerKeys.executableScriptName <<= NativePackagerKeys.packageName ) import SettingsHelper._ diff --git a/src/main/scala/com/typesafe/sbt/packager/Keys.scala b/src/main/scala/com/typesafe/sbt/packager/Keys.scala index 2bec3bc06..053ab5372 100644 --- a/src/main/scala/com/typesafe/sbt/packager/Keys.scala +++ b/src/main/scala/com/typesafe/sbt/packager/Keys.scala @@ -12,6 +12,7 @@ object Keys extends linux.Keys // These keys are used by the JavaApp/JavaServer archetypes. val packageName = SettingKey[String]("packageName", "Name of the created output package. Used for dirs/scripts.") + val executableScriptName = SettingKey[String]("executableScriptName", "Name of the executing script.") val makeBashScript = TaskKey[Option[File]]("makeBashScript", "Creates or discovers the bash script used by this project.") val bashScriptDefines = TaskKey[Seq[String]]("bashScriptDefines", "A list of definitions that should be written to the bash file template.") val bashScriptExtraDefines = TaskKey[Seq[String]]("bashScriptExtraDefines", "A list of extra definitions that should be written to the bash file template.") 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 753fbbc35..a9f5b0018 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaApp.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaApp.scala @@ -5,7 +5,7 @@ package archetypes import Keys._ import sbt._ import sbt.Project.Initialize -import sbt.Keys.{ mappings, target, name, mainClass, normalizedName, sourceDirectory } +import sbt.Keys.{ mappings, target, name, mainClass, sourceDirectory } import com.typesafe.sbt.packager.linux.{ LinuxFileMetaData, LinuxPackageMapping } import SbtNativePackager._ @@ -45,21 +45,21 @@ object JavaAppPackaging { hasMain getOrElse Nil }, // TODO - Overridable bash template. - makeBashScript <<= (bashScriptDefines, target in Universal, packageName, sourceDirectory) map makeUniversalBinScript, + makeBashScript <<= (bashScriptDefines, target in Universal, executableScriptName, sourceDirectory) map makeUniversalBinScript, batScriptExtraDefines := Nil, - batScriptReplacements <<= (normalizedName, Keys.mainClass in Compile, scriptClasspath, batScriptExtraDefines) map { (name, mainClass, cp, extras) => + batScriptReplacements <<= (packageName, Keys.mainClass in Compile, scriptClasspath, batScriptExtraDefines) map { (name, mainClass, cp, extras) => mainClass map { mc => JavaAppBatScript.makeReplacements(name = name, mainClass = mc, appClasspath = cp, extras = extras) } getOrElse Nil }, - makeBatScript <<= (batScriptReplacements, target in Universal, packageName, sourceDirectory) map makeUniversalBatScript, - mappings in Universal <++= (makeBashScript, packageName) map { (script, name) => + makeBatScript <<= (batScriptReplacements, target in Universal, executableScriptName, sourceDirectory) map makeUniversalBatScript, + mappings in Universal <++= (makeBashScript, executableScriptName) map { (script, name) => for { s <- script.toSeq } yield s -> ("bin/" + name) }, - mappings in Universal <++= (makeBatScript, packageName) map { (script, name) => + mappings in Universal <++= (makeBatScript, executableScriptName) map { (script, name) => for { s <- script.toSeq } yield s -> ("bin/" + name + ".bat") @@ -164,7 +164,7 @@ object JavaAppPackaging { !(name.endsWith(".jar") || name.endsWith("-sources.jar") || name.endsWith("-javadoc.jar")) } - def findProjectDependencyArtifacts: Initialize[Task[Seq[Attributed[File]]]] = + def findProjectDependencyArtifacts: Def.Initialize[Task[Seq[Attributed[File]]]] = (sbt.Keys.buildDependencies, sbt.Keys.thisProjectRef, sbt.Keys.state) apply { (build, thisProject, stateTask) => val refs = thisProject +: dependencyProjectRefs(build, thisProject) // Dynamic lookup of dependencies... 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 ed877b851..980c6f1ef 100644 --- a/src/main/scala/com/typesafe/sbt/packager/debian/DebianPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/debian/DebianPlugin.scala @@ -4,7 +4,7 @@ package debian import Keys._ import sbt._ -import sbt.Keys.{ target, name, normalizedName, TaskStreams } +import sbt.Keys.{ target, name, TaskStreams } import linux.{ LinuxFileMetaData, LinuxPackageMapping, LinuxSymlink } import linux.Keys.{ linuxScriptReplacements, daemonShell } import com.typesafe.sbt.packager.Hashing @@ -28,6 +28,7 @@ trait DebianPlugin extends Plugin with linux.LinuxPlugin with NativePackaging wi target in Debian <<= (target, name in Debian, version in Debian) apply ((t, n, v) => t / (n + "-" + v)), name in Debian <<= (name in Linux), packageName in Debian <<= (packageName in Linux), + executableScriptName in Debian <<= (executableScriptName in Linux), version in Debian <<= (version in Linux), linuxPackageMappings in Debian <<= linuxPackageMappings, packageDescription in Debian <<= packageDescription in Linux, diff --git a/src/main/scala/com/typesafe/sbt/packager/debian/Keys.scala b/src/main/scala/com/typesafe/sbt/packager/debian/Keys.scala index 85ce654d1..8a761d520 100644 --- a/src/main/scala/com/typesafe/sbt/packager/debian/Keys.scala +++ b/src/main/scala/com/typesafe/sbt/packager/debian/Keys.scala @@ -48,6 +48,7 @@ object Keys extends DebianKeys { // Metadata keys def name = sbt.Keys.name def packageName = linux.Keys.packageName + def executableScriptName = linux.Keys.executableScriptName 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/docker/DockerPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala index 51502bfb6..81fbaf052 100644 --- a/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala @@ -8,7 +8,7 @@ import sbt._ trait DockerPlugin extends Plugin with UniversalPlugin { val Docker = config("docker") extend Universal - private[this] final def makeDockerContent(dockerBaseImage: String, dockerBaseDirectory: String, maintainer: String, daemonUser: String, name: String, exposedPorts: Seq[Int], exposedVolumes: Seq[String]) = { + private[this] final def makeDockerContent(dockerBaseImage: String, dockerBaseDirectory: String, maintainer: String, daemonUser: String, execScript: String, exposedPorts: Seq[Int], exposedVolumes: Seq[String]) = { val headerCommands = Seq( Cmd("FROM", dockerBaseImage), Cmd("MAINTAINER", maintainer) @@ -19,7 +19,7 @@ trait DockerPlugin extends Plugin with UniversalPlugin { Cmd("WORKDIR", "%s" format dockerBaseDirectory), ExecCmd("RUN", "chown", "-R", daemonUser, "."), Cmd("USER", daemonUser), - ExecCmd("ENTRYPOINT", "bin/%s" format name), + ExecCmd("ENTRYPOINT", "bin/%s" format execScript), ExecCmd("CMD") ) @@ -49,8 +49,8 @@ trait DockerPlugin extends Plugin with UniversalPlugin { } private[this] final def generateDockerConfig( - dockerBaseImage: String, dockerBaseDirectory: String, maintainer: String, daemonUser: String, packageName: String, exposedPorts: Seq[Int], exposedVolumes: Seq[String], target: File) = { - val dockerContent = makeDockerContent(dockerBaseImage, dockerBaseDirectory, maintainer, daemonUser, packageName, exposedPorts, exposedVolumes) + dockerBaseImage: String, dockerBaseDirectory: String, maintainer: String, daemonUser: String, execScript: String, exposedPorts: Seq[Int], exposedVolumes: Seq[String], target: File) = { + val dockerContent = makeDockerContent(dockerBaseImage, dockerBaseDirectory, maintainer, daemonUser, execScript, exposedPorts, exposedVolumes) val f = target / "Dockerfile" IO.write(f, dockerContent) @@ -150,6 +150,7 @@ trait DockerPlugin extends Plugin with UniversalPlugin { dockerBaseImage := "dockerfile/java", name in Docker <<= name, packageName in Docker <<= packageName, + executableScriptName in Docker <<= executableScriptName, dockerRepository := None, sourceDirectory in Docker <<= sourceDirectory apply (_ / "docker"), target in Docker <<= target apply (_ / "docker"), @@ -157,7 +158,7 @@ trait DockerPlugin extends Plugin with UniversalPlugin { // TODO this must be changed, when there is a setting for the startScripts name dockerGenerateConfig <<= (dockerBaseImage in Docker, defaultLinuxInstallLocation in Docker, maintainer in Docker, daemonUser in Docker, - packageName /* this is not scoped!*/ , dockerExposedPorts in Docker, dockerExposedVolumes in Docker, target in Docker) map + executableScriptName /* this is not scoped!*/ , dockerExposedPorts in Docker, dockerExposedVolumes in Docker, target in Docker) map generateDockerConfig ) ++ mapGenericFilesToDocker ++ inConfig(Docker)(Seq( daemonUser := "daemon", diff --git a/src/main/scala/com/typesafe/sbt/packager/docker/Keys.scala b/src/main/scala/com/typesafe/sbt/packager/docker/Keys.scala index 5dde299bb..80693bcf4 100644 --- a/src/main/scala/com/typesafe/sbt/packager/docker/Keys.scala +++ b/src/main/scala/com/typesafe/sbt/packager/docker/Keys.scala @@ -21,7 +21,7 @@ object Keys extends DockerKeys { def mappings = sbt.Keys.mappings def name = sbt.Keys.name def packageName = universal.Keys.packageName - def normalizedName = universal.Keys.normalizedName + def executableScriptName = universal.Keys.executableScriptName def stage = universal.Keys.stage def publish = sbt.Keys.publish def publishArtifact = sbt.Keys.publishArtifact 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 8ce055e62..cf1ede477 100644 --- a/src/main/scala/com/typesafe/sbt/packager/linux/Keys.scala +++ b/src/main/scala/com/typesafe/sbt/packager/linux/Keys.scala @@ -49,6 +49,6 @@ trait Keys { object Keys extends Keys { def name = sbt.Keys.name def packageName = packager.Keys.packageName - def normalizedName = sbt.Keys.normalizedName + def executableScriptName = packager.Keys.executableScriptName 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 d9d3a1379..bb68f1f69 100644 --- a/src/main/scala/com/typesafe/sbt/packager/linux/LinuxPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/linux/LinuxPlugin.scala @@ -36,8 +36,8 @@ trait LinuxPlugin extends Plugin { packageDescription in Linux <<= packageDescription, name in Linux <<= name, packageName in Linux <<= packageName, - normalizedName in Linux <<= (name in Linux) apply Project.normalizeModuleID, - daemonUser in Linux <<= normalizedName in Linux, + executableScriptName in Linux <<= executableScriptName, + daemonUser in Linux <<= packageName in Linux, daemonGroup in Linux <<= daemonUser in Linux, daemonShell in Linux := "/bin/false", defaultLinuxInstallLocation := "/usr/share", @@ -47,16 +47,17 @@ 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 in Linux, + maintainer in Linux, packageSummary in Linux, daemonUser in Linux, daemonGroup in Linux, daemonShell in Linux, + packageName in Linux, executableScriptName in Linux, sbt.Keys.version, defaultLinuxInstallLocation, linuxJavaAppStartScriptBuilder) - apply { (author, descr, daemonUser, daemonGroup, daemonShell, name, version, installLocation, builder) => + apply { (author, descr, daemonUser, daemonGroup, daemonShell, name, execScript, version, installLocation, builder) => val appDir = installLocation + "/" + name // TODO Making replacements should be done somewhere else. Maybe TemplateWriter builder.makeReplacements( author = author, description = descr, - execScript = name, + execScript = execScript, chdir = appDir, appName = name, daemonUser = daemonUser, 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 193055ff8..ce2519202 100644 --- a/src/main/scala/com/typesafe/sbt/packager/rpm/Keys.scala +++ b/src/main/scala/com/typesafe/sbt/packager/rpm/Keys.scala @@ -62,7 +62,7 @@ object Keys extends RpmKeys { // METADATA keys. def name = sbt.Keys.name def packageName = packager.Keys.packageName - def normalizedName = sbt.Keys.normalizedName + def executableScriptName = linux.Keys.executableScriptName 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 02b90c7e3..5aa2e8486 100644 --- a/src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala @@ -46,9 +46,9 @@ trait RpmPlugin extends Plugin with LinuxPlugin { packageDescription in Rpm <<= packageDescription in Linux, target in Rpm <<= target(_ / "rpm"), name in Rpm <<= name in Linux, - packageName in Rpm <<= packageName in Linux + packageName in Rpm <<= packageName in Linux, + executableScriptName in Rpm <<= executableScriptName in Linux ) ++ inConfig(Rpm)(Seq( - normalizedName <<= name apply Project.normalizeModuleID, packageArchitecture := "noarch", rpmMetadata <<= (packageName, version, rpmRelease, rpmPrefix, packageArchitecture, rpmVendor, rpmOs, packageSummary, packageDescription, rpmAutoprov, rpmAutoreq) apply RpmMetadata, 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 62cea4fe8..0adda621a 100644 --- a/src/main/scala/com/typesafe/sbt/packager/universal/Keys.scala +++ b/src/main/scala/com/typesafe/sbt/packager/universal/Keys.scala @@ -20,7 +20,7 @@ object Keys extends UniversalKeys { def packageDoc = sbt.Keys.packageDoc def name = sbt.Keys.name def packageName = packager.Keys.packageName - def normalizedName = sbt.Keys.normalizedName + def executableScriptName = packager.Keys.executableScriptName def target = sbt.Keys.target def sourceDirectory = sbt.Keys.sourceDirectory def streams = sbt.Keys.streams 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 e43f2740a..4ba702df2 100644 --- a/src/main/scala/com/typesafe/sbt/packager/universal/UniversalPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/universal/UniversalPlugin.scala @@ -25,7 +25,8 @@ trait UniversalPlugin extends Plugin { name in Universal <<= name, name in UniversalDocs <<= name in Universal, name in UniversalSrc <<= name in Universal, - packageName in Universal <<= packageName + packageName in Universal <<= packageName, + executableScriptName in Universal <<= executableScriptName ) ++ makePackageSettingsForConfig(Universal) ++ makePackageSettingsForConfig(UniversalDocs) ++ @@ -38,7 +39,6 @@ trait UniversalPlugin extends Plugin { makePackageSettings(packageZipTarball, config)(makeTgz) ++ makePackageSettings(packageXzTarball, config)(makeTxz) ++ inConfig(config)(Seq( - normalizedName <<= name apply Project.normalizeModuleID, packageName <<= (packageName, version) apply (_ + "-" + _), mappings <<= sourceDirectory map findSources, dist <<= (packageBin, streams) map printDist, diff --git a/src/main/scala/com/typesafe/sbt/packager/windows/Keys.scala b/src/main/scala/com/typesafe/sbt/packager/windows/Keys.scala index 7c04b7128..361e3a66e 100644 --- a/src/main/scala/com/typesafe/sbt/packager/windows/Keys.scala +++ b/src/main/scala/com/typesafe/sbt/packager/windows/Keys.scala @@ -14,7 +14,7 @@ trait WindowsKeys { val wixProductConfig = TaskKey[xml.Node]("wix-product-xml", "The WIX XML configuration for a product (nested in Wix/Product elements).") val wixConfig = TaskKey[xml.Node]("wix-xml", "The WIX XML configuration for this package.") val wixFile = TaskKey[File]("wix-file", "The WIX XML file to package with.") - @deprecated("use packageBin instead!") + @deprecated("use packageBin instead!", "0.7.0") val packageMsi = TaskKey[File]("package-msi", "creates a new windows CAB file containing everything for the installation.") val candleOptions = SettingKey[Seq[String]]("candle-options", "Options to pass to the candle.exe program.") val lightOptions = SettingKey[Seq[String]]("light-options", "Options to pass to the light.exe program.") @@ -25,11 +25,12 @@ object Keys extends WindowsKeys { def target = sbt.Keys.target def mappings = sbt.Keys.mappings def name = sbt.Keys.name + def packageName = packager.Keys.packageName + def executableScriptName = packager.Keys.executableScriptName def streams = sbt.Keys.streams def sourceDirectory = sbt.Keys.sourceDirectory def packageBin = sbt.Keys.packageBin - // TODO - move this somewhere generic. - def maintainer = linux.Keys.maintainer - def packageSummary = linux.Keys.packageSummary - def packageDescription = linux.Keys.packageDescription + def maintainer = packager.Keys.maintainer + def packageSummary = packager.Keys.packageSummary + def packageDescription = packager.Keys.packageDescription } \ No newline at end of file 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 48eb0f288..a38dbb392 100644 --- a/src/main/scala/com/typesafe/sbt/packager/windows/WindowsPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/windows/WindowsPlugin.scala @@ -4,6 +4,7 @@ package windows import Keys._ import sbt._ +import sbt.Keys.{ normalizedName } trait WindowsPlugin extends Plugin { val Windows = config("windows") @@ -13,6 +14,7 @@ trait WindowsPlugin extends Plugin { target in Windows <<= target apply (_ / "windows"), // TODO - Should this use normalized name like the linux guys? name in Windows <<= name, + packageName in Windows <<= normalizedName, // Defaults so that our simplified building works candleOptions := Seq("-ext", "WixUtilExtension"), lightOptions := Seq("-ext", "WixUIExtension", diff --git a/src/sbt-test/debian/test-executableScriptName/build.sbt b/src/sbt-test/debian/test-executableScriptName/build.sbt new file mode 100644 index 000000000..d5d397098 --- /dev/null +++ b/src/sbt-test/debian/test-executableScriptName/build.sbt @@ -0,0 +1,29 @@ +import NativePackagerKeys._ + +packagerSettings + +packageArchetype.java_server + +name := "debian-test" + +executableScriptName := "debian-exec" + +version := "0.1.0" + +maintainer := "Josh Suereth " + +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-upstart-script") <<= (target, streams) map { (target, out) => + val script = IO.read(target / "debian-test-0.1.0" / "etc" / "init" / "debian-test.conf") + assert(script.contains("exec ./bin/debian-exec"), "wrong exec call\n" + script) + out.log.success("Successfully tested control script") + () +} diff --git a/src/sbt-test/debian/test-executableScriptName/project/plugins.sbt b/src/sbt-test/debian/test-executableScriptName/project/plugins.sbt new file mode 100644 index 000000000..b53de154c --- /dev/null +++ b/src/sbt-test/debian/test-executableScriptName/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version")) diff --git a/src/sbt-test/debian/test-executableScriptName/src/main/scala/test/Main.scala b/src/sbt-test/debian/test-executableScriptName/src/main/scala/test/Main.scala new file mode 100644 index 000000000..638bef378 --- /dev/null +++ b/src/sbt-test/debian/test-executableScriptName/src/main/scala/test/Main.scala @@ -0,0 +1,10 @@ +package test + +object Main { + def main (args: Array[String]) { + //server app imitation + while (true){ + Thread.sleep(1000L) + } + } +} \ No newline at end of file diff --git a/src/sbt-test/debian/test-executableScriptName/test b/src/sbt-test/debian/test-executableScriptName/test new file mode 100644 index 000000000..2e0e20140 --- /dev/null +++ b/src/sbt-test/debian/test-executableScriptName/test @@ -0,0 +1,18 @@ +# Run the debian packaging. +> debian:package-bin +$ exists target/debian-test_0.1.0_all.deb +# Testing the packageName configuration +$ exists target/debian-test-0.1.0/DEBIAN +$ exists target/debian-test-0.1.0/DEBIAN/control +# -------------------------------------------- +$ exists target/debian-test-0.1.0/usr/ +$ exists target/debian-test-0.1.0/usr/share/ +$ exists target/debian-test-0.1.0/usr/share/debian-test/ +$ exists target/debian-test-0.1.0/usr/share/debian-test/bin/ +$ exists target/debian-test-0.1.0/usr/share/debian-test/bin/debian-exec +$ exists target/debian-test-0.1.0/var/log/debian-test/ +$ exists target/debian-test-0.1.0/var/run/debian-test/ +$ exists target/debian-test-0.1.0/etc/default/debian-test/ +# -------------------------------------------- +$ exists target/debian-test-0.1.0/etc/init/debian-test.conf +> check-upstart-script diff --git a/src/sbt-test/docker/test-executableScriptName/build.sbt b/src/sbt-test/docker/test-executableScriptName/build.sbt new file mode 100644 index 000000000..c2c5eb358 --- /dev/null +++ b/src/sbt-test/docker/test-executableScriptName/build.sbt @@ -0,0 +1,21 @@ +import com.typesafe.sbt.SbtNativePackager._ +import NativePackagerKeys._ + +packageArchetype.java_application + +name := "docker-test" + +packageName in Docker := "docker-package" + +executableScriptName := "docker-exec" + +version := "0.1.0" + +maintainer := "Gary Coady " + +TaskKey[Unit]("check-dockerfile") <<= (target, streams) map { (target, out) => + val dockerfile = IO.read(target / "docker" / "Dockerfile") + assert(dockerfile.contains("ENTRYPOINT [\"bin/docker-exec\"]\n"), "dockerfile doesn't contain ENTRYPOINT [\"docker-exec\"]\n" + dockerfile) + out.log.success("Successfully tested control script") + () +} diff --git a/src/sbt-test/docker/test-executableScriptName/project/plugins.sbt b/src/sbt-test/docker/test-executableScriptName/project/plugins.sbt new file mode 100644 index 000000000..b53de154c --- /dev/null +++ b/src/sbt-test/docker/test-executableScriptName/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version")) diff --git a/src/sbt-test/docker/test-executableScriptName/src/main/scala/Main.scala b/src/sbt-test/docker/test-executableScriptName/src/main/scala/Main.scala new file mode 100644 index 000000000..61471c658 --- /dev/null +++ b/src/sbt-test/docker/test-executableScriptName/src/main/scala/Main.scala @@ -0,0 +1,3 @@ +object Main extends App { + println("Hello world") +} diff --git a/src/sbt-test/docker/test-executableScriptName/test b/src/sbt-test/docker/test-executableScriptName/test new file mode 100644 index 000000000..9e5c2f511 --- /dev/null +++ b/src/sbt-test/docker/test-executableScriptName/test @@ -0,0 +1,6 @@ +# Generate the Docker image locally +> docker:publishLocal +$ exists target/docker/Dockerfile +$ exists target/docker/files/opt/docker/bin/docker-exec +> check-dockerfile +$ exec bash -c 'docker run docker-package:0.1.0 | grep -q "Hello world"' \ No newline at end of file diff --git a/src/sbt-test/rpm/test-executableScriptName/build.sbt b/src/sbt-test/rpm/test-executableScriptName/build.sbt new file mode 100644 index 000000000..2976918e0 --- /dev/null +++ b/src/sbt-test/rpm/test-executableScriptName/build.sbt @@ -0,0 +1,49 @@ +import NativePackagerKeys._ + +packageArchetype.java_server + +name := "rpm-test" + +version := "0.1.0" + +maintainer := "Josh Suereth " + +packageSummary := "Test rpm package" + +executableScriptName := "rpm-exec" + +packageDescription := """A fun package description of our software, + with multiple lines.""" + +rpmRelease := "1" + +rpmVendor := "typesafe" + +rpmUrl := Some("http://github.com/sbt/sbt-native-packager") + +rpmLicense := Some("BSD") + +TaskKey[Unit]("check-spec-file") <<= (target, streams) map { (target, out) => + val spec = IO.read(target / "rpm" / "SPECS" / "rpm-test.spec") + out.log.success(spec) + assert(spec contains "%attr(0644,root,root) /usr/share/rpm-test/lib/rpm-test.rpm-test-0.1.0.jar", "Wrong installation path\n" + spec) + assert(spec contains "%config %attr(0755,root,root) /etc/init.d/rpm-test", "Wrong /etc/init.d/\n" + spec) + assert(spec contains "%config %attr(755,root,root) /etc/default/rpm-test", "Wrong etc default file\n" + spec) + assert(spec contains "%dir %attr(755,rpm-test,rpm-test) /var/log/rpm-test", "Wrong logging dir path\n" + spec) + assert(spec contains "%dir %attr(755,rpm-test,rpm-test) /var/run/rpm-test", "Wrong /var/run dir path\n" + spec) + out.log.success("Successfully tested rpm-test file") + () +} + +TaskKey[Unit]("unzip") <<= (packageBin in Rpm, streams) map { (rpmFile, streams) => + val rpmPath = Seq(rpmFile.getAbsolutePath) + Process("rpm2cpio" , rpmPath) #| Process("cpio -i --make-directories") ! streams.log + () +} + +TaskKey[Unit]("checkStartupScript") <<= (target, streams) map { (target, out) => + val script = IO.read(file("etc/init.d/rpm-test")) + assert(script contains "rpm-exec", "SystemV script didn't contain correct executable filename 'rpm-exec' \n" + script) + out.log.success("Successfully tested startup script start up script") + () +} \ No newline at end of file diff --git a/src/sbt-test/rpm/test-executableScriptName/project/plugins.sbt b/src/sbt-test/rpm/test-executableScriptName/project/plugins.sbt new file mode 100644 index 000000000..b53de154c --- /dev/null +++ b/src/sbt-test/rpm/test-executableScriptName/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version")) diff --git a/src/sbt-test/rpm/test-executableScriptName/src/main/scala/test/Main.scala b/src/sbt-test/rpm/test-executableScriptName/src/main/scala/test/Main.scala new file mode 100644 index 000000000..638bef378 --- /dev/null +++ b/src/sbt-test/rpm/test-executableScriptName/src/main/scala/test/Main.scala @@ -0,0 +1,10 @@ +package test + +object Main { + def main (args: Array[String]) { + //server app imitation + while (true){ + Thread.sleep(1000L) + } + } +} \ No newline at end of file diff --git a/src/sbt-test/rpm/test-executableScriptName/test b/src/sbt-test/rpm/test-executableScriptName/test new file mode 100644 index 000000000..fca66983e --- /dev/null +++ b/src/sbt-test/rpm/test-executableScriptName/test @@ -0,0 +1,14 @@ +# Run the debian packaging. +> rpm:package-bin +$ exists target/rpm/RPMS/noarch/rpm-test-0.1.0-1.noarch.rpm +$ exists target/rpm/SPECS/rpm-test.spec + +# Check files for defaults +> check-spec-file + +> unzip +# Bootscript != executable Script +$ exists etc/init.d/rpm-test +# $ exists usr/share/rpm-test/bin/rpm-exec + +> checkStartupScript \ No newline at end of file diff --git a/src/sbt-test/rpm/test-packageName/build.sbt b/src/sbt-test/rpm/test-packageName/build.sbt index f943712da..14657befb 100644 --- a/src/sbt-test/rpm/test-packageName/build.sbt +++ b/src/sbt-test/rpm/test-packageName/build.sbt @@ -27,12 +27,11 @@ TaskKey[Unit]("check-spec-file") <<= (target, streams) map { (target, out) => val spec = IO.read(target / "rpm" / "SPECS" / "rpm-package.spec") out.log.success(spec) assert(spec contains "%attr(0644,root,root) /usr/share/rpm-package/lib/rpm-test.rpm-test-0.1.0.jar", "Wrong installation path\n" + spec) - assert(spec contains "%config %attr(0755,root,root) /etc/init.d/rpm-package", "Wrong etc path path\n" + spec) - assert(spec contains "%config %attr(755,root,root) /etc/default/rpm-package", "Wrong etc default file\n" + spec) - assert(spec contains "%config %attr(0755,root,root) /etc/init.d/rpm-package", "Wrong etc path\n" + spec) - assert(spec contains "%dir %attr(755,rpm-test,rpm-test) /var/log/rpm-package", "Wrong logging dir path\n" + spec) - assert(spec contains "%dir %attr(755,rpm-test,rpm-test) /var/run/rpm-package", "Wrong /var/run dir path\n" + spec) - out.log.success("Successfully tested rpm test file") + assert(spec contains "%config %attr(0755,root,root) /etc/init.d/rpm-package", "Wrong /etc/init.d path\n" + spec) + assert(spec contains "%config %attr(755,root,root) /etc/default/rpm-package", "Wrong /etc default file\n" + spec) + assert(spec contains "%dir %attr(755,rpm-package,rpm-package) /var/log/rpm-package", "Wrong logging dir path\n" + spec) + assert(spec contains "%dir %attr(755,rpm-package,rpm-package) /var/run/rpm-package", "Wrong /var/run dir path\n" + spec) + out.log.success("Successfully tested rpm-package file") () } diff --git a/src/sbt-test/universal/test-executableScriptName/build.sbt b/src/sbt-test/universal/test-executableScriptName/build.sbt new file mode 100644 index 000000000..e59fb9447 --- /dev/null +++ b/src/sbt-test/universal/test-executableScriptName/build.sbt @@ -0,0 +1,14 @@ +import NativePackagerKeys._ + +packageArchetype.java_application + +name := "simple-test" + +executableScriptName := "simple-exec" + +version := "0.1.0" + +TaskKey[Unit]("unzip") <<= (packageBin in Universal, streams) map { (zipFile, streams) => + val args = Seq(zipFile.getAbsolutePath) + Process("unzip", args) ! streams.log +} diff --git a/src/sbt-test/universal/test-executableScriptName/project/plugins.sbt b/src/sbt-test/universal/test-executableScriptName/project/plugins.sbt new file mode 100644 index 000000000..b53de154c --- /dev/null +++ b/src/sbt-test/universal/test-executableScriptName/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version")) diff --git a/src/sbt-test/universal/test-executableScriptName/src/main/scala/Main.scala b/src/sbt-test/universal/test-executableScriptName/src/main/scala/Main.scala new file mode 100644 index 000000000..61471c658 --- /dev/null +++ b/src/sbt-test/universal/test-executableScriptName/src/main/scala/Main.scala @@ -0,0 +1,3 @@ +object Main extends App { + println("Hello world") +} diff --git a/src/sbt-test/universal/test-executableScriptName/test b/src/sbt-test/universal/test-executableScriptName/test new file mode 100644 index 000000000..f0589c769 --- /dev/null +++ b/src/sbt-test/universal/test-executableScriptName/test @@ -0,0 +1,6 @@ +# Run the zip packaging. +> show universal:package-bin +$ exists target/universal/simple-test-0.1.0.zip +> unzip +$ exists simple-test-0.1.0/bin/ +$ exists simple-test-0.1.0/bin/simple-exec \ No newline at end of file diff --git a/test-project/build.sbt b/test-project/build.sbt index 8a739faa9..5814cf6fb 100644 --- a/test-project/build.sbt +++ b/test-project/build.sbt @@ -25,6 +25,10 @@ debianPackageDependencies in Debian ++= Seq("java2-runtime", "bash (>= 2.05a-11) debianPackageRecommends in Debian += "git" +rpmVendor := "typesafe" + +rpmLicense := Some("BSD") + //debianMakePrermScript := Some(sourceDirectory.value / "deb" / "control" / "prerm") //change defaults