diff --git a/src/main/scala/com/typesafe/sbt/packager/universal/Archives.scala b/src/main/scala/com/typesafe/sbt/packager/universal/Archives.scala index 5aa6ab0c7..f5339d6d0 100644 --- a/src/main/scala/com/typesafe/sbt/packager/universal/Archives.scala +++ b/src/main/scala/com/typesafe/sbt/packager/universal/Archives.scala @@ -14,9 +14,10 @@ object Archives { * @param name of output (without extension) * @param mappings included in the output * @param top level directory + * @param options NOT USED * @return zip file */ - def makeZip(target: File, name: String, mappings: Seq[(File, String)], top: Option[String]): File = { + def makeZip(target: File, name: String, mappings: Seq[(File, String)], top: Option[String], options: Seq[String]): File = { val zip = target / (name + ".zip") // add top level directory if defined @@ -35,9 +36,10 @@ object Archives { * @param name of output (without extension) * @param mappings included in the output * @param top level directory + * @param options NOT USED * @return zip file */ - def makeNativeZip(target: File, name: String, mappings: Seq[(File, String)], top: Option[String]): File = { + def makeNativeZip(target: File, name: String, mappings: Seq[(File, String)], top: Option[String], options: Seq[String]): File = { val zip = target / (name + ".zip") // add top level directory if defined @@ -58,9 +60,10 @@ object Archives { * @param name of output (without extension) * @param mappings included in the output * @param top level directory : NOT USED + * @param options NOT USED * @return dmg file */ - def makeDmg(target: File, name: String, mappings: Seq[(File, String)], top: Option[String]): File = { + def makeDmg(target: File, name: String, mappings: Seq[(File, String)], top: Option[String], options: Seq[String]): File = { val t = target / "dmg" val dmg = target / (name + ".dmg") if (!t.isDirectory) IO.createDirectory(t) @@ -139,9 +142,9 @@ object Archives { } file(f.getAbsolutePath + ".xz") } + val makeTxz = makeTarball(xz, ".txz") _ val makeTgz = makeTarball(gzip, ".tgz") _ - val makeTar = makeTarball(identity, ".tar") _ /** * Helper method used to construct tar-related compression functions. @@ -149,10 +152,11 @@ object Archives { * @param name of output (without extension) * @param mappings included in the output * @param top level directory + * @param options for tar command * @return tar file * */ - def makeTarball(compressor: File => File, ext: String)(target: File, name: String, mappings: Seq[(File, String)], top: Option[String]): File = { + def makeTarball(compressor: File => File, ext: String)(target: File, name: String, mappings: Seq[(File, String)], top: Option[String], options: Seq[String]): File = { val relname = name val tarball = target / (name + ext) IO.withTemporaryDirectory { f => @@ -179,7 +183,9 @@ object Archives { val tmptar = f / (relname + ".tar") - Process(Seq("tar", "--force-local", "-pcvf", tmptar.getAbsolutePath) ++ distdirs, Some(rdir)).! match { + val cmd = Seq("tar") ++ options ++ Seq(tmptar.getAbsolutePath) ++ distdirs + println("Running with " + cmd.mkString(" ")) + Process(cmd, Some(rdir)).! match { case 0 => () case n => sys.error("Error tarballing " + tarball + ". Exit code: " + n) } 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 8e7bfdb64..0348a5f90 100644 --- a/src/main/scala/com/typesafe/sbt/packager/universal/Keys.scala +++ b/src/main/scala/com/typesafe/sbt/packager/universal/Keys.scala @@ -12,4 +12,5 @@ trait UniversalKeys { val dist = TaskKey[File]("dist", "Creates the distribution packages.") val stagingDirectory = SettingKey[File]("stagingDirectory", "Directory where we stage distributions/releases.") val topLevelDirectory = SettingKey[Option[String]]("topLevelDirectory", "Top level dir in compressed output file.") + val universalArchiveOptions = SettingKey[Seq[String]]("universal-archive-options", "Options passed to the tar/zip command. Scope by task") } 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 84aa154b6..5f9188518 100644 --- a/src/main/scala/com/typesafe/sbt/packager/universal/UniversalPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/universal/UniversalPlugin.scala @@ -70,7 +70,8 @@ object UniversalPlugin extends AutoPlugin { ) ++ makePackageSettingsForConfig(Universal) ++ makePackageSettingsForConfig(UniversalDocs) ++ - makePackageSettingsForConfig(UniversalSrc) + makePackageSettingsForConfig(UniversalSrc) ++ + defaultUniversalArchiveOptions /** Creates all package types for a given configuration */ private[this] def makePackageSettingsForConfig(config: Configuration): Seq[Setting[_]] = @@ -89,6 +90,11 @@ object UniversalPlugin extends AutoPlugin { target in config <<= target apply (_ / config.name) ) + private[this] def defaultUniversalArchiveOptions: Seq[Setting[_]] = Seq( + universalArchiveOptions in (Universal, packageZipTarball) := Seq("-pcvf"), + universalArchiveOptions in (Universal, packageXzTarball) := Seq("-pcvf") + ) + private[this] def printDist(dist: File, streams: TaskStreams): File = { streams.log.info("") streams.log.info("Your package is ready in " + dist.getCanonicalPath) @@ -96,12 +102,13 @@ object UniversalPlugin extends AutoPlugin { dist } - private type Packager = (File, String, Seq[(File, String)], Option[String]) => File + private type Packager = (File, String, Seq[(File, String)], Option[String], Seq[String]) => File /** Creates packaging settings for a given package key, configuration + archive type. */ private[this] def makePackageSettings(packageKey: TaskKey[File], config: Configuration)(packager: Packager): Seq[Setting[_]] = inConfig(config)(Seq( + universalArchiveOptions in packageKey := Nil, mappings in packageKey <<= mappings map checkMappings, - packageKey <<= (target, packageName, mappings in packageKey, topLevelDirectory) map packager + packageKey <<= (target, packageName, mappings in packageKey, topLevelDirectory, universalArchiveOptions in packageKey) map packager )) /** check that all mapped files actually exist */ diff --git a/src/sphinx/formats/universal.rst b/src/sphinx/formats/universal.rst index c72bbd92c..ffc1d0f22 100644 --- a/src/sphinx/formats/universal.rst +++ b/src/sphinx/formats/universal.rst @@ -170,6 +170,25 @@ Tasks Customize --------- +Universal Archive Options +~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can customize the commandline options (if used) for the different zip formats. +If you want to force local for the `tgz` output add this line: + +.. code-block:: scala + + universalArchiveOptions in (Universal, packageZipTarball) := Seq("--force-local", "-pcvf") + +This will set the cli options for the `packageZipTarball` task in the `Universal` plugin to the following sequence. +Currently these task can be customized + + ``universal:package-zip-tarball`` + `universalArchiveOptions in (Universal, packageZipTarball)` + + ``universal:package-xz-tarball`` + `universalArchiveOptions in (Universal, packageXzTarball)` + Getting Started with Universal Packaging ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ By default, all files found in the ``src/universal`` directory are included in the distribution. So, the first step