Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial commit.

  • Loading branch information...
commit d06b76aba7ad5c739a9d23cfbbe73a5163e47e70 0 parents
Gunnar Völkel authored October 12, 2011
8  .classpath
... ...
@@ -0,0 +1,8 @@
  1
+<?xml version="1.0" encoding="UTF-8"?>
  2
+<classpath>
  3
+	<classpathentry kind="src" path="src"/>
  4
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
  5
+	<classpathentry kind="lib" path="classes"/>
  6
+	<classpathentry kind="lib" path="lib/dev/clojure-1.2.1.jar"/>
  7
+	<classpathentry kind="output" path="bin"/>
  8
+</classpath>
7  .gitignore
... ...
@@ -0,0 +1,7 @@
  1
+pom.xml
  2
+*jar
  3
+/lib/
  4
+/classes/
  5
+.lein-failures
  6
+.lein-deps-sum
  7
+bin/
23  .project
... ...
@@ -0,0 +1,23 @@
  1
+<?xml version="1.0" encoding="UTF-8"?>
  2
+<projectDescription>
  3
+	<name>lein-checkouts</name>
  4
+	<comment></comment>
  5
+	<projects>
  6
+	</projects>
  7
+	<buildSpec>
  8
+		<buildCommand>
  9
+			<name>ccw.builder</name>
  10
+			<arguments>
  11
+			</arguments>
  12
+		</buildCommand>
  13
+		<buildCommand>
  14
+			<name>org.eclipse.jdt.core.javabuilder</name>
  15
+			<arguments>
  16
+			</arguments>
  17
+		</buildCommand>
  18
+	</buildSpec>
  19
+	<natures>
  20
+		<nature>ccw.nature</nature>
  21
+		<nature>org.eclipse.jdt.core.javanature</nature>
  22
+	</natures>
  23
+</projectDescription>
5  project.clj
... ...
@@ -0,0 +1,5 @@
  1
+(defproject lein-checkouts "1.0.0-SNAPSHOT"
  2
+  	:description "Executes the given lein task on all checkout dependencies of the current project."
  3
+  	:dev-dependencies [[org.clojure/clojure "1.2.1"]]
  4
+	:eval-in-leiningen true
  5
+)
162  src/leiningen/checkouts.clj
... ...
@@ -0,0 +1,162 @@
  1
+(ns leiningen.checkouts
  2
+  (:require
  3
+    [leiningen.compile :as lc]
  4
+  )  
  5
+  (:use
  6
+    [leiningen.core :only (apply-task read-project task-not-found)]
  7
+    [clojure.string :only (join)]    
  8
+  )
  9
+  (:import
  10
+    java.io.File
  11
+  )
  12
+)
  13
+
  14
+
  15
+(defn error [msg-format & params]
  16
+  (println (apply format (str "ERROR: " msg-format) params))
  17
+  (System/exit 1)
  18
+)
  19
+
  20
+
  21
+(defn user-dir
  22
+  []
  23
+  (-> "user.dir" System/getProperty File.)
  24
+)
  25
+
  26
+
  27
+(defn list-checkouts
  28
+  [^File dir]
  29
+  (seq (.listFiles (File. dir "checkouts")))
  30
+)
  31
+
  32
+  
  33
+(defn get-project-data
  34
+  [^File dir]
  35
+  (read-project (.getAbsolutePath (File. dir "project.clj")))
  36
+)
  37
+
  38
+
  39
+(defrecord Project [name, dir, data, checkouts])
  40
+
  41
+(defn create-project
  42
+  [dir]
  43
+  (if-let [data (get-project-data dir)]
  44
+    (Project. (:name data), dir, data, nil)
  45
+    (error "There is no \"project.clj\" in directory \"%s\"!" (.getPath dir))
  46
+  )
  47
+)
  48
+
  49
+(defn build-checkouts-map 
  50
+  [project]
  51
+  (loop [project-list [(create-project (-> project :root File.))], result-map {}]
  52
+    ; as long as we have another project ...
  53
+    (if-let [p (first project-list)] 
  54
+      ; ... we check whether the project is already in our result map ...
  55
+      (if (contains? result-map (:name p))
  56
+        ; ... then we simply continue with the enxt project ...
  57
+        (recur (rest project-list), result-map)
  58
+	      ; ... else if the project has checkouts ...
  59
+	      (if-let [checkouts (seq (map create-project (list-checkouts (:dir p))))]
  60
+	        ; ... then assoc the checkouts to the current project and add them to the project list ...
  61
+	        (recur
  62
+	          (apply conj (rest project-list) checkouts)
  63
+	          (assoc result-map  (:name p) (assoc p :checkouts (set (map :name checkouts))))           
  64
+	        )
  65
+	        ; ... else just add p to the result map
  66
+          (recur
  67
+            (rest project-list)
  68
+            (assoc result-map  (:name p) p)
  69
+          )
  70
+	      )
  71
+      )
  72
+      ; ... finally we return the result map
  73
+      result-map
  74
+    )
  75
+  )
  76
+)
  77
+
  78
+(defn update-checkouts-map
  79
+  [checkouts-map, no-deps]
  80
+  (let [
  81
+        no-deps-names (map :name no-deps),
  82
+        checkouts-map (apply dissoc checkouts-map no-deps-names)
  83
+       ]
  84
+    (reduce
  85
+      (fn [cm, k] (update-in cm [k :checkouts] #(apply disj % no-deps-names))) 
  86
+      checkouts-map
  87
+      (keys checkouts-map) 
  88
+    )    
  89
+  )
  90
+)
  91
+
  92
+(defn create-checkout-build-seq
  93
+  [checkouts-map]
  94
+  (loop [checkouts-map checkouts-map, build-seq []]
  95
+    (if (empty? checkouts-map)
  96
+      build-seq
  97
+      ; if there are checkouts with no sub-checkouts ...
  98
+      (if-let [no-deps (seq (filter #(empty? (:checkouts %)) (vals checkouts-map)))]
  99
+        ; ... then add them to the build sequence and update the checkouts-map          
  100
+        (recur (update-checkouts-map checkouts-map, no-deps), (apply conj build-seq no-deps))          
  101
+        ; ... else signal error.
  102
+        (error "There seem to be cyclic dependent checkouts!")
  103
+      )
  104
+    )
  105
+  )
  106
+)
  107
+
  108
+(defn perform-lein-task
  109
+  [task-name, project]
  110
+  (apply-task task-name (:data project) [] task-not-found)
  111
+)
  112
+
  113
+(def clean-task "clean")
  114
+(def deps-task "deps")
  115
+(def compile-task "compile")
  116
+(def jar-task "jar")
  117
+(def uberjar-task "uberjar")
  118
+(def install-task "install")
  119
+
  120
+
  121
+(def task-set #{clean-task, deps-task, compile-task, jar-task, uberjar-task, install-task})
  122
+
  123
+(defn build-checkouts
  124
+  [build-seq, task]
  125
+  (let [
  126
+        build-last? (#{compile-task jar-task uberjar-task install-task} task),
  127
+        deps? (or (= task deps-task) build-last?)
  128
+       ]
  129
+	  (doseq [p (butlast build-seq)]
  130
+	    (println (format "[PROCESSING] project \"%s\"" (:name p)))
  131
+	    (perform-lein-task clean-task p)
  132
+      (when deps? (perform-lein-task deps-task p))
  133
+	    (when build-last? (perform-lein-task install-task p))
  134
+	  )
  135
+	  (let [p (last build-seq)]
  136
+	    (println (format "[PROCESSING] project \"%s\"" (:name p)))
  137
+	    (perform-lein-task clean-task p)
  138
+	    (when deps? (perform-lein-task deps-task p))
  139
+	    (when build-last? 
  140
+	        (perform-lein-task task p)	     
  141
+	    )
  142
+	    nil
  143
+	  )
  144
+  )
  145
+)
  146
+
  147
+
  148
+(defn checkouts
  149
+  "Executes a leiningen task on all checkout dependencies."
  150
+  [project, task]
  151
+  (if project
  152
+	  (if-let [task (task-set task)]
  153
+	    (-> project
  154
+	      build-checkouts-map 
  155
+	      create-checkout-build-seq
  156
+	      (build-checkouts task)
  157
+	    )
  158
+	    (error "No task specified! One of the following tasks has to be specified:\n* %s" (join "\n* " (sort (seq task-set))))
  159
+	  )
  160
+    (error "No project specified!")
  161
+  )
  162
+)

0 notes on commit d06b76a

Please sign in to comment.
Something went wrong with that request. Please try again.