Fix deploy task to use :repositories for configuration.

No more separate :deploy-to configuration.
This commit is contained in:
Phil Hagelberg 2011-01-24 19:38:28 -08:00
parent 0ecfbe150d
commit 781ec86f18
4 changed files with 50 additions and 62 deletions

View file

@ -415,6 +415,8 @@ test! && lein install</tt> and make the hudson user's
<tt>~/.m2/repository</tt> directory available over password-protected
HTTP using something like <a href="http://nginx.net">nginx</a>.
TODO: mention deploy task
### Server-side Projects
There are many ways to get your project deployed as a server-side

View file

@ -89,14 +89,11 @@
;; Set this in order to only use the :repositories you list below.
:omit-default-repositories true
:repositories {"java.net" "http://download.java.net/maven/2"
"bigend" {:url "http://blueant.com/archiva/repository/internal"
:username "milgrim"
:password "locative.1"}}
;; Remote repository to which to deploy. (http:// or file://)
:deploy-to {:snapshots "http://blueant.com/archiva/repository/snapshots"
:releases "http://blueant.com/archiva/repository/internal"
;; Also supports :private-key and :passphrase.
:username "milgrim" :password "locative.1"}
"snapshots" {:url "http://blueant.com/archiva/snapshots"
;; Also supports :private-key and :passphrase.
:username "milgrim" :password "locative.1"}
"releases" {:url "http://blueant.com/archiva/internal"
:username "milgrim" :password "locative.1"}}
;; If you'd rather use a different directory structure, you can set these.
:source-path "src/main/clojure"
:library-path "target/dependency"

View file

@ -5,7 +5,7 @@
[leiningen.jar :only [jar]]
[leiningen.pom :only [pom snapshot?]]
[leiningen.util.maven :only [make-model make-artifact]]
[leiningen.deps :only [make-repository make-auth]]
[leiningen.deps :only [make-repositories]]
[clojure.java.io :only [file]])
(:import [org.apache.maven.artifact.ant DeployTask Pom Authentication]
[org.apache.maven.project MavenProject]))
@ -14,36 +14,27 @@
(doto (MavenProject. (make-model project))
(.setArtifact (make-artifact (make-model project)))))
;; for supporting command-line options
(defn- keywordize-opts [options]
(let [options (apply hash-map options)]
(zipmap (map keyword (keys options)) (vals options))))
(defn make-target-repo [project options]
(let [deploy-opts (merge (:deploy-to project) options)
repo-url (if (snapshot? project)
(:snapshots deploy-opts)
(:releases deploy-opts))
repo (make-repository ["remote repository" repo-url])]
(when-let [auth (make-auth repo-url options)]
(.addAuthentication repo auth))
repo))
(defn deploy
"Build and deploy jar to remote repository. Set :deploy-to in project.clj:
"Build and deploy jar to remote repository.
{:snapshots \"http://secret.com/archiva/repository/snapshots\"
:releases \"http://secret.com/archiva/repository/internal\"
:username \"durin\" :password \"mellon\"}
The target repository will be looked up in :repositories: snapshot
versions will go to the repo named \"snapshots\" while stable versions
will go to \"releases\". You can also deploy to another repository
in :repositories by providing its name as an argument.
SNAPSHOT versions will be deployed to :snapshots repository, releases go to
:releases. Also supported are :private-key and :passphrase. You can
set authentication options keyed by repository URL in ~/.lein/init.clj
to avoid checking sensitive information into source control:
:repositories {\"java.net\" \"http://download.java.net/maven/2\"
\"snapshots\" {:url \"https://blueant.com/archiva/snapshots\"
:username \"milgrim\" :password \"locative\"}
\"releases\" {:url \"https://blueant.com/archiva/internal\"
:private-key \"etc/id_dsa\"}}
(def leiningen-auth {\"http://secr.et/repo\" {:password \"reindeerflotilla\"}
\"file:///var/repo {:passphrase \"vorpalbunny\"}})"
([project & opts]
You can set authentication options keyed by repository name in
~/.lein/init.clj to avoid checking sensitive information into source
control:
(def leiningen-auth {\"releases\" {:passphrase \"vorpalbunny\"}})
"
([project repository-name]
(doto (DeployTask.)
(.setProject lancet/ant-project)
(.getSupportedProtocols) ;; see note re: exceptions in deps.clj
@ -51,10 +42,10 @@ to avoid checking sensitive information into source control:
(.addPom (doto (Pom.)
(.setMavenProject (make-maven-project project))
(.setFile (file (pom project)))))
(.addRemoteRepository (make-target-repo project (keywordize-opts opts)))
(.addRemoteRepository ((keyword repository-name)
(make-repositories project)))
(.execute)))
([project]
(if-let [target (:deploy-to project)]
(apply deploy project target)
(do (println "Either set :deploy-to in project.clj or"
"provide deploy target options.") 1))))
(deploy project (if (snapshot? project)
"snapshots"
"releases"))))

View file

@ -11,29 +11,31 @@
(org.apache.maven.settings Server)
(org.apache.tools.ant.util FlatFileNameMapper)))
(defn make-auth [[id settings]]
(let [user-options (when-let [user-opts (resolve 'user/leiningen-auth)]
(get @user-opts id))
{:keys [username password passphrase
private-key] :as settings} (merge user-options settings)
auth (Authentication.)]
(when (seq settings)
(when username (.setUserName auth username))
(when password (.setPassword auth password))
(when passphrase (.setPassphrase auth passphrase))
(when private-key (.setPrivateKey auth private-key))
auth)))
(defn make-repository [[id settings]]
(let [repo (RemoteRepository.)]
(.setId repo id)
(if (string? settings)
(.setUrl repo settings)
(let [{:keys [url username password]} settings]
(.setUrl repo url)
(.addAuthentication repo (Authentication. (doto (Server.)
(.setUsername username)
(.setPassword password))))))
(.setUrl repo (:url settings)))
(when-let [auth (make-auth id settings)]
(.addAuthentication repo auth))
repo))
(defn make-auth [url options]
(let [auth (Authentication.)
user-options (when-let [user-opts (resolve 'user/leiningen-auth)]
(get @user-opts url))
{:keys [username password passphrase
private-key]} (merge user-options options)]
(when username (.setUserName auth username))
(when password (.setPassword auth password))
(when passphrase (.setPassphrase auth passphrase))
(when private-key (.setPrivateKey auth private-key))
auth))
(defn make-repositories [project]
(map make-repository (repositories-for project)))
;; Add symlinking to Lancet's toolbox.
(lancet/define-ant-task symlink symlink)
@ -72,12 +74,8 @@
(.setBasedir lancet/ant-project (:root project))
(.setFilesetId deps-task "dependency.fileset")
(.setPathId deps-task (:name project))
(doseq [[id settings] (repositories-for project)]
(let [r (make-repository [id settings])
repo-url (if (string? settings) settings (:url settings))]
(when-let [auth (make-auth repo-url (if (map? settings) settings {}))]
(.addAuthentication r auth))
(.addConfiguredRemoteRepository deps-task r)))
(doseq [repo (make-repositories project)]
(.addConfiguredRemoteRepository deps-task repo))
(doseq [dep (project deps-set)]
(.addDependency deps-task (make-dependency dep)))
deps-task))