diff --git a/src/leiningen/localrepo.clj b/src/leiningen/localrepo.clj index a40ffb0..9088898 100644 --- a/src/leiningen/localrepo.clj +++ b/src/leiningen/localrepo.clj @@ -72,28 +72,64 @@ [options] Options: -r | --repo repo-path + -p | --pom POM-file (minimal POM is generated if no POM file specified) Example: foo-1.0.jar bar/foo 1.0") +(def default-pom-format + " + + 4.0.0 + %s + %s + %s + %s + Autogenerated by lein-localrepo + https://github.com/kumarshantanu/lein-localrepo +") + + +(defn default-pom-file + "Generate default temporary POM file returning the file name" + [group-id artifact-id version] + (let [pom-file (File/createTempFile "pom" ".xml") + pom-name (.getAbsolutePath pom-file)] + (.deleteOnExit pom-file) + (spit pom-name (format default-pom-format + group-id artifact-id version artifact-id)) + pom-name)) + + (defn c-install* - [repo-path filename artifact-id version] + [repo-path pom-filename filename artifact-id version] (aether/install :local-repo (assert-dir repo-path) :coordinates [(symbol artifact-id) version] - :jar-file (jio/file filename)) + :jar-file (jio/file filename) + :pom-file pom-filename) (main/exit 0)) (defn c-install [& args] (let [[options args banner] (cli/cli args - ["-r" "--repo" "Local repo path" :default local-repo-path]) + ["-r" "--repo" "Local repo path" :default local-repo-path] + ["-p" "--pom" "Artifact POM file"]) help-abort (fn [] (println doc-install) (main/abort))] (cond (not= 3 (count args)) (help-abort) - :otherwise (apply c-install* (:repo options) args)))) + :otherwise (let [[filename artifact-id version] args + [pom-group-id pom-artifact-id] (let [i (.indexOf artifact-id "/")] + (if (>= i 0) + [(.substring artifact-id 0 i) + (.substring artifact-id (inc i))] + [artifact-id artifact-id])) + pom-filename (if (:pom options) + (:pom options) + (default-pom-file pom-group-id pom-artifact-id version))] + (c-install* (:repo options) pom-filename filename artifact-id version))))) (defn read-artifact-description @@ -331,7 +367,7 @@ $ lein localrepo help install (let [argc (count args)] (case command "coords" (apply-cmd #(= argc 1) command c-coords args) - "install" (apply-cmd #(#{3 5} argc) command c-install args) + "install" (apply-cmd #(#{3 5 7} argc) command c-install args) "list" (apply-cmd #(#{0 1 2 3} argc) command c-list args) "remove" (apply-cmd #(>= argc 0) command c-remove args) "help" (apply-cmd #(or (= argc 0)