Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add -p option (fallback: auto-generate) for POM file, fix #1 and #3

  • Loading branch information...
commit 27b43c9873a01451ed75e7b1381f6575e1ff7c1c 1 parent e3f5820
@kumarshantanu authored
Showing with 41 additions and 5 deletions.
  1. +41 −5 src/leiningen/localrepo.clj
View
46 src/leiningen/localrepo.clj
@@ -72,28 +72,64 @@
[options] <filename> <artifact-id> <version>
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
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
+<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>%s</groupId>
+ <artifactId>%s</artifactId>
+ <version>%s</version>
+ <name>%s</name>
+ <description>Autogenerated by lein-localrepo</description>
+ <url>https://github.com/kumarshantanu/lein-localrepo</url>
+</project>")
+
+
+(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)
Please sign in to comment.
Something went wrong with that request. Please try again.