From 9f9ec17f657c57bee767084a9ac9369117940202 Mon Sep 17 00:00:00 2001 From: Ivan Frain Date: Wed, 12 Feb 2014 21:34:34 +0100 Subject: [PATCH 1/3] Add human readable helper methods for directory mappings. --- .../com/typesafe/sbt/PackagerPlugin.scala | 7 +++-- .../sbt/packager/MappingsHelper.scala | 31 +++++++++++++++++++ src/sphinx/universal.rst | 16 ++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/main/scala/com/typesafe/sbt/packager/MappingsHelper.scala diff --git a/src/main/scala/com/typesafe/sbt/PackagerPlugin.scala b/src/main/scala/com/typesafe/sbt/PackagerPlugin.scala index bebe1e2a6..4645193f8 100644 --- a/src/main/scala/com/typesafe/sbt/PackagerPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/PackagerPlugin.scala @@ -17,7 +17,9 @@ object SbtNativePackager extends Plugin with GenericPackageSettings { val NativePackagerKeys = packager.Keys - + + val NativePackagerHelper = packager.MappingsHelper + def packagerSettings = linuxSettings ++ debianSettings ++ rpmSettings ++ @@ -47,7 +49,8 @@ object SbtNativePackager extends Plugin def java_server: Seq[Setting[_]] = genericMappingSettings ++ archetypes.JavaServerAppPackaging.settings } - + + // TODO - Add a few targets that detect the current OS and build a package for that OS. } \ No newline at end of file diff --git a/src/main/scala/com/typesafe/sbt/packager/MappingsHelper.scala b/src/main/scala/com/typesafe/sbt/packager/MappingsHelper.scala new file mode 100644 index 000000000..889b5a412 --- /dev/null +++ b/src/main/scala/com/typesafe/sbt/packager/MappingsHelper.scala @@ -0,0 +1,31 @@ +package com.typesafe.sbt +package packager + +import sbt._ + +/** A set of helper methods to simplify the writing of mappings */ +object MappingsHelper { + + /** return a Seq of mappings which effect is to add a whole directory in the generated package */ + def directory(sourceDir: File): Seq[(File, String)] = { + sourceDir.*** pair relativeTo(sourceDir.getParentFile) + } + + /** It lightens the build file if one wants to give a string instead of file. */ + def directory(sourceDir: String): Seq[(File, String)] = { + directory(file(sourceDir)) + } + + /** return a Seq of mappings which effect is to add the content of directory in the generated package, + * excluding the directory itself */ + def contentOf(sourceDir: File): Seq[(File, String)] = { + (sourceDir.*** --- sourceDir) pair relativeTo(sourceDir) + } + + /** It lightens the build file if one wants to give a string instead of file. */ + def contentOf(sourceDir: String): Seq[(File, String)] = { + contentOf(file(sourceDir)) + } + +} + diff --git a/src/sphinx/universal.rst b/src/sphinx/universal.rst index d49c3425f..6fd7ee76a 100644 --- a/src/sphinx/universal.rst +++ b/src/sphinx/universal.rst @@ -166,6 +166,14 @@ generates a function with a ``file -> Option[String]`` mapping, which tries to g string path from ``dir.getParentFile`` to the passed in file. ``pair`` uses the ``relativeTo`` function to generate a mapping ``File -> String``, which is _your file_ to _relative destination_. +It exists some helper methods to map a complete directory in more human readable way. + +.. code-block:: scala + + import NativePackagerHelper._ + + mappings in Universal ++= directory("SomeResourcesToInclude") + Mapping the content of a directory. .. code-block:: scala @@ -177,6 +185,14 @@ Mapping the content of a directory. The ``dir`` gets excluded and is used as root for ``relativeTo(dir)``. +It also exists some helper methods to simplify writing of such mapping. + +.. code-block:: scala + + import NativePackagerHelper._ + + mappings in Universal ++= contentOf("SomeResourcesToInclude") + Commands -------- From 3314ab823a9b8118dc62157afe011dc2242b8c85 Mon Sep 17 00:00:00 2001 From: Ivan Frain Date: Sat, 15 Feb 2014 13:44:09 +0100 Subject: [PATCH 2/3] Add documentation about using helper methods for directory mapping which depends on tasks. --- src/sphinx/universal.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/sphinx/universal.rst b/src/sphinx/universal.rst index 6fd7ee76a..04323d10c 100644 --- a/src/sphinx/universal.rst +++ b/src/sphinx/universal.rst @@ -172,8 +172,15 @@ It exists some helper methods to map a complete directory in more human readable import NativePackagerHelper._ + //For dynamic content, e.g. something in the target directory which depends on a Task + mappings in Universal <++= (packageBin in Compile, target) map { (_, target) => + directory(target / "scala-2.10" / "api") + } + + //For static content it can be added to mappings directly mappings in Universal ++= directory("SomeResourcesToInclude") + Mapping the content of a directory. .. code-block:: scala @@ -191,6 +198,12 @@ It also exists some helper methods to simplify writing of such mapping. import NativePackagerHelper._ + //For dynamic content, e.g. something in the target directory which depends on a Task + mappings in Universal <++= (packageBin in Compile, target) map { (_, target) => + contentOf(target / "scala-2.10" / "api") + } + + //For static content it can be added to mappings directly mappings in Universal ++= contentOf("SomeResourcesToInclude") Commands From 3a5e0440c4d265dc3dd19a1a936fc062db863f84 Mon Sep 17 00:00:00 2001 From: Ivan Frain Date: Mon, 17 Feb 2014 13:03:37 +0100 Subject: [PATCH 3/3] issue-161: Fix the case where a directory mapped does not have parent. It happens when one wants to map a directory from the root of the project. In that case we use the `basic` mapper on the directory itself. --- .../scala/com/typesafe/sbt/packager/MappingsHelper.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/scala/com/typesafe/sbt/packager/MappingsHelper.scala b/src/main/scala/com/typesafe/sbt/packager/MappingsHelper.scala index 889b5a412..fa0f053a7 100644 --- a/src/main/scala/com/typesafe/sbt/packager/MappingsHelper.scala +++ b/src/main/scala/com/typesafe/sbt/packager/MappingsHelper.scala @@ -8,7 +8,11 @@ object MappingsHelper { /** return a Seq of mappings which effect is to add a whole directory in the generated package */ def directory(sourceDir: File): Seq[(File, String)] = { - sourceDir.*** pair relativeTo(sourceDir.getParentFile) + val parentFile = sourceDir.getParentFile + if (parentFile != null) + sourceDir.*** pair relativeTo(sourceDir.getParentFile) + else + sourceDir.*** pair basic } /** It lightens the build file if one wants to give a string instead of file. */ @@ -26,6 +30,5 @@ object MappingsHelper { def contentOf(sourceDir: String): Seq[(File, String)] = { contentOf(file(sourceDir)) } - }