For the particular build I'm working on I need to make a call to an external command-line app using the lein-shell plugin. When invoking the shell command I'd like to pass in the artifact-id and version properties that I've defined in defproject to keep the resulting artifacts the app creates consistent.
In Maven I would use the ${artifactId} and ${version} properties to accomplish this. Is there analogous functionality in Leiningen?
I don't know of anything that gives you this functionality out of the box, but it's pretty straightforward to write some custom middleware to transform the project map before it gets handed off to the shell task. You could hard-wire the properties in question, or get fancy and walk the project map and do the template subtitution you describe in a more general fashion. See the plugins documentation for more information about writing middleware.
Related
Is there a not too dirty way to detect at runtime, whether the code was started with lein test? I just want to select a different redis database, so solutions like environ or using different resource files seem to be a bit overkill.
For example, leiningen automatically enables the test profile, but I haven't found a way to get a list of currently enabled profiles.
There is no simple way to do it. Neither lein.test nor clojure.test expose such information. Even if you find a way to hack into some private var of lein test or clojure.test and check it to determine if your code is run as part of lein test.
However, it would have a very big issue: your production code would need to require testing library code (e.g. clojure.test) or even worse your build tool code (lein test plugin code).
You might try to define such configuration var (dynamic or not) in your production code and set it in your tests using fixtures.
The best solution would be to configure your application dynamically based on the external variable like system property or environment variable (e.g. by using suggested environ). This way you can have as many different configuration sets as you need (e.g. prod vs unit test vs integration test vs performance tests and so on) and not just two (prod vs test).
It might seem like overkill, but component for instance is invented for exact usecases like this. Or dependency injection in general.
I know that feeling, it's just a private project, no need for difficult stuff etc. Thats why I put together my own template so that all I need to get started is run lein new ...
This is my solution to circumvent the "just want to select a different redis database" usecases.
Edit It is a template for a web framework: https://github.com/sveri/closp but a lot of these parts are not specific to web dev, especially the components part: https://github.com/sveri/closp/tree/master/resources/leiningen/new/closp/clj/components
There is also an integration test where I make use of test components specifically: https://github.com/sveri/closp/blob/master/resources/leiningen/new/closp/integtest/clj/web/setup.clj
I found a way with Cprop. Set a var in your "env/{test|prod|test}/config.clj" file:
(System/setProperty "lein.profile" "dev")
then you can read the value:
(require '[cprop.source :as source])
(str "from-system-props: >> " (:lein-profile (source/from-system-props)))
other option is to search for the key ":conf" in the system-props:
:conf "test-config.edn"
because the config file changes according to the profile.
I've been reading about cookiecutter as a way of instantiating project templates. The projects I'm interested in templating typically contain a bunch of different sub-project types such as C++ software, microcontroller-specific firmware, PCB schematic/layout, FPGA HDL, etc. Describing each sub-project type is easy with Cookiecutter, but is there a way to make a master cookiecutter that calls the appropriate sub-project cookiecutter at a given point? I haven't seen anything in the docs/tutorials that talk about this kind of recursive mode of operation.
I've used the internal Cookiecutter API in Python scripts so I can generate multiple components quickly. The method is described here: http://cookiecutter.readthedocs.org/en/latest/advanced_usage.html#calling-cookiecutter-functions-from-python
I also think this would be an interesting use of a post_gen_project.py hook. I'll try and get that working.
I'm trying to implement a Leiningen plugin configured using a dedicated project sub-map. The latter contains a "profiles" section containing plugin-specific profiles and the plugin's code is trying to merge one of them into the main plugin sub-map through the same merging logic Leiningen profiles use.
I first tried to implement this by injecting corresponding top-level Leiningen profiles into the project map and then by calling merge-profiles but Leiningen seems not to find such injected profiles (I tried by using middleware code as well with no outcome difference). By debugging leiningen.core.project I realised Leiningen looks up available profiles in project metadata, which doesn't contain the injected profiles.
Is there a way to implement such a logic easily and without fiddling with Leiningen's internals?
According to https://github.com/technomancy/leiningen/blob/master/doc/PLUGINS.md#evaluating-in-project-context merge-profiles should be passed the project and an array of the profile maps. I was passing in an array of profile names instead, which seems to work anyway indeed but only for profiles defined in the original project source file.
I have a maven project that converts text files of a specific format to another format.
For testing I have put in src/test/resources a large amount of test files.
I also have another project that uses the first one to do the conversion and then do some extra stuff on the output format. I also want to test this project against the same test dataset, but I dont want to have duplicate data sets and I want to be able to test the first project alone since it is also a standalone converter project.
Is there any common solution for doing that? I dont mind not having the test dataset inside the projects source tree as long as each project can access the data set independently of the other. I dont want to setup a database for that also. I am thinking something like a repository of test data simpler than an RDBMS. Is there any application for this kind of need that I can use with a specific maven plugin? Ease of setup and simplicity is my priority. Also I m thinking something like packaging the test data and putting it in a internal maven repo and then downloading it and unzip it in the junit code. Or better, is there a maven plugin that can do this for me?
Any ideas?
It is possible to share resources with Maven, for example with the help of the Assembly and Dependency plugins. Basically:
Create a module with a packaging of type pom to hold the shared resources
Use the assembly plugin to package the module as a zip
Declare a dependency on this zip in "consumer" modules
And use dependency:unpack-dependencies (plus some exclusion rules) to unpack the zip
This approach is detailed in How to share resources across projects in Maven. It requires a bit of setup (which is "provided") and is not too complicated.
Just place them in a tree in the src/main/resources directory of a separate module specially to share the test data. They will be added to the jar file and me nicely compressed and versioned in your nexus repository, file-share, ~/.m2/repository or whatever you use to store/distribute maven artifacts.
Then just add a dependency in the projects you need the data in the test scope and use resource loading to get them from the jars.
You do not need any special plugins or other infrastructure. This just works.
I'm just getting started with a project that combines GWT, Google App Engine and the Google Eclipse plugin. Where is the best place to store my tests? I normally keep my code organized Maven-style, with src/main/java, and tests in src/test/java. The default setup I get from the plugin dumped my source directly into src, which I'm not too fond of, but I'd prefer not to fight against the tools. What's the "standard" place to put unit tests in such a project?
Solution:
create src/main/java, move the existing code under there
create src/test/java, add your tests here
go to Project -> Properties -> Java Build Path, add the new locations as Source Folders.
I've faced a kind of problem woth GAE testing: Some tests require an appengine-testing.jar wich conflicts with the main appengine-api-xxx.jar of the poject. That way, I was able to run tests for GAE but it conflicted with a normal run/debug launch. To be able to run the app in my local machine, I had to remove the appengine-testing.jar and then, a lot of compilation errors appeared in my test/ clases.
If you want an advice, set your test clases in another project (where you can use the jars without conflict)
Otherwise, if you got make it work, please, tell me how did you do.
Thanks a lot.
Put it where it pains you least.
GWT on Google App Engine is pretty new at this point; you are
optimistic to expect there is a "standard" place, especially since
you've already found an inconsistency in what the tools do.
Since you've already accepted the source starting at "src/", why not
put the test source in "test/"? This is certainly standard in many
contexts.