(ns lein.check
  "How many Github Clojure projects use Leiningen? Biased towards
  recently-updated projects."
  (:require [net.cgrand.enlive-html :as html]
            [clj.io :as io]))

(def page-url "http://github.com/languages/Clojure/updated?page=%s")

(defn project-page [project]
  (format "http://github.com%s" project))

(defn fetch-url [url]
  (html/html-resource (java.net.URL. url)))

(def build-tools {:leiningen #"project\.clj"
                  :ant #"build\.xml"
                  :maven #"pom\.xml"})

(defn project-tools [url]
  (set (for [[tool file] build-tools
             :when (re-find file (io/slurp* (project-page url)))]
         tool)))

(defn check-page [page]
  (let [res (fetch-url (format page-url page))]
    (for [project (html/select res [:td.title (html/nth-child 2)])
          :let [url (:href (:attrs project))]]
      [url (project-tools url)])))

(def project-pages (pmap check-page (iterate inc 1)))

(defn -main [pages]
  (let [total (Integer. pages)
        project-pages (take total project-pages)]
    (doseq [[t _] build-tools]
      (println "Of the" (count project-pages) "most recent Clojure projects,"
               (count (filter (comp t second) project-pages))
               "use" (name t) "."))))

;; At the time of this writing:
;; Of 100 Clojure projects checked, 73 use Leiningen, 26 use maven,
;; and 7 use ant. 49 use only leiningen, 7 use only maven, and 2 use
;; only ant.

(#{:maven :leiningen}
 #{:leiningen}
 #{:leiningen}
 #{:leiningen}
 #{:leiningen}
 #{:ant :leiningen}
 #{}
 #{:leiningen}
 #{:leiningen}
 #{:leiningen}
 #{:leiningen}
 #{}
 #{:leiningen}
 #{:maven}
 #{}
 #{}
 #{:maven :leiningen}
 #{:leiningen}
 #{:ant}
 #{:ant :leiningen}
 #{:maven :leiningen}
 #{:maven :leiningen}
 #{:leiningen}
 #{:leiningen}
 #{:leiningen}
 #{:leiningen}
 #{:maven :leiningen}
 #{:leiningen}
 #{:leiningen}
 #{:leiningen}
 #{:leiningen}
 #{:leiningen}
 #{:maven :leiningen}
 #{:leiningen}
 #{:maven :leiningen}
 #{:leiningen}
 #{}
 #{:leiningen}
 #{:leiningen}
 #{}
 #{}
 #{:maven :leiningen}
 #{:maven :leiningen}
 #{:leiningen}
 #{}
 #{:ant}
 #{}
 #{}
 #{:leiningen}
 #{:maven}
 #{:leiningen}
 #{:leiningen}
 #{:leiningen}
 #{:leiningen}
 #{:maven :leiningen}
 #{:maven :leiningen}
 #{:leiningen}
 #{:maven}
 #{:ant :leiningen}
 #{:leiningen}
 #{:maven :leiningen}
 #{:leiningen}
 #{:leiningen}
 #{:leiningen}
 #{:leiningen}
 #{:ant :leiningen}
 #{:leiningen}
 #{:maven}
 #{:maven :leiningen}
 #{:leiningen}
 #{}
 #{:leiningen}
 #{:leiningen}
 #{}
 #{:leiningen}
 #{:maven :leiningen}
 #{:leiningen}
 #{:leiningen}
 #{:leiningen}
 #{:maven :leiningen}
 #{:leiningen}
 #{:maven :leiningen}
 #{:maven :leiningen}
 #{:leiningen}
 #{}
 #{}
 #{:leiningen}
 #{:ant :leiningen}
 #{:maven}
 #{}
 #{:maven :leiningen}
 #{:maven}
 #{:leiningen}
 #{:leiningen}
 #{:maven :leiningen}
 #{}
 #{:leiningen}
 #{:maven}
 #{}
 #{})

Generated by Phil Hagelberg using scpaste at Mon May 3 20:36:28 2010. PDT. (raw)