From a5b70150048242c5887e9ab42780cab249f6844d Mon Sep 17 00:00:00 2001 From: Alexey Kardapoltsev Date: Sat, 16 Aug 2014 16:09:53 +0600 Subject: [PATCH 1/3] FIX #324 adding empty dirs to deb package --- .../typesafe/sbt/packager/debian/JDebPackaging.scala | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/scala/com/typesafe/sbt/packager/debian/JDebPackaging.scala b/src/main/scala/com/typesafe/sbt/packager/debian/JDebPackaging.scala index c037fde3b..b5a109150 100644 --- a/src/main/scala/com/typesafe/sbt/packager/debian/JDebPackaging.scala +++ b/src/main/scala/com/typesafe/sbt/packager/debian/JDebPackaging.scala @@ -4,9 +4,8 @@ package debian import Keys._ import sbt._ -import sbt.Keys.{ target, name, normalizedName, TaskStreams } -import linux.{ LinuxFileMetaData, LinuxPackageMapping, LinuxSymlink } -import linux.Keys.{ linuxScriptReplacements, daemonShell } +import sbt.Keys.{ target, normalizedName } +import linux.{ LinuxSymlink } import com.typesafe.sbt.packager.linux.LinuxPackageMapping import scala.collection.JavaConversions._ @@ -63,12 +62,11 @@ trait JDebPackaging { this: DebianPlugin with linux.LinuxPlugin => */ private[debian] def fileAndDirectoryProducers(mappings: Seq[LinuxPackageMapping], target: File): Seq[DataProducer] = mappings.map { case LinuxPackageMapping(paths, perms, zipped) => - // TODO implement mappers here or use the maintainerscripts logic? - val (dirs, files) = paths.partition(_._1.isDirectory) paths map { case (path, name) if path.isDirectory => val permMapper = new PermMapper(-1, -1, perms.user, perms.group, null, perms.permissions, -1, null) - new DataProducerDirectory(target / name, null, Array("**"), Array(permMapper)) + val dirName = if (name.startsWith("/")) name.drop(1) else name + new DataProducerDirectory(target, Array(dirName), null, Array(permMapper)) case (path, name) => val permMapper = new PermMapper(-1, -1, perms.user, perms.group, perms.permissions, null, -1, null) new DataProducerFile(target / name, name, null, null, Array(permMapper)) From 78f9f0fa0274e8055767771c73721c92eb8c5d84 Mon Sep 17 00:00:00 2001 From: Alexey Kardapoltsev Date: Mon, 18 Aug 2014 14:06:06 +0600 Subject: [PATCH 2/3] test for directories mappings within jdeb packaging --- .../debian/jdeb-dir-mappings/build.sbt | 40 +++++++++++++++++++ .../jdeb-dir-mappings/project/plugins.sbt | 1 + .../src/resources/conf/application.conf | 0 .../src/resources/conf/log4j.properties | 0 src/sbt-test/debian/jdeb-dir-mappings/test | 4 ++ 5 files changed, 45 insertions(+) create mode 100644 src/sbt-test/debian/jdeb-dir-mappings/build.sbt create mode 100644 src/sbt-test/debian/jdeb-dir-mappings/project/plugins.sbt create mode 100644 src/sbt-test/debian/jdeb-dir-mappings/src/resources/conf/application.conf create mode 100644 src/sbt-test/debian/jdeb-dir-mappings/src/resources/conf/log4j.properties create mode 100644 src/sbt-test/debian/jdeb-dir-mappings/test diff --git a/src/sbt-test/debian/jdeb-dir-mappings/build.sbt b/src/sbt-test/debian/jdeb-dir-mappings/build.sbt new file mode 100644 index 000000000..e4459cf1b --- /dev/null +++ b/src/sbt-test/debian/jdeb-dir-mappings/build.sbt @@ -0,0 +1,40 @@ +import NativePackagerKeys._ + +packagerSettings + +mapGenericFilesToLinux + +name := "debian-test" + +version := "0.1.0" + +maintainer := "Josh Suereth " + +packageSummary := "Test debian package" + +packageDescription := """A fun package description of our software, + with multiple lines.""" + +debianPackageDependencies in Debian ++= Seq("java2-runtime", "bash (>= 2.05a-11)") + +debianPackageRecommends in Debian += "git" + +linuxPackageMappings in Debian += packageDirectoryAndContentsMapping( + (baseDirectory.value / "src" / "resources" / "conf") -> "/usr/share/conf") + +linuxPackageMappings in Debian += packageDirectoryAndContentsMapping( + (baseDirectory.value / "src" / "resources" / "empty") -> "/var/empty") + +packageBin in Debian <<= debianJDebPackaging in Debian + +TaskKey[Unit]("check-dir-mappings") <<= (target, streams) map { (target, out) => +// val tmpDir = java.nio.file.Files.createTempDirectory("jdeb") + val extracted = file("/tmp/jdeb" + System.currentTimeMillis().toString) + Seq("dpkg-deb", "-R", (target / "debian-test_0.1.0_all.deb").absolutePath, extracted.absolutePath).! + assert((extracted / "usr/share/conf/application.conf").exists(), "File application.conf not exists") + assert((extracted / "usr/share/conf/log4j.properties").exists(), "File log4j.properties not exists") + assert((extracted / "var/empty").exists(), "Empty dir not exists") +// extracted.delete() + out.log.success("Successfully tested control script") + () +} diff --git a/src/sbt-test/debian/jdeb-dir-mappings/project/plugins.sbt b/src/sbt-test/debian/jdeb-dir-mappings/project/plugins.sbt new file mode 100644 index 000000000..b53de154c --- /dev/null +++ b/src/sbt-test/debian/jdeb-dir-mappings/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version")) diff --git a/src/sbt-test/debian/jdeb-dir-mappings/src/resources/conf/application.conf b/src/sbt-test/debian/jdeb-dir-mappings/src/resources/conf/application.conf new file mode 100644 index 000000000..e69de29bb diff --git a/src/sbt-test/debian/jdeb-dir-mappings/src/resources/conf/log4j.properties b/src/sbt-test/debian/jdeb-dir-mappings/src/resources/conf/log4j.properties new file mode 100644 index 000000000..e69de29bb diff --git a/src/sbt-test/debian/jdeb-dir-mappings/test b/src/sbt-test/debian/jdeb-dir-mappings/test new file mode 100644 index 000000000..2adb1b9c5 --- /dev/null +++ b/src/sbt-test/debian/jdeb-dir-mappings/test @@ -0,0 +1,4 @@ +# Run the debian packaging. +> debian:package-bin +$ exists target/debian-test_0.1.0_all.deb +> check-dir-mappings From 29fc5aa3353e6d252a98f21bfbe3f9e33cc54881 Mon Sep 17 00:00:00 2001 From: Alexey Kardapoltsev Date: Tue, 19 Aug 2014 00:07:39 +0600 Subject: [PATCH 3/3] fixing empty directory mapping test --- src/sbt-test/debian/jdeb-dir-mappings/build.sbt | 2 +- src/sbt-test/debian/jdeb-dir-mappings/test | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sbt-test/debian/jdeb-dir-mappings/build.sbt b/src/sbt-test/debian/jdeb-dir-mappings/build.sbt index e4459cf1b..a59e4f1d3 100644 --- a/src/sbt-test/debian/jdeb-dir-mappings/build.sbt +++ b/src/sbt-test/debian/jdeb-dir-mappings/build.sbt @@ -34,7 +34,7 @@ TaskKey[Unit]("check-dir-mappings") <<= (target, streams) map { (target, out) => assert((extracted / "usr/share/conf/application.conf").exists(), "File application.conf not exists") assert((extracted / "usr/share/conf/log4j.properties").exists(), "File log4j.properties not exists") assert((extracted / "var/empty").exists(), "Empty dir not exists") -// extracted.delete() + extracted.delete() out.log.success("Successfully tested control script") () } diff --git a/src/sbt-test/debian/jdeb-dir-mappings/test b/src/sbt-test/debian/jdeb-dir-mappings/test index 2adb1b9c5..eaac4b35b 100644 --- a/src/sbt-test/debian/jdeb-dir-mappings/test +++ b/src/sbt-test/debian/jdeb-dir-mappings/test @@ -1,4 +1,5 @@ # Run the debian packaging. +$ mkdir src/resources/empty > debian:package-bin $ exists target/debian-test_0.1.0_all.deb > check-dir-mappings