Separate :snapshots and :releases repository URLs in project.clj.

Plane commit; woo!
This commit is contained in:
Phil Hagelberg 2011-01-15 08:52:50 -05:00
parent 48109fa593
commit 0cf1ddf024
3 changed files with 29 additions and 21 deletions

View file

@ -90,9 +90,10 @@
:username "milgrim" :username "milgrim"
:password "locative.1"}} :password "locative.1"}}
;; Remote repository to which to deploy. (http:// or file://) ;; Remote repository to which to deploy. (http:// or file://)
:deploy-to ["http://blueant.com/archiva/repository/snapshots" :deploy-to {:snapshots "http://blueant.com/archiva/repository/snapshots"
:releases "http://blueant.com/archiva/repository/internal"
;; Also supports :private-key and :passphrase. ;; Also supports :private-key and :passphrase.
:username "milgrim" :password "locative.1"] :username "milgrim" :password "locative.1"}
;; If you'd rather use a different directory structure, you can set these. ;; If you'd rather use a different directory structure, you can set these.
:source-path "src/main/clojure" :source-path "src/main/clojure"
:library-path "target/dependency" :library-path "target/dependency"

View file

@ -3,7 +3,7 @@
(:require [lancet]) (:require [lancet])
(:use [leiningen.core :only [abort]] (:use [leiningen.core :only [abort]]
[leiningen.jar :only [jar]] [leiningen.jar :only [jar]]
[leiningen.pom :only [pom]] [leiningen.pom :only [pom snapshot?]]
[leiningen.util.maven :only [make-model make-artifact]] [leiningen.util.maven :only [make-model make-artifact]]
[leiningen.deps :only [make-repository]] [leiningen.deps :only [make-repository]]
[clojure.java.io :only [file]]) [clojure.java.io :only [file]])
@ -31,26 +31,31 @@
(when private-key (.setPrivateKey auth private-key)) (when private-key (.setPrivateKey auth private-key))
auth)) auth))
(defn make-target-repo [repo-url auth-options] (defn make-target-repo [project options]
(let [repo (make-repository ["remote repository" repo-url])] (let [deploy-opts (merge (:deploy-to project) options)
(when-let [auth (make-auth repo-url auth-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)) (.addAuthentication repo auth))
repo)) repo))
(defn deploy (defn deploy
"Build and deploy jar to remote repository. Takes target repository "Build and deploy jar to remote repository. Set :deploy-to in project.clj:
URL as an argument or set :deploy-to in project.clj to a URL or auth vector:
[\"http://secret.com/archiva/repository/snapshots/\" {:snapshots \"http://secret.com/archiva/repository/snapshots\"
:username \"durin\" :password \"mellon\"]. :releases \"http://secret.com/archiva/repository/internal\"
:username \"durin\" :password \"mellon\"}
Also supported are :private-key and :passphrase. You can set SNAPSHOT versions will be deployed to :snapshots repository, releases go to
authentication options in ~/.lein/init.clj as well to avoid checking :releases. Also supported are :private-key and :passphrase. You can
sensitive information into source control: set authentication options keyed by repository URL in ~/.lein/init.clj
to avoid checking sensitive information into source control:
(def leiningen-auth {\"http://secr.et/repo\" {:password \"reindeerflotilla\"} (def leiningen-auth {\"http://secr.et/repo\" {:password \"reindeerflotilla\"}
\"file:///var/repo {:passphrase \"vorpalbunny\"}})" \"file:///var/repo {:passphrase \"vorpalbunny\"}})"
([project repo-url & auth] ([project & opts]
(doto (DeployTask.) (doto (DeployTask.)
(.setProject lancet/ant-project) (.setProject lancet/ant-project)
(.getSupportedProtocols) ;; see note re: exceptions in deps.clj (.getSupportedProtocols) ;; see note re: exceptions in deps.clj
@ -58,11 +63,10 @@ sensitive information into source control:
(.addPom (doto (Pom.) (.addPom (doto (Pom.)
(.setMavenProject (make-maven-project project)) (.setMavenProject (make-maven-project project))
(.setFile (file (pom project))))) (.setFile (file (pom project)))))
(.addRemoteRepository (make-target-repo repo-url (keywordize-opts auth))) (.addRemoteRepository (make-target-repo project (keywordize-opts opts)))
(.execute))) (.execute)))
([project] ([project]
(when-not (:deploy-to project) (if-let [target (:deploy-to project)]
(abort "Can't deploy without :deploy-to set in project.clj.")) (deploy target)
(if (string? (:deploy-to project)) (do (println "Either set :deploy-to in project.clj or"
(deploy project (:deploy-to project)) "provide deploy target options.") 1))))
(apply project (:deploy-to project)))))

View file

@ -13,8 +13,11 @@
It should not be considered canonical data. For more information see It should not be considered canonical data. For more information see
https://github.com/technomancy/leiningen -->\n") https://github.com/technomancy/leiningen -->\n")
(defn snapshot? [project]
(re-find #"SNAPSHOT" (:version project)))
(defn check-for-snapshot-deps [project] (defn check-for-snapshot-deps [project]
(when (and (not (re-find #"SNAPSHOT" (:version project))) (when (and (not (snapshot? project))
(not (System/getenv "LEIN_SNAPSHOTS_IN_RELEASE")) (not (System/getenv "LEIN_SNAPSHOTS_IN_RELEASE"))
(some #(re-find #"SNAPSHOT" (second %)) (:dependencies project))) (some #(re-find #"SNAPSHOT" (second %)) (:dependencies project)))
(throw (Exception. (str "Release versions may not depend upon snapshots." (throw (Exception. (str "Release versions may not depend upon snapshots."