From 6c09a1874290c7d884139f5f541099022ea197fb Mon Sep 17 00:00:00 2001 From: Nepomuk Seiler Date: Wed, 1 Oct 2014 10:28:36 +0200 Subject: [PATCH] Formatting --- .../archetypes/JavaServerApplication.scala | 42 +++--- .../sbt/packager/debian/DebianPlugin.scala | 122 +++++++++--------- .../typesafe/sbt/packager/rpm/RpmHelper.scala | 2 +- 3 files changed, 83 insertions(+), 83 deletions(-) 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 0642406b6..a35d4eeea 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala @@ -56,7 +56,7 @@ object JavaServerAppPackaging { map makeEtcDefaultScript, linuxPackageMappings <++= (makeEtcDefault, packageName in Linux) map { (conf, name) => conf.map(c => LinuxPackageMapping(Seq(c -> ("/etc/default/" + name)), - LinuxFileMetaData(Users.Root, Users.Root, "644")).withConfig()).toSeq + LinuxFileMetaData(Users.Root, Users.Root, "644")).withConfig()).toSeq }, // === /var/run/app pid folder === @@ -76,20 +76,20 @@ object JavaServerAppPackaging { requiredStopFacilities <<= (serverLoading) apply defaultFacilities, // === Startscript creation === linuxScriptReplacements <++= (requiredStartFacilities, requiredStopFacilities, startRunlevels, stopRunlevels, serverLoading) apply - makeStartScriptReplacements, + makeStartScriptReplacements, linuxScriptReplacements += JavaServerLoaderScript.loaderFunctionsReplacement(serverLoading.value, ARCHETYPE), linuxStartScriptTemplate := JavaServerLoaderScript( - script = startScriptName(serverLoading.value, Debian), - loader = serverLoading.value, - archetype = ARCHETYPE, - template = Option(sourceDirectory.value / "templates" / "start") + script = startScriptName(serverLoading.value, Debian), + loader = serverLoading.value, + archetype = ARCHETYPE, + template = Option(sourceDirectory.value / "templates" / "start") ), defaultLinuxStartScriptLocation <<= serverLoading apply getStartScriptLocation, linuxMakeStartScript in Debian <<= (linuxStartScriptTemplate in Debian, - linuxScriptReplacements in Debian, - target in Universal, - serverLoading in Debian) map makeStartScript, + linuxScriptReplacements in Debian, + target in Universal, + serverLoading in Debian) map makeStartScript, linuxPackageMappings <++= (packageName, linuxMakeStartScript, serverLoading, defaultLinuxStartScriptLocation) map startScriptMapping )) ++ Seq( // === Maintainer scripts === @@ -108,20 +108,20 @@ object JavaServerAppPackaging { requiredStartFacilities in Rpm <<= (serverLoading) apply defaultFacilities, requiredStopFacilities in Rpm <<= (serverLoading) apply defaultFacilities, linuxScriptReplacements <++= (requiredStartFacilities, requiredStopFacilities, startRunlevels, stopRunlevels, serverLoading) apply - makeStartScriptReplacements, + makeStartScriptReplacements, linuxScriptReplacements += JavaServerLoaderScript.loaderFunctionsReplacement(serverLoading.value, ARCHETYPE) )) ++ Seq( // === Startscript creation === linuxStartScriptTemplate := JavaServerLoaderScript( - script = startScriptName((serverLoading in Rpm).value, Rpm), - loader = (serverLoading in Rpm).value, - archetype = ARCHETYPE, - template = Option(sourceDirectory.value / "templates" / "start") + script = startScriptName((serverLoading in Rpm).value, Rpm), + loader = (serverLoading in Rpm).value, + archetype = ARCHETYPE, + template = Option(sourceDirectory.value / "templates" / "start") ), linuxMakeStartScript in Rpm <<= (linuxStartScriptTemplate in Rpm, - linuxScriptReplacements in Rpm, - target in Universal, - serverLoading in Rpm) map makeStartScript, + linuxScriptReplacements in Rpm, + target in Universal, + serverLoading in Rpm) map makeStartScript, defaultLinuxStartScriptLocation in Rpm <<= (serverLoading in Rpm) apply getStartScriptLocation, linuxPackageMappings in Rpm <++= (packageName in Rpm, linuxMakeStartScript in Rpm, serverLoading in Rpm, defaultLinuxStartScriptLocation in Rpm) map startScriptMapping, @@ -129,16 +129,16 @@ object JavaServerAppPackaging { // == Maintainer scripts === // TODO this is very basic - align debian and rpm plugin rpmPre <<= (rpmScriptsDirectory, rpmPre, linuxScriptReplacements in Rpm, serverLoading in Rpm) apply { - (dir, pre, replacements, loader) => rpmScriptletContent(dir, Pre, replacements, pre) + (dir, pre, replacements, loader) => rpmScriptletContent(dir, Pre, replacements, pre) }, rpmPost <<= (rpmScriptsDirectory, rpmPost, linuxScriptReplacements in Rpm, serverLoading in Rpm) apply { - (dir, post, replacements, loader) => rpmScriptletContent(dir, Post, replacements, post) + (dir, post, replacements, loader) => rpmScriptletContent(dir, Post, replacements, post) }, rpmPostun <<= (rpmScriptsDirectory, rpmPostun, linuxScriptReplacements in Rpm, serverLoading in Rpm) apply { - (dir, postun, replacements, loader) => rpmScriptletContent(dir, Postun, replacements, postun) + (dir, postun, replacements, loader) => rpmScriptletContent(dir, Postun, replacements, postun) }, rpmPreun <<= (rpmScriptsDirectory, rpmPreun, linuxScriptReplacements in Rpm, serverLoading in Rpm) apply { - (dir, preun, replacements, loader) => rpmScriptletContent(dir, Preun, replacements, preun) + (dir, preun, replacements, loader) => rpmScriptletContent(dir, Preun, replacements, preun) } ) } 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 3bcbd6b48..d18200fe1 100644 --- a/src/main/scala/com/typesafe/sbt/packager/debian/DebianPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/debian/DebianPlugin.scala @@ -9,7 +9,7 @@ import linux.{ LinuxFileMetaData, LinuxPackageMapping, LinuxSymlink } import linux.Keys.{ linuxScriptReplacements, daemonShell } import com.typesafe.sbt.packager.Hashing import com.typesafe.sbt.packager.archetypes.TemplateWriter -import com.typesafe.sbt.packager.linux.LinuxPackageMapping +import com.typesafe.sbt.packager.linux.LinuxPackageMapping trait DebianPlugin extends Plugin with linux.LinuxPlugin with NativePackaging with JDebPackaging { val Debian = config("debian") extend Linux @@ -17,9 +17,9 @@ trait DebianPlugin extends Plugin with linux.LinuxPlugin with NativePackaging wi import com.typesafe.sbt.packager.universal.Archives import DebianPlugin.Names - import DebianPlugin.defaultMaintainerScript + import DebianPlugin.defaultMaintainerScript import linux.LinuxPlugin.Users - import SbtNativePackager.Universal + import SbtNativePackager.Universal def debianSettings: Seq[Setting[_]] = Seq( /* ==== Debian default settings ==== */ @@ -41,10 +41,10 @@ trait DebianPlugin extends Plugin with linux.LinuxPlugin with NativePackaging wi /* ==== Debian configuration settings ==== */ debianControlScriptsDirectory <<= (sourceDirectory) apply (_ / "debian" / Names.Debian), debianMaintainerScripts := Seq.empty, - debianMakePreinstScript := defaultMaintainerScript(Names.Preinst, linuxScriptReplacements.value, (target in Universal).value), - debianMakePrermScript := defaultMaintainerScript(Names.Prerm, linuxScriptReplacements.value, (target in Universal).value), - debianMakePostinstScript := defaultMaintainerScript(Names.Postinst, linuxScriptReplacements.value, (target in Universal).value), - debianMakePostrmScript := defaultMaintainerScript(Names.Postrm, linuxScriptReplacements.value, (target in Universal).value), + debianMakePreinstScript := defaultMaintainerScript(Names.Preinst, linuxScriptReplacements.value, (target in Universal).value), + debianMakePrermScript := defaultMaintainerScript(Names.Prerm, linuxScriptReplacements.value, (target in Universal).value), + debianMakePostinstScript := defaultMaintainerScript(Names.Postinst, linuxScriptReplacements.value, (target in Universal).value), + debianMakePostrmScript := defaultMaintainerScript(Names.Postrm, linuxScriptReplacements.value, (target in Universal).value), debianChangelog := None, /* ==== Debian maintainer scripts ==== */ @@ -98,7 +98,7 @@ trait DebianPlugin extends Plugin with linux.LinuxPlugin with NativePackaging wi (mappings, dir) => val md5file = dir / Names.Debian / "md5sums" val md5sums = for { - (file, name) <- (dir.*** --- dir pair relativeTo(dir)) + (file, name) <- (dir.*** --- dir pair relativeTo(dir)) if file.isFile if !(name startsWith Names.Debian) if !(name contains "debian-binary") @@ -110,10 +110,10 @@ trait DebianPlugin extends Plugin with linux.LinuxPlugin with NativePackaging wi chmod(md5file, "0644") md5file }, - debianMakeChownReplacements <<= (linuxPackageMappings, streams) map makeChownReplacements, - debianExplodedPackage <<= (linuxPackageMappings, debianControlFile, debianMaintainerScripts, debianConffilesFile, debianChangelog, daemonShell in Linux, - linuxScriptReplacements, debianMakeChownReplacements, linuxPackageSymlinks, target, streams) - map { (mappings, _, maintScripts, _, changelog, shell, replacements, chown, symlinks, t, streams) => + debianMakeChownReplacements <<= (linuxPackageMappings, streams) map makeChownReplacements, + debianExplodedPackage <<= (linuxPackageMappings, debianControlFile, debianMaintainerScripts, debianConffilesFile, debianChangelog, daemonShell in Linux, + linuxScriptReplacements, debianMakeChownReplacements, linuxPackageSymlinks, target, streams) + map { (mappings, _, maintScripts, _, changelog, shell, replacements, chown, symlinks, t, streams) => // Create files and directories mappings foreach { @@ -140,14 +140,14 @@ trait DebianPlugin extends Plugin with linux.LinuxPlugin with NativePackaging wi for ((file, name) <- maintScripts) { val targetFile = t / Names.Debian / name copyAndFixPerms(file, targetFile, LinuxFileMetaData()) - filterAndFixPerms(targetFile, chown +: replacements, LinuxFileMetaData()) + filterAndFixPerms(targetFile, chown +: replacements, LinuxFileMetaData()) } t }, // Setting the packaging strategy - packageBin <<= debianNativePackaging, - // Replacement for ${{header}} as debian control scripts are bash scripts - linuxScriptReplacements += ("header" -> "#!/bin/sh\n") + packageBin <<= debianNativePackaging, + // Replacement for ${{header}} as debian control scripts are bash scripts + linuxScriptReplacements += ("header" -> "#!/bin/sh\n") // Adding package specific implementation settings ) ++ debianNativeSettings ++ debianJDebSettings) @@ -226,42 +226,42 @@ trait DebianPlugin extends Plugin with linux.LinuxPlugin with NativePackaging wi appName + "_" + version + "_" + arch + ".changes" } - /** - * Debian assumes the application chowns the necessary files and directories in the - * control scripts (Pre/Postinst). - * - * This method generates a replacement which can be inserted in bash script to chown - * all files which are not root. While adding the chown commands it checks if the users - * and groups have valid names. - * - * @param mappings - all mapped files - * @param streams - logging - * @return (CHOWN_REPLACEMENT -> ".. list of chown commands") - */ - private[debian] def makeChownReplacements(mappings: Seq[LinuxPackageMapping], streams: TaskStreams): (String, String) = { + /** + * Debian assumes the application chowns the necessary files and directories in the + * control scripts (Pre/Postinst). + * + * This method generates a replacement which can be inserted in bash script to chown + * all files which are not root. While adding the chown commands it checks if the users + * and groups have valid names. + * + * @param mappings - all mapped files + * @param streams - logging + * @return (CHOWN_REPLACEMENT -> ".. list of chown commands") + */ + private[debian] def makeChownReplacements(mappings: Seq[LinuxPackageMapping], streams: TaskStreams): (String, String) = { // how to create the chownCmd. TODO maybe configurable? - def chownCmd(user: String, group: String)(path: String): String = s"chown $user:$group $path" - - val header = "# Chown definitions created by SBT Native Packager\n" + def chownCmd(user: String, group: String)(path: String): String = s"chown $user:$group $path" + + val header = "# Chown definitions created by SBT Native Packager\n" // Check for non root user/group and create chown commands // filter all root mappings, map to (user,group) key, group by, append everything - val chowns = mappings filter { - case LinuxPackageMapping(_, LinuxFileMetaData(Users.Root, Users.Root, _, _, _), _) => false - case _ => true - } map { - case LinuxPackageMapping(paths, meta, _) => (meta.user, meta.group) -> paths - } groupBy (_._1) map { - case ((user, group), pathList) => - validateUserGroupNames(user, streams) - validateUserGroupNames(group, streams) - val chown = chownCmd(user, group) _ - // remove key, flatten it and then use mapping path (_.2) to create chown command - pathList.map(_._2).flatten map (m => chown(m._2)) - } - val replacement = header :: chowns.flatten.toList mkString "\n" - DebianPlugin.CHOWN_REPLACEMENT -> replacement - } - + val chowns = mappings filter { + case LinuxPackageMapping(_, LinuxFileMetaData(Users.Root, Users.Root, _, _, _), _) => false + case _ => true + } map { + case LinuxPackageMapping(paths, meta, _) => (meta.user, meta.group) -> paths + } groupBy (_._1) map { + case ((user, group), pathList) => + validateUserGroupNames(user, streams) + validateUserGroupNames(group, streams) + val chown = chownCmd(user, group) _ + // remove key, flatten it and then use mapping path (_.2) to create chown command + pathList.map(_._2).flatten map (m => chown(m._2)) + } + val replacement = header :: chowns.flatten.toList mkString "\n" + DebianPlugin.CHOWN_REPLACEMENT -> replacement + } + } /** @@ -284,16 +284,16 @@ object DebianPlugin { val Changelog = "changelog" val Files = "files" } - - val CHOWN_REPLACEMENT = "chown-paths" - - def defaultMaintainerScript(name: String, replacements: Seq[(String, String)], tmpDir: File): Option[File] = { - val url = Option(getClass getResource s"$name-template") - url map { source => - val scriptBits = TemplateWriter.generateScript(source, replacements) - val script = tmpDir / "tmp" / "etc" / "default" / name - IO.write(script, scriptBits) - script - } - } + + val CHOWN_REPLACEMENT = "chown-paths" + + def defaultMaintainerScript(name: String, replacements: Seq[(String, String)], tmpDir: File): Option[File] = { + val url = Option(getClass getResource s"$name-template") + url map { source => + val scriptBits = TemplateWriter.generateScript(source, replacements) + val script = tmpDir / "tmp" / "etc" / "default" / name + IO.write(script, scriptBits) + script + } + } } diff --git a/src/main/scala/com/typesafe/sbt/packager/rpm/RpmHelper.scala b/src/main/scala/com/typesafe/sbt/packager/rpm/RpmHelper.scala index afbaeed48..b375e6042 100644 --- a/src/main/scala/com/typesafe/sbt/packager/rpm/RpmHelper.scala +++ b/src/main/scala/com/typesafe/sbt/packager/rpm/RpmHelper.scala @@ -85,7 +85,7 @@ object RpmHelper { ) ++ Seq(spec.meta.name + ".spec") log.debug("Executing rpmbuild with: " + args.mkString(" ")) (Process(args, Some(specsDir)) ! log) match { - case 0 => () + case 0 => () case code => sys.error("Unable to run rpmbuild, check output for details. Errorcode " + code) } }