Skip to content

Commit 5d488bf

Browse files
committed
FIX #662 and make universal archive options customizable
1 parent 8e5a2cc commit 5d488bf

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

src/main/scala/com/typesafe/sbt/packager/universal/Archives.scala

+12-6
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ object Archives {
1414
* @param name of output (without extension)
1515
* @param mappings included in the output
1616
* @param top level directory
17+
* @param options NOT USED
1718
* @return zip file
1819
*/
19-
def makeZip(target: File, name: String, mappings: Seq[(File, String)], top: Option[String]): File = {
20+
def makeZip(target: File, name: String, mappings: Seq[(File, String)], top: Option[String], options: Seq[String]): File = {
2021
val zip = target / (name + ".zip")
2122

2223
// add top level directory if defined
@@ -35,9 +36,10 @@ object Archives {
3536
* @param name of output (without extension)
3637
* @param mappings included in the output
3738
* @param top level directory
39+
* @param options NOT USED
3840
* @return zip file
3941
*/
40-
def makeNativeZip(target: File, name: String, mappings: Seq[(File, String)], top: Option[String]): File = {
42+
def makeNativeZip(target: File, name: String, mappings: Seq[(File, String)], top: Option[String], options: Seq[String]): File = {
4143
val zip = target / (name + ".zip")
4244

4345
// add top level directory if defined
@@ -58,9 +60,10 @@ object Archives {
5860
* @param name of output (without extension)
5961
* @param mappings included in the output
6062
* @param top level directory : NOT USED
63+
* @param options NOT USED
6164
* @return dmg file
6265
*/
63-
def makeDmg(target: File, name: String, mappings: Seq[(File, String)], top: Option[String]): File = {
66+
def makeDmg(target: File, name: String, mappings: Seq[(File, String)], top: Option[String], options: Seq[String]): File = {
6467
val t = target / "dmg"
6568
val dmg = target / (name + ".dmg")
6669
if (!t.isDirectory) IO.createDirectory(t)
@@ -139,20 +142,21 @@ object Archives {
139142
}
140143
file(f.getAbsolutePath + ".xz")
141144
}
145+
142146
val makeTxz = makeTarball(xz, ".txz") _
143147
val makeTgz = makeTarball(gzip, ".tgz") _
144-
val makeTar = makeTarball(identity, ".tar") _
145148

146149
/**
147150
* Helper method used to construct tar-related compression functions.
148151
* @param target folder to build package in
149152
* @param name of output (without extension)
150153
* @param mappings included in the output
151154
* @param top level directory
155+
* @param options for tar command
152156
* @return tar file
153157
*
154158
*/
155-
def makeTarball(compressor: File => File, ext: String)(target: File, name: String, mappings: Seq[(File, String)], top: Option[String]): File = {
159+
def makeTarball(compressor: File => File, ext: String)(target: File, name: String, mappings: Seq[(File, String)], top: Option[String], options: Seq[String]): File = {
156160
val relname = name
157161
val tarball = target / (name + ext)
158162
IO.withTemporaryDirectory { f =>
@@ -179,7 +183,9 @@ object Archives {
179183

180184
val tmptar = f / (relname + ".tar")
181185

182-
Process(Seq("tar", "--force-local", "-pcvf", tmptar.getAbsolutePath) ++ distdirs, Some(rdir)).! match {
186+
val cmd = Seq("tar") ++ options ++ Seq(tmptar.getAbsolutePath) ++ distdirs
187+
println("Running with " + cmd.mkString(" "))
188+
Process(cmd, Some(rdir)).! match {
183189
case 0 => ()
184190
case n => sys.error("Error tarballing " + tarball + ". Exit code: " + n)
185191
}

src/main/scala/com/typesafe/sbt/packager/universal/Keys.scala

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ trait UniversalKeys {
1212
val dist = TaskKey[File]("dist", "Creates the distribution packages.")
1313
val stagingDirectory = SettingKey[File]("stagingDirectory", "Directory where we stage distributions/releases.")
1414
val topLevelDirectory = SettingKey[Option[String]]("topLevelDirectory", "Top level dir in compressed output file.")
15+
val universalArchiveOptions = SettingKey[Seq[String]]("universal-archive-options", "Options passed to the tar/zip command. Scope by task")
1516
}

src/main/scala/com/typesafe/sbt/packager/universal/UniversalPlugin.scala

+10-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ object UniversalPlugin extends AutoPlugin {
7070
) ++
7171
makePackageSettingsForConfig(Universal) ++
7272
makePackageSettingsForConfig(UniversalDocs) ++
73-
makePackageSettingsForConfig(UniversalSrc)
73+
makePackageSettingsForConfig(UniversalSrc) ++
74+
defaultUniversalArchiveOptions
7475

7576
/** Creates all package types for a given configuration */
7677
private[this] def makePackageSettingsForConfig(config: Configuration): Seq[Setting[_]] =
@@ -89,19 +90,25 @@ object UniversalPlugin extends AutoPlugin {
8990
target in config <<= target apply (_ / config.name)
9091
)
9192

93+
private[this] def defaultUniversalArchiveOptions: Seq[Setting[_]] = Seq(
94+
universalArchiveOptions in (Universal, packageZipTarball) := Seq("-pcvf"),
95+
universalArchiveOptions in (Universal, packageXzTarball) := Seq("-pcvf")
96+
)
97+
9298
private[this] def printDist(dist: File, streams: TaskStreams): File = {
9399
streams.log.info("")
94100
streams.log.info("Your package is ready in " + dist.getCanonicalPath)
95101
streams.log.info("")
96102
dist
97103
}
98104

99-
private type Packager = (File, String, Seq[(File, String)], Option[String]) => File
105+
private type Packager = (File, String, Seq[(File, String)], Option[String], Seq[String]) => File
100106
/** Creates packaging settings for a given package key, configuration + archive type. */
101107
private[this] def makePackageSettings(packageKey: TaskKey[File], config: Configuration)(packager: Packager): Seq[Setting[_]] =
102108
inConfig(config)(Seq(
109+
universalArchiveOptions in packageKey := Nil,
103110
mappings in packageKey <<= mappings map checkMappings,
104-
packageKey <<= (target, packageName, mappings in packageKey, topLevelDirectory) map packager
111+
packageKey <<= (target, packageName, mappings in packageKey, topLevelDirectory, universalArchiveOptions in packageKey) map packager
105112
))
106113

107114
/** check that all mapped files actually exist */

src/sphinx/formats/universal.rst

+19
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,25 @@ Tasks
170170
Customize
171171
---------
172172

173+
Universal Archive Options
174+
~~~~~~~~~~~~~~~~~~~~~~~~~
175+
176+
You can customize the commandline options (if used) for the different zip formats.
177+
If you want to force local for the `tgz` output add this line:
178+
179+
.. code-block:: scala
180+
181+
universalArchiveOptions in (Universal, packageZipTarball) := Seq("--force-local", "-pcvf")
182+
183+
This will set the cli options for the `packageZipTarball` task in the `Universal` plugin to the following sequence.
184+
Currently these task can be customized
185+
186+
``universal:package-zip-tarball``
187+
`universalArchiveOptions in (Universal, packageZipTarball)`
188+
189+
``universal:package-xz-tarball``
190+
`universalArchiveOptions in (Universal, packageXzTarball)`
191+
173192
Getting Started with Universal Packaging
174193
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
175194
By default, all files found in the ``src/universal`` directory are included in the distribution. So, the first step

0 commit comments

Comments
 (0)