-
Notifications
You must be signed in to change notification settings - Fork 444
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
Conversation
Hi @ivanfrain, Thank you for your contribution! We really value the time you've taken to put this together. Before we proceed with reviewing this pull request, please sign the Typesafe Contributors License Agreement: |
import sbt._ | ||
|
||
/** A set of helper methods to simplify the writing of mappings */ | ||
object MappingsHelper { |
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.
Look cool to me. @muuki88 or @aparkinson ? |
|
||
import NativePackagerHelper._ | ||
|
||
mappings in Universal ++= contentOf("SomeResourcesToInclude") |
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. This explains why I was not able to use the target
from sbt Keys like this:
mapping in Universal ++= directory(target / "scala-2.10" / "api")
The above snippet does not compile due to bad type java.io.File. Using target
... requires a kind of task scope.
I'll add it to the doc !
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.
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:
> reload
[info] Loading project definition from /Users/ivan/****
/Users/ivan/****/build.sbt:49: error: value / is not a member of java.io.File
directory(target / "streams")
^
[error] Type error in expression
Do you have any idea about this problem ?
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.
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 target
:
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 comment
The 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.
Thanks very much! This looks pretty good. Small tweaks on the docs and we can merge this |
You are welcome and thank you for the review. |
Would you like to add the additional docs in this pr? If not, we merge this and add the in a follow up pr (even though it would be nice every to have everything in one place and you get the credits ;) ) |
…ich depends on tasks.
Hi @ivanfrain, Thank you for your contribution! We really value the time you've taken to put this together. Before we proceed with reviewing this pull request, please sign the Typesafe Contributors License Agreement: |
@muuki88 I added the documentation about the mapping which depends on task. Tell me if you are ok with that. I tested the different mappings mentionned in the Universal documentation and I was not able to make them work because of the "target" problem I mentionned above. I think opening an issue on that to understand what's happening could be good. On that point, I also tested wwhat you have proposed @jsuereth, due to implicit problem ...Thus I have tried with s/target/t and it did not work either. |
Hmm, I'll have to look into this target problem Was thing in sbt 0.12.4? |
It was with sbt 0.13.1 on MacOSX. Let me know if you need other information to reproduce the problem. |
Awesome. @jsuereth , I think we are fine with merging and raising another issue with "target" problem referencing this one? |
sounds good. the |
Very Good. I am ok too, I mean I have finished for this pull request. I would like two propose two new features/enhancements (sorry if this is not the right place for discussing this). I'll be able to implement them as well. Is it ok to open issues for :
|
You should open tickets for 1 and 2. ALso, for 2 - You probably want "../conf", although I don't recommend adding user-writable directories to your executable classpath [security].... (even though that's how typesafe config works cough @havocp cough). You should open a ticket in either case. I hoped |
I don't understand enough background here to know what the security issue is or what Typesafe config change you are proposing. You can parse any file you want with the config lib. Presumably you could also put your config files in a non writable directory - if you don't want it to be writable then don't make it writable? Is the point that you want a writable config but don't allow adding jars to classpath? It's not secure to have a writable default config either though; both play and Akka for example let you set all kinds of sensitive stuff in there. So I don't understand the scenario where you'd want the config writable but not the classpath (for the default classpath-based config anyway - if you wanted a user writable config you'd want it to be a special sandboxed one and then you could read it from where you want instead of from classpath). Classpath config is just the default global one that affects all libs in the jar. |
I like 1. A few days ago I would have liked 2 as well, however I gave it a thought. Adding a conf folder to the classpath is an easy way, as most of the libraries scan the classpath for a specific file. However, the good libraries also provide to specify a system property where to find their configuration files. E.g. Typesafe Config and Log4j. I put together an example here to demonstrate how you can easily and safely use config files from your application. @jsuereth I will give this project a little love. Maybe we can transfer it to the sbt organization at some point. |
@muuki88 Thanks I'll have a look at your project. |
It happens when one wants to map a directory from the root of the project. In that case we use the `basic` mapper on the directory itself.
Hi @ivanfrain, Thank you for your contribution! We really value the time you've taken to put this together. Before we proceed with reviewing this pull request, please sign the Typesafe Contributors License Agreement: |
I finally add another update since the mapping with a directory at the root of a project was not working. In such case getParentFile returns null and thus prevent from running the relativeTo method correctly. From my point of view, ready for merging. |
By the way I have signed the Typesafe contributor CLA 5 minutes ago. |
Attempt to resolve issue 161 - Add human readable methods to map directories
I added two helper methods to simplify directory mappings.
One can add a directory by writing
One can add a directory content by writing
(Hope this one is better than my first pull request)