Remove plugin task.
This commit is contained in:
parent
c2b40834e0
commit
464e631bef
2 changed files with 0 additions and 120 deletions
|
@ -1,84 +0,0 @@
|
|||
(ns leiningen.plugin
|
||||
"Manage user-level plugins."
|
||||
(:use [leiningen.core :only [read-project abort]]
|
||||
[leiningen.uberjar :only [write-components]]
|
||||
[leiningen.deps :only [deps]]
|
||||
[leiningen.jar :only [local-repo-path extract-jar
|
||||
get-default-uberjar-name]]
|
||||
[leiningen.util.file :only [tmp-dir delete-file-recursively]]
|
||||
[leiningen.util.paths :only [leiningen-home]]
|
||||
[clojure.java.io :only [file]])
|
||||
(:require [leiningen.install]
|
||||
[leiningen.help])
|
||||
(:import (java.util.zip ZipOutputStream)
|
||||
(java.io File FileOutputStream)))
|
||||
|
||||
(def plugins-path (file (leiningen-home) "plugins"))
|
||||
|
||||
(defn plugin-standalone-filename [group name version]
|
||||
(str (if group (str group "-") nil) name "-" version ".jar"))
|
||||
|
||||
(defn extract-name-and-group [project-name]
|
||||
((juxt name namespace) (symbol project-name)))
|
||||
|
||||
(defn uninstall
|
||||
"Delete the plugin jarfile
|
||||
Syntax: lein plugin uninstall [GROUP/]ARTIFACT-ID VERSION"
|
||||
[project-name version]
|
||||
(let [[name group] (extract-name-and-group project-name)
|
||||
jarfile (file plugins-path
|
||||
(plugin-standalone-filename group name version))]
|
||||
(if (.exists jarfile)
|
||||
(if (.delete jarfile)
|
||||
(println (format "Uninstalled %s %s." project-name version))
|
||||
(abort (format "Failed to delete \"%s\"." (.getAbsolutePath jarfile))))
|
||||
(abort (format "Plugin \"%s %s\" doesn't appear to be installed."
|
||||
project-name version)))))
|
||||
|
||||
(defn- uninstall-old [project-name]
|
||||
(doseq [plugin (.list plugins-path)
|
||||
:let [pat (re-pattern (format "^\\Q%s\\E-.*\\.jar$" project-name))]
|
||||
:when (re-find pat plugin)]
|
||||
(.delete (file plugins-path plugin))))
|
||||
|
||||
;; TODO: extract shared behavior between this and the install task
|
||||
(defn install
|
||||
"Download, package, and install plugin jarfile into ~/.lein/plugins
|
||||
Syntax: lein plugin install [GROUP/]ARTIFACT-ID VERSION
|
||||
You can use the same syntax here as when listing Leiningen
|
||||
dependencies."
|
||||
[project-name version]
|
||||
(uninstall-old project-name)
|
||||
(leiningen.install/install project-name version)
|
||||
(.mkdirs plugins-path)
|
||||
(let [[name group] (extract-name-and-group project-name)
|
||||
temp-project (file tmp-dir (str "lein-" (java.util.UUID/randomUUID)))
|
||||
jarfile (-> (local-repo-path (or group name) name version)
|
||||
(.replace "$HOME" (System/getProperty "user.home")))
|
||||
_ (extract-jar (file jarfile) temp-project)
|
||||
project (read-project (str (file temp-project "project.clj")))
|
||||
standalone-filename (plugin-standalone-filename group name version)]
|
||||
(deps (dissoc project :dev-dependencies :native-dependencies
|
||||
:eval-in-leiningen))
|
||||
(with-open [out (-> (file plugins-path standalone-filename)
|
||||
(FileOutputStream.)
|
||||
(ZipOutputStream.))]
|
||||
(let [deps (->> (.listFiles (file (:library-path project)))
|
||||
(filter #(.endsWith (.getName %) ".jar"))
|
||||
(cons (file jarfile)))]
|
||||
(write-components project deps out)))
|
||||
(delete-file-recursively temp-project)
|
||||
(println "Created" standalone-filename)))
|
||||
|
||||
(defn ^{:doc "Manage user-level plugins."
|
||||
:help-arglists '([subtask project-name version])
|
||||
:subtasks [#'install #'uninstall]}
|
||||
plugin
|
||||
([] (println (leiningen.help/help-for "plugin")))
|
||||
([_] (plugin))
|
||||
([_ _] (plugin))
|
||||
([subtask project-name version]
|
||||
(case subtask
|
||||
"install" (install project-name version)
|
||||
"uninstall" (uninstall project-name version)
|
||||
(plugin))))
|
|
@ -1,36 +0,0 @@
|
|||
(ns leiningen.test.plugin
|
||||
(:use [leiningen.plugin]
|
||||
[leiningen.util.file :only [unique-lein-tmp-dir
|
||||
delete-file-recursively]]
|
||||
[leiningen.core :only [read-project defproject]]
|
||||
[leiningen.test.helper :only [sample-project]]
|
||||
[clojure.test]
|
||||
[clojure.java.io :only [file]]))
|
||||
|
||||
(deftest test-plugin-standalone-filename
|
||||
(is (= (plugin-standalone-filename "tehgroup" "tehname" "0.0.1")
|
||||
"tehgroup-tehname-0.0.1.jar"))
|
||||
(is (= (plugin-standalone-filename nil "tehname" "0.0.1")
|
||||
"tehname-0.0.1.jar")))
|
||||
|
||||
(deftest test-extract-name-and-group
|
||||
(is (= (extract-name-and-group "tehgroup/tehname")
|
||||
["tehname" "tehgroup"]))
|
||||
(is (= (extract-name-and-group "tehname")
|
||||
["tehname" nil])))
|
||||
|
||||
(deftest test-help-mentions-subtasks
|
||||
(let [out (with-out-str (plugin "help"))]
|
||||
(is (re-find #"install" out))
|
||||
(is (re-find #"uninstall" out))))
|
||||
|
||||
(deftest test-install
|
||||
(with-out-str
|
||||
(leiningen.install/install sample-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))))
|
||||
|
||||
(doseq [[_ var] (ns-publics *ns*)] (alter-meta! var assoc :busted true))
|
Loading…
Reference in a new issue