-
Notifications
You must be signed in to change notification settings - Fork 443
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
Attempt to resolve issue 161 - Add human readable methods to map directories #165
Changes from 2 commits
57ed3eb
9f9ec17
3314ab8
3a5e044
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
} | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I think the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What you mean by that @jsuereth ? That one can place files in side these directories and they get automatically added to the corresponding package, e.g.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was aware these work even if I did not test them yet. You mean that we should add some documentation for directory mapping for debian, linux ,rpm ... ? If yes I can do it as soon as possible. Correct me if I am wrong but adding directory mappings with such helper methods in Linux for example the user have to use the packageMapping method as explained in the linux.rst document ? packageMapping(directory("MyResourceDir"): _*) with.... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @muuki88 What I mean is all files in All I'm suggesting is we add docs for that "default lookup" as well as "here, you can also customize" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh also, this would work with |
||
|
||
.. 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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only works for static files, which are already present. I think an example which depends on a task is neccessary, like mappings in Universal <++= (packageBin in Compile, target) map { (_, target) =>
contentOf(target / "somefolder")
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. This explains why I was not able to use the mapping in Universal ++= directory(target / "scala-2.10" / "api") The above snippet does not compile due to bad type java.io.File. Using I'll add it to the doc ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before adding it to the documentation, I did test this and unfortunately, it does not compile. might be a type problem I do not understand yet. I have put the following in my build.sbt : mappings in Universal <++= (packageBin in Compile, target) map { (_, target) =>
directory(target / "streams")
} And loading the project, I have obtained the following error:
Do you have any idea about this problem ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sbt 0.13: mappings in Universal ++= {
val ensureRun = (packageBin in Compile).value
directory(target.value / "streams")
} What I think you're running into above is some shadowing flipping out the implicits. Try to use a different name for mappings in Universal <++= (packageBin in Compile, target) map { (_, t) =>
directory(t / "streams")
} Also +1 on an example which depends on a task. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah damn, sorry for the confusion. Didn't test it either, just quickly wrote it. |
||
|
||
Commands | ||
-------- | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. these are definitely the most frequently used.