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..fa0f053a7 --- /dev/null +++ b/src/main/scala/com/typesafe/sbt/packager/MappingsHelper.scala @@ -0,0 +1,34 @@ +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)] = { + 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. */ + 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..04323d10c 100644 --- a/src/sphinx/universal.rst +++ b/src/sphinx/universal.rst @@ -166,6 +166,21 @@ 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._ + + //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 @@ -177,6 +192,20 @@ 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._ + + //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 --------