Skip to content

Commit

Permalink
Merge pull request #165 from ivanfrain/issue-161
Browse files Browse the repository at this point in the history
Attempt to resolve issue 161 - Add human readable methods to map directories
  • Loading branch information
muuki88 committed Feb 18, 2014
2 parents 2ed3a93 + 3a5e044 commit 9790943
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/scala/com/typesafe/sbt/PackagerPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ object SbtNativePackager extends Plugin
with GenericPackageSettings {

val NativePackagerKeys = packager.Keys


val NativePackagerHelper = packager.MappingsHelper

def packagerSettings = linuxSettings ++
debianSettings ++
rpmSettings ++
Expand Down Expand Up @@ -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.

}
34 changes: 34 additions & 0 deletions src/main/scala/com/typesafe/sbt/packager/MappingsHelper.scala
Original file line number Diff line number Diff line change
@@ -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))
}
}

29 changes: 29 additions & 0 deletions src/sphinx/universal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
--------

Expand Down

0 comments on commit 9790943

Please sign in to comment.