Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,23 @@ This plugin provides a Leiningen task to emulate the behaviour of Leiningen 1.x.
Put `[lein-libdir "0.1.0"]` into the `:plugins` vector of your
`:user` profile`, or reference it from the :plugins property of your project.

If you require the jar files to be copied somewhere other than "lib",
then set the :libdir-path property in your project.
The following options can be specified under the `:libdir` key in the
project definition:

* `:path` - A string containing the relative path of the target lib
dir. If omitted, the default is "lib".
* `:filter` - A regular expression which must match on file names of jar
file names to be copied or a function which should be a predicate
accepting java.io.File objects and returning whether it should be
copied or not. The default is to copy all files.

## Example

```clojure
(defproject myproject "0.1.0-SNAPSHOT"
:plugins [[lein-libdir "0.1.0"]]
:libdir-path "lib")
:libdir {:path "lib"
:filter #"frob"})
```

To copy the files, run the libdir task:
Expand Down
33 changes: 25 additions & 8 deletions src/leiningen/libdir.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,39 @@
(io/copy file target-file))))

(defn copy-deps
[project target-dir sourceify?]
[project target-dir filter-pred sourceify?]
(let [project (project/unmerge-profiles project [:default])
deps (->> (classpath/resolve-dependencies :dependencies project)
(filter #(and (.endsWith (.getName %) ".jar") (.exists %))))]
(filter #(and (.endsWith (.getName %) ".jar") (.exists %)))
(filter filter-pred))]
(.mkdirs target-dir)
(copy-files target-dir deps)
(main/info "Copied" (count deps) "file(s) to:" (.getAbsolutePath target-dir))))

(defn file-matches [re file]
(re-find re (str file)))

(defn libdir
"Copy jar dependencies into the project lib directory.

Set :libdir-path in the project to a string containing the relative path
of the target lib dir. If omitted, the default is \"lib\"."
The following options can be specified under the :libdir key in the
project definition:

:path - A string containing the relative path of the target lib
dir. If omitted, the default is \"lib\".
:filter - A regular expression which must match on file names of jar
file names to be copied or a function which should be a predicate
accepting java.io.File objects and returning whether it should be
copied or not. The default is to copy all files."
[project & args]
(let [target-dir (if-let [path (:libdir-path project)]
(java.io.File. path)
(java.io.File. (:root project) "lib"))]
(copy-deps project target-dir nil)))
(let [options (:libdir project)
target-dir (if-let [path (or (:path options) (:libdir-path project))]
(java.io.File. path)
(java.io.File. (:root project) "lib"))
filter-pred (let [filter (:filter options)]
(cond (fn? filter) filter
(instance? java.util.regex.Pattern filter)
(partial file-matches filter)
(not filter) identity))]
(copy-deps project target-dir filter-pred nil)))