Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tree: 3ebd2d1d65
Fetching contributors…

Cannot retrieve contributors at this time

90 lines (80 sloc) 2.985 kB
; Copyright © 2011 Sattvik Software & Technology Resources, Ltd. Co.
; All rights reserved.
; This program and the accompanying materials are made available under the
; terms of the Eclipse Public License v1.0 which accompanies this distribution,
; and is available at <>.
; By using this software in any fashion, you are agreeing to be bound by the
; terms of this license. You must not remove this notice, or any other, from
; this software.
(use '
(use 'clojure.stacktrace)
(import '[ File PushbackReader]
'[java.util.regex Matcher Pattern])
(set! *warn-on-reflection*
(Boolean/valueOf (System/getProperty "clojure.warn.reflection" "false")))
(defn find-clojure-files
"Finds all Clojure source files in a given directory."
(let [file (as-file path)]
(.isDirectory file) (mapcat find-clojure-files (.listFiles file))
(and (.isFile file)
(.. file getName (endsWith ".clj"))) [file]
:else nil)))
(defn file->ns
"Looks for the namespace in a Clojure source file."
(binding [*in* (PushbackReader. (reader file))]
(let [next-form (fn [] (read *in* false ::eof))]
(loop [form (next-form)]
(= ::eof form)
(and (list? form)
(= 'ns (first form)))
(second form)
(recur (next-form)))))))
(def compiled-ns (atom #{}))
(defn compile-ns
"Compiles a namespace."
([ns failed-ns]
(when-not (@compiled-ns ns)
(println (format "Compiling %s…" ns))
(compile ns)
(swap! compiled-ns conj ns)
(catch Exception e
(let [msg (.getMessage e)
cnfe-pattern #".*java\.lang\.ClassNotFoundException: ([a-zA-z0-9-_.]+)(, compiling:| )\(.*:\d+\)$"]
(if-let [matches (re-matches cnfe-pattern msg)]
(let [not-found-ns (symbol (matches 1))]
(println (format "Dependency failure detected, will try to compile %s." not-found-ns))
(if (failed-ns not-found-ns)
(throw e)
(if (compile-ns not-found-ns (conj failed-ns ns))
(println "Failure resolved.")
(compile-ns ns failed-ns))
(throw e))))
(throw e)))))))
(compile-ns ns #{})))
(defn compile-dir
"Compiles all Clojure files in the given directory."
(binding [*compile-path* (System/getProperty "clojure.compile.path")]
(->> (find-clojure-files dir)
(map file->ns)
(remove nil?)
(map compile-ns)
(defn args->dirs
"Splits any path arguments into directories"
(let [split-path (fn [^String arg] (seq (.split arg (Pattern/quote File/pathSeparator))))]
(flatten (map split-path args))))
(dorun (map compile-dir (args->dirs *command-line-args*)))
Jump to Line
Something went wrong with that request. Please try again.