diff --git a/README.md b/README.md index 3dc76cd..448a4cd 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/src/leiningen/libdir.clj b/src/leiningen/libdir.clj index 230df81..43482d9 100644 --- a/src/leiningen/libdir.clj +++ b/src/leiningen/libdir.clj @@ -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)))