From eedd14370759c6f65afda25cf4911458fa9555ee Mon Sep 17 00:00:00 2001 From: Moritz Heidkamp Date: Wed, 30 Jan 2013 11:32:35 +0100 Subject: [PATCH 1/4] Add filter option This patch adds an option to filter the dependencies to be copied into the libdir. Possible values are a regular expression which is matched on the dependency jar file names or a predicate which is applied to the java.io.File object to check for whether it is to be copied. The config structure is changed so that all libdir specific options now reside below the :libdir key in the project defintion. :libdir-path is kept for backwards compatibility, though. --- src/leiningen/libdir.clj | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/leiningen/libdir.clj b/src/leiningen/libdir.clj index 230df81..af91dc7 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))) From fed98d01aa523306c1205c13493af77d3c6c6aab Mon Sep 17 00:00:00 2001 From: Moritz Heidkamp Date: Wed, 30 Jan 2013 11:41:34 +0100 Subject: [PATCH 2/4] Update README --- README.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3dc76cd..e843c39 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: From fe7d31a8be7c6fdad515c488553f0b28f1d5b6ea Mon Sep 17 00:00:00 2001 From: Moritz Heidkamp Date: Wed, 30 Jan 2013 11:43:22 +0100 Subject: [PATCH 3/4] Some formatting fixes --- README.md | 2 +- src/leiningen/libdir.clj | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e843c39..e7d614f 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ 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 +* `: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. diff --git a/src/leiningen/libdir.clj b/src/leiningen/libdir.clj index af91dc7..43482d9 100644 --- a/src/leiningen/libdir.clj +++ b/src/leiningen/libdir.clj @@ -33,8 +33,8 @@ 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\". + :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 From 907ea40bdbd129c1bf2bc9eb9d0a2f812b691762 Mon Sep 17 00:00:00 2001 From: Moritz Heidkamp Date: Wed, 30 Jan 2013 14:15:54 +0100 Subject: [PATCH 4/4] Slightly more realistic :filter example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e7d614f..448a4cd 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ project definition: (defproject myproject "0.1.0-SNAPSHOT" :plugins [[lein-libdir "0.1.0"]] :libdir {:path "lib" - :filter #"^frob"}) + :filter #"frob"}) ``` To copy the files, run the libdir task: