Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix packageZipTarball defaults for UniversalDocs and UniversalSource #1086

Merged
merged 2 commits into from
Jan 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 27 additions & 22 deletions src/main/scala/com/typesafe/sbt/packager/universal/Archives.scala
Original file line number Diff line number Diff line change
Expand Up @@ -223,49 +223,54 @@ 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)
}

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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)

Expand Down
5 changes: 4 additions & 1 deletion src/sbt-test/universal/test-zips/build.sbt
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions src/sbt-test/universal/test-zips/test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These commands don't seem to work at all.

$ 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
2 changes: 2 additions & 0 deletions test-project-simple/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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