Skip to content

Commit 11978c7

Browse files
committed
Merge pull request #160 from sbt/wip/directory-mappings-docs
Adding documentation how to map directories
2 parents c73a96a + bd7a407 commit 11978c7

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/sphinx/universal.rst

+34
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,40 @@ Besides ``mappings``, the ``name``, ``sourceDirectory`` and ``target`` configura
142142

143143
**Note: The Universal plugin will make anything in a bin/ directory executable. This is to work around issues with JVM and file system manipulations.**
144144

145+
Mapping Examples
146+
----------------
147+
SBT provides and IO and .. Path: http://www.scala-sbt.org/0.13.1/docs/Detailed-Topics/Paths.html API, which
148+
lets you define custom mappings easily. The files will appear in the generate universal zip, but also in your
149+
debian/rpm/msi/dmg builds as described above in the conventions.
150+
151+
The ``packageBin in Compile`` dependency is only needed, if your files get generated
152+
during the ``packageBin`` command or before. For static files you can remove it.
153+
154+
Mapping a complete directory.
155+
156+
.. code-block:: scala
157+
158+
mappings in Universal <++= (packageBin in Compile, target ) map { (_, target) =>
159+
val dir = target / "scala-2.10" / "api"
160+
(dir.***) pair relativeTo(dir.getParentFile)
161+
}
162+
163+
This maps the ``api`` folder directly to the generate universal zip. ``dir.***`` is a short way for
164+
``dir ** "*"``, which means _select all files including dir_. ``relativeTo(dir.getParentFile)``
165+
generates a function with a ``file -> Option[String]`` mapping, which tries to generate a relative
166+
string path from ``dir.getParentFile`` to the passed in file. ``pair`` uses the ``relativeTo``
167+
function to generate a mapping ``File -> String``, which is _your file_ to _relative destination_.
168+
169+
Mapping the content of a directory.
170+
171+
.. code-block:: scala
172+
173+
mappings in Universal <++= (packageBin in Compile, target ) map { (_, target) =>
174+
val dir = target / "scala-2.10" / "api"
175+
(dir.*** --- dir) pair relativeTo(dir)
176+
}
177+
178+
The ``dir`` gets excluded and is used as root for ``relativeTo(dir)``.
145179

146180
Commands
147181
--------

0 commit comments

Comments
 (0)