Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Topolnik committed Mar 19, 2013
0 parents commit 034913c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/target
/lib
/classes
/checkouts
pom.xml
pom.xml.asc
*.jar
*.class
.lein-deps-sum
.lein-failures
.lein-plugins
.lein-repl-history
9 changes: 9 additions & 0 deletions project.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(defproject com.ingemark/lein-with-checkout "0.1.0-SNAPSHOT"
:description "Check out a revision from git and apply tasks on it"
:url "https://github.com/Inge-mark/lein-with-checkout"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:eval-in :leiningen
:lein-release {:deploy-via :clojars}

:dependencies [[org.clojure/clojure "1.5.1"]])
27 changes: 27 additions & 0 deletions src/leiningen/with_checkout.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(ns leiningen.with-checkout
(require [leiningen.core.main :as main]
(clojure.java [shell :as sh] [io :as io])
[clojure.string :as s]))

(set! *warn-on-reflection* true)

(defn abort [fmt & args] (main/abort (apply format fmt args)))

(defn sh! [& args]
(apply println "$" args)
(let [p (-> (ProcessBuilder. ^"[Ljava.lang.String;" (into-array args))
(.redirectErrorStream true)
.start)]
(io/copy (.getInputStream p) System/out)
(let [res (.waitFor p)]
(when-not (zero? res) (abort "Command failed with exit code %s: %s" res args))
res)))

(defn with-checkout [project tag & args]
(let [tag (if (= tag :latest) "`git tag | tail -1`" tag)
checkout-dir "target/lein-with-checkout"]
(sh! "mkdir" "-p" checkout-dir)
(try
(sh! "sh" "-c" (format "git archive %s | tar -xC %s" tag checkout-dir))
(sh! "sh" "-c" (format "cd %s ; lein %s" checkout-dir (s/join " " args)))
(finally (sh! "rm" "-rf" checkout-dir)))))

0 comments on commit 034913c

Please sign in to comment.