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 bf2e20bb4..0e6d6d54a 100644 --- a/src/main/scala/com/typesafe/sbt/packager/universal/Archives.scala +++ b/src/main/scala/com/typesafe/sbt/packager/universal/Archives.scala @@ -223,28 +223,33 @@ object Archives { * @param target folder to build package in * @param name of output (without extension) * @param mappings included in the output - * @param top level directory + * @param topDirectory level directory * @param options for tar command * @return tar file * */ - def makeTarballWithOptions( - compressor: File => File, - ext: String - )(target: File, name: String, mappings: Seq[(File, String)], top: Option[String], options: Seq[String]): File = { - val relname = name + def makeTarballWithOptions(compressor: File => File, ext: String)(target: File, + name: String, + mappings: Seq[(File, String)], + topDirectory: Option[String], + options: Seq[String]): File = { val tarball = target / (name + ext) - IO.withTemporaryDirectory { f => - val rdir = f / relname - val m2 = top map { dir => - mappings map { case (f, p) => f -> (rdir / dir / p) } - } getOrElse { - mappings map { case (f, p) => f -> (rdir / p) } - } + IO.withTemporaryDirectory { tempDirectory => + val workingDirectory = tempDirectory / name + val temporaryMappings = topDirectory + .map { dir => + mappings map { case (f, p) => f -> (workingDirectory / dir / p) } + } + .getOrElse { + mappings map { case (f, p) => f -> (workingDirectory / p) } + } - IO.copy(m2) - // TODO - Is this enough? - for ((from, to) <- m2 if (to.getAbsolutePath contains "/bin/") || from.canExecute) { + // create the working directory + IO.createDirectory(workingDirectory) + IO.copy(temporaryMappings) + // setExecutable does not always work. There are known issues with macOSx where + // the executable flags is missing after compression. + for ((from, to) <- temporaryMappings if (to.getAbsolutePath contains "/bin/") || from.canExecute) { println("Making " + to.getAbsolutePath + " executable") to.setExecutable(true, false) } @@ -252,20 +257,20 @@ object Archives { IO.createDirectory(tarball.getParentFile) // all directories that should be zipped - val distdirs = top map (_ :: Nil) getOrElse { - IO.listFiles(rdir).map(_.getName).toList // no top level dir, use all available + val distdirs = topDirectory.map(_ :: Nil).getOrElse { + IO.listFiles(workingDirectory).map(_.getName).toList // no top level dir, use all available } - val tmptar = f / (relname + ".tar") + val temporaryTarFile = tempDirectory / (name + ".tar") - val cmd = Seq("tar") ++ options ++ Seq(tmptar.getAbsolutePath) ++ distdirs + val cmd = Seq("tar") ++ options ++ Seq(temporaryTarFile.getAbsolutePath) ++ distdirs println("Running with " + cmd.mkString(" ")) - sys.process.Process(cmd, Some(rdir)).! match { + sys.process.Process(cmd, workingDirectory).! match { case 0 => () case n => sys.error("Error tarballing " + tarball + ". Exit code: " + n) } - IO.copyFile(compressor(tmptar), tarball) + IO.copyFile(compressor(temporaryTarFile), tarball) } tarball } 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 e37bc6b6e..e733b9272 100644 --- a/src/main/scala/com/typesafe/sbt/packager/universal/UniversalPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/universal/UniversalPlugin.scala @@ -86,9 +86,9 @@ object UniversalPlugin extends AutoPlugin { private[this] def defaultUniversalArchiveOptions: Seq[Setting[_]] = Seq( universalArchiveOptions in (Universal, packageZipTarball) := Seq("-pcvf"), universalArchiveOptions in (Universal, packageXzTarball) := Seq("-pcvf"), + universalArchiveOptions in (UniversalDocs, packageZipTarball) := Seq("-pcvf"), universalArchiveOptions in (UniversalDocs, packageXzTarball) := Seq("-pcvf"), - universalArchiveOptions in (UniversalDocs, packageXzTarball) := Seq("-pcvf"), - universalArchiveOptions in (UniversalSrc, packageXzTarball) := Seq("-pcvf"), + universalArchiveOptions in (UniversalSrc, packageZipTarball) := Seq("-pcvf"), universalArchiveOptions in (UniversalSrc, packageXzTarball) := Seq("-pcvf") ) diff --git a/src/sbt-test/universal/test-zips/build.sbt b/src/sbt-test/universal/test-zips/build.sbt index b72e96af7..5b6321874 100644 --- a/src/sbt-test/universal/test-zips/build.sbt +++ b/src/sbt-test/universal/test-zips/build.sbt @@ -1,5 +1,8 @@ enablePlugins(JavaAppPackaging) name := "simple-test" - version := "0.1.0" + +// add some mappings +mappings in UniversalSrc := (mappings in Universal).value +mappings in UniversalDocs := (mappings in Universal).value diff --git a/src/sbt-test/universal/test-zips/test b/src/sbt-test/universal/test-zips/test index cd0caebb5..4bea834a3 100644 --- a/src/sbt-test/universal/test-zips/test +++ b/src/sbt-test/universal/test-zips/test @@ -9,10 +9,18 @@ $ exists target/universal-src/simple-test-0.1.0.zip # Run the tgz packaging. > universal:packageZipTarball $ exists target/universal/simple-test-0.1.0.tgz +> universal-docs:packageZipTarball +$ exists target/universal-docs/simple-test-0.1.0.tgz +> universal-src:packageZipTarball +$ exists target/universal-src/simple-test-0.1.0.tgz # Run the txz packaging. > universal:packageXzTarball $ exists target/universal/simple-test-0.1.0.txz +> universal-docs:packageXzTarball +$ exists target/universal-docs/simple-test-0.1.0.txz +> universal-src:packageXzTarball +$ exists target/universal-src/simple-test-0.1.0.txz # TODO - Check contents of zips diff --git a/test-project-simple/build.sbt b/test-project-simple/build.sbt index 5e3d2d622..c6cf30b26 100644 --- a/test-project-simple/build.sbt +++ b/test-project-simple/build.sbt @@ -20,3 +20,5 @@ rpmChangelogFile := Some("changelog.txt") javaOptions in Universal ++= Seq("-J-Xmx64m", "-J-Xms64m", "-jvm-debug 12345") //bashScriptConfigLocation := Some("${app_home}/../conf/jvmopts") + +mappings in UniversalSrc := (mappings in Universal).value