Skip to content

Commit cea4517

Browse files
authored
fix packageZipTarball defaults for UniversalDocs and UniversalSource (#1086)
* fix packageZipTarball defaults for UniversalDocs and UniversalSource Resurects #1018 * Add mappings to universalSrc/universalDocs and create working directory
1 parent ae70fa5 commit cea4517

File tree

5 files changed

+43
-25
lines changed

5 files changed

+43
-25
lines changed

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

+27-22
Original file line numberDiff line numberDiff line change
@@ -223,49 +223,54 @@ object Archives {
223223
* @param target folder to build package in
224224
* @param name of output (without extension)
225225
* @param mappings included in the output
226-
* @param top level directory
226+
* @param topDirectory level directory
227227
* @param options for tar command
228228
* @return tar file
229229
*
230230
*/
231-
def makeTarballWithOptions(
232-
compressor: File => File,
233-
ext: String
234-
)(target: File, name: String, mappings: Seq[(File, String)], top: Option[String], options: Seq[String]): File = {
235-
val relname = name
231+
def makeTarballWithOptions(compressor: File => File, ext: String)(target: File,
232+
name: String,
233+
mappings: Seq[(File, String)],
234+
topDirectory: Option[String],
235+
options: Seq[String]): File = {
236236
val tarball = target / (name + ext)
237-
IO.withTemporaryDirectory { f =>
238-
val rdir = f / relname
239-
val m2 = top map { dir =>
240-
mappings map { case (f, p) => f -> (rdir / dir / p) }
241-
} getOrElse {
242-
mappings map { case (f, p) => f -> (rdir / p) }
243-
}
237+
IO.withTemporaryDirectory { tempDirectory =>
238+
val workingDirectory = tempDirectory / name
239+
val temporaryMappings = topDirectory
240+
.map { dir =>
241+
mappings map { case (f, p) => f -> (workingDirectory / dir / p) }
242+
}
243+
.getOrElse {
244+
mappings map { case (f, p) => f -> (workingDirectory / p) }
245+
}
244246

245-
IO.copy(m2)
246-
// TODO - Is this enough?
247-
for ((from, to) <- m2 if (to.getAbsolutePath contains "/bin/") || from.canExecute) {
247+
// create the working directory
248+
IO.createDirectory(workingDirectory)
249+
IO.copy(temporaryMappings)
250+
// setExecutable does not always work. There are known issues with macOSx where
251+
// the executable flags is missing after compression.
252+
for ((from, to) <- temporaryMappings if (to.getAbsolutePath contains "/bin/") || from.canExecute) {
248253
println("Making " + to.getAbsolutePath + " executable")
249254
to.setExecutable(true, false)
250255
}
251256

252257
IO.createDirectory(tarball.getParentFile)
253258

254259
// all directories that should be zipped
255-
val distdirs = top map (_ :: Nil) getOrElse {
256-
IO.listFiles(rdir).map(_.getName).toList // no top level dir, use all available
260+
val distdirs = topDirectory.map(_ :: Nil).getOrElse {
261+
IO.listFiles(workingDirectory).map(_.getName).toList // no top level dir, use all available
257262
}
258263

259-
val tmptar = f / (relname + ".tar")
264+
val temporaryTarFile = tempDirectory / (name + ".tar")
260265

261-
val cmd = Seq("tar") ++ options ++ Seq(tmptar.getAbsolutePath) ++ distdirs
266+
val cmd = Seq("tar") ++ options ++ Seq(temporaryTarFile.getAbsolutePath) ++ distdirs
262267
println("Running with " + cmd.mkString(" "))
263-
sys.process.Process(cmd, Some(rdir)).! match {
268+
sys.process.Process(cmd, workingDirectory).! match {
264269
case 0 => ()
265270
case n =>
266271
sys.error("Error tarballing " + tarball + ". Exit code: " + n)
267272
}
268-
IO.copyFile(compressor(tmptar), tarball)
273+
IO.copyFile(compressor(temporaryTarFile), tarball)
269274
}
270275
tarball
271276
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ object UniversalPlugin extends AutoPlugin {
8686
private[this] def defaultUniversalArchiveOptions: Seq[Setting[_]] = Seq(
8787
universalArchiveOptions in (Universal, packageZipTarball) := Seq("-pcvf"),
8888
universalArchiveOptions in (Universal, packageXzTarball) := Seq("-pcvf"),
89+
universalArchiveOptions in (UniversalDocs, packageZipTarball) := Seq("-pcvf"),
8990
universalArchiveOptions in (UniversalDocs, packageXzTarball) := Seq("-pcvf"),
90-
universalArchiveOptions in (UniversalDocs, packageXzTarball) := Seq("-pcvf"),
91-
universalArchiveOptions in (UniversalSrc, packageXzTarball) := Seq("-pcvf"),
91+
universalArchiveOptions in (UniversalSrc, packageZipTarball) := Seq("-pcvf"),
9292
universalArchiveOptions in (UniversalSrc, packageXzTarball) := Seq("-pcvf")
9393
)
9494

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
enablePlugins(JavaAppPackaging)
22

33
name := "simple-test"
4-
54
version := "0.1.0"
5+
6+
// add some mappings
7+
mappings in UniversalSrc := (mappings in Universal).value
8+
mappings in UniversalDocs := (mappings in Universal).value

src/sbt-test/universal/test-zips/test

+8
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@ $ exists target/universal-src/simple-test-0.1.0.zip
99
# Run the tgz packaging.
1010
> universal:packageZipTarball
1111
$ exists target/universal/simple-test-0.1.0.tgz
12+
> universal-docs:packageZipTarball
13+
$ exists target/universal-docs/simple-test-0.1.0.tgz
14+
> universal-src:packageZipTarball
15+
$ exists target/universal-src/simple-test-0.1.0.tgz
1216

1317
# Run the txz packaging.
1418
> universal:packageXzTarball
1519
$ exists target/universal/simple-test-0.1.0.txz
20+
> universal-docs:packageXzTarball
21+
$ exists target/universal-docs/simple-test-0.1.0.txz
22+
> universal-src:packageXzTarball
23+
$ exists target/universal-src/simple-test-0.1.0.txz
1624

1725

1826
# TODO - Check contents of zips

test-project-simple/build.sbt

+2
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ rpmChangelogFile := Some("changelog.txt")
2020
javaOptions in Universal ++= Seq("-J-Xmx64m", "-J-Xms64m", "-jvm-debug 12345")
2121

2222
//bashScriptConfigLocation := Some("${app_home}/../conf/jvmopts")
23+
24+
mappings in UniversalSrc := (mappings in Universal).value

0 commit comments

Comments
 (0)