Skip to content
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

folder mappings #69

Closed
stanch opened this issue Nov 8, 2013 · 9 comments
Closed

folder mappings #69

stanch opened this issue Nov 8, 2013 · 9 comments

Comments

@stanch
Copy link

stanch commented Nov 8, 2013

Hi,

What would be the easiest way to add a folder with all files (or better—pattern-filtered) to this?

mappings in Universal += {
  file("my/local/conffile") -> "conf/my.conf"
}
@stanch
Copy link
Author

stanch commented Nov 8, 2013

Just a small note, I would love to see this on Windows / universal :)

@jsuereth
Copy link
Member

jsuereth commented Nov 8, 2013

You probably want to use sbt's fitlering/including mechanisms:

mappings in Universal += {
   // Don't assume your CWD is the project.  some sbt tools load you externally.  baseDirectory gives you
    // the root of the project
   val base = baseDirectory.value
   val confDir = base / "src" / "universal" / "conf"

   for {
      (file, relativePath) <-  (confDir.*** --- confDir) x relativeTo(confDir)
   } yield file -> s"/etc/$relativePath"
}

That last line is confusing, so let's deconstruct it a bit.

The x method is defined for "mappings" specifically. The left hand side is a list of files or a PathFinder. The right hand side is a function which takes files and creates their "mapped" location. Sbt provides a few out of the box like:

  • flatten
  • relativeTo(realDirectory)
  • rebase(multipleBaseDirectories*)

The second feature on the left is more confusing: (confDir.*** ---confDir) is a Path/FileFinder. You may have seen code like dir ** "*.scala" in sbt. The syntax is meant to mimic Ant's include/exclude globbing and filtering.

confDir.*** is shorthand for confDir ** "*" i.e. Glob all files under confDir, recursively.
--- is way to take two PathFinders and remove the right hand side from the left hand side. So in this instance, we're NOT including the conf directory itself in the mappings.

Here's some useful docs:

I'm going to mark this as closed. If you think we need some better "packaging specific" helpers, please open feature requests for each individually. I'm more than happy to help make this easier!

@jsuereth jsuereth closed this as completed Nov 8, 2013
@jsuereth
Copy link
Member

jsuereth commented Nov 8, 2013

Also wanted to mention. I'm pretty active around sbt questions on Stackoverflow. I'd love to have you ask (and have answered) native packager questions there. It's got much better Google SEO than I was ever able to accomplish with my documentation sites :). Thanks!

@stanch
Copy link
Author

stanch commented Nov 8, 2013

Thanks! I think this works for me, but of course some people may be shocked with APIs like that :) I will ask the next question on SO when I have one!

@jsuereth
Copy link
Member

jsuereth commented Nov 8, 2013

Great! I'm going ot add stackoverflow to the readme. I follow the sbt tag, but I also just created the sbt-native-packager tag, so either should catch my attention :)

Also, I agree the API may be mimicking the old Ant style too closely. I always forget how to use it when I don't have it. I also find the alternative (directly creating classes) ugly, so I've been using the more terse one. Any advice on what you think could help make it easier to grasp is welcome!

@stanch
Copy link
Author

stanch commented Nov 8, 2013

I think the really weird parts are --- and x... Right now no idea how to make this look better. That said, the actual API may just benefit from some extra examples: http://www.scala-sbt.org/0.13.0/api/#sbt.PathFinder. I don’t think it makes sense to provide any specific file handling routines to sbt-native-packager in particular.
By the way, your code should read ++=, not +=, and the extra empty line prevents it from working in .sbt configurations ;)

@jsuereth
Copy link
Member

jsuereth commented Nov 8, 2013

DOH! THanks for the reminder. TOo used to .scala build files.

@wsargent
Copy link
Contributor

wsargent commented Sep 1, 2017

FYI, the 0.13 version of (confDir.*** --- confDir) x relativeTo(confDir) is

(confDir.allPaths --- confDir) x Path.relativeTo(confDir)

@muuki88
Copy link
Contributor

muuki88 commented Sep 2, 2017

Thanks for sharing 😍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants