diff --git a/src/leiningen/plugin.clj b/src/leiningen/plugin.clj index 4589a446..a0d264d6 100644 --- a/src/leiningen/plugin.clj +++ b/src/leiningen/plugin.clj @@ -7,7 +7,7 @@ [leiningen.jar :only (local-repo-path extract-jar get-default-uberjar-name)] - [leiningen.util.file :only (tmp-dir)] + [leiningen.util.file :only (tmp-dir delete-file-recursively)] [clojure.java.io :only (file)]) (:require [leiningen.install] [leiningen.help]) @@ -31,6 +31,7 @@ Syntax: lein plugin install [GROUP/]ARTIFACT-ID VERSION dependencies." [project-name version] (leiningen.install/install project-name version) + (.mkdirs plugins-path) (let [[name group] (extract-name-and-group project-name) temp-project (format "%s/lein-%s" tmp-dir (java.util.UUID/randomUUID)) jarfile (-> (local-repo-path name (or group name) version) @@ -46,6 +47,7 @@ Syntax: lein plugin install [GROUP/]ARTIFACT-ID VERSION (filter #(.endsWith (.getName %) ".jar")) (cons (file jarfile)))] (write-components deps out))) + (delete-file-recursively temp-project) (println "Created" standalone-filename))) (defn uninstall diff --git a/src/leiningen/util/file.clj b/src/leiningen/util/file.clj index 05229c46..638cfe76 100644 --- a/src/leiningen/util/file.clj +++ b/src/leiningen/util/file.clj @@ -3,6 +3,9 @@ (def tmp-dir (System/getProperty "java.io.tmpdir")) +(defn unique-lein-tmp-dir [] + (file tmp-dir (str "lein-" (java.util.UUID/randomUUID)))) + ;; grumble, grumble; why didn't this make it into clojure.java.io? (defn delete-file-recursively "Delete file f. If it's a directory, recursively delete all its contents. diff --git a/test/test_plugin.clj b/test/test_plugin.clj index f0c778dd..5cb63b45 100644 --- a/test/test_plugin.clj +++ b/test/test_plugin.clj @@ -1,5 +1,10 @@ (ns test-plugin - (:use [leiningen.plugin] :reload) + (:use [leiningen.plugin] + [leiningen.util.file :only (unique-lein-tmp-dir + delete-file-recursively)] + [leiningen.compile :only (platform-nullsink)] + [leiningen.core :only (read-project defproject)] + [clojure.java.io :only (file)]) (:use [clojure.test])) (deftest test-plugin-standalone-filename @@ -28,8 +33,14 @@ uninstall Delete the plugin jarfile Syntax: lein plugin uninstall [GROUP/]ARTIFACT-ID VERSION\n" (with-out-str (plugin "help"))))) +(defonce test-project (read-project "test_projects/sample/project.clj")) + +(deftest test-install + (with-out-str + (leiningen.install/install test-project) + (binding [plugins-path (unique-lein-tmp-dir) + leiningen.install/install (constantly nil)] + (install "nomnomnom" "0.5.0-SNAPSHOT") + (is (.exists (file plugins-path "nomnomnom-0.5.0-SNAPSHOT.jar"))) + (delete-file-recursively plugins-path)))) -;; TODO: figure out a clever way to actually test instaling -;; (deftest test-install -;; (install "lein-plugin" "0.1.0") -;; )