Skip to content

Commit

Permalink
Read deps from deps.js instead of parsing js files. Remove classpath/…
Browse files Browse the repository at this point in the history
…jar searching code.
  • Loading branch information
brentonashworth committed Jul 12, 2011
1 parent d53bd9b commit 03be3eb
Showing 1 changed file with 12 additions and 49 deletions.
61 changes: 12 additions & 49 deletions src/clj/cljs/closure.clj
Expand Up @@ -58,39 +58,6 @@
(defn random-string [length]
(apply str (take length (repeatedly random-char))))

;; from clojure.contrib.jar

(defn jar-file?
"Returns true if file is a normal file with a .jar or .JAR extension."
[^File file]
(and (.isFile file)
(or (.endsWith (.getName file) ".jar")
(.endsWith (.getName file) ".JAR"))))

(defn filenames-in-jar
"Returns a sequence of Strings naming the non-directory entries in
the JAR file."
[^JarFile jar-file]
(map #(.getName %)
(filter #(not (.isDirectory %))
(enumeration-seq (.entries jar-file)))))

;; from clojure.contrib.classpath

(defn classpath
"Returns a sequence of File objects of the elements on CLASSPATH."
[]
(map #(File. %)
(.split (System/getProperty "java.class.path")
(System/getProperty "path.separator"))))

(defn classpath-jarfiles
"Returns a sequence of JarFile objects for the JAR files on classpath."
[]
(map #(JarFile. %) (filter jar-file? (classpath))))

;; End of functions from clojure.contrib

;; Closure API
;; ===========

Expand Down Expand Up @@ -349,25 +316,21 @@ the JAR file."
{}
deps))

(defn all-goog-js
"Return the list of all Google Closure library JavaScript files."
[]
(for [g (filter #(.endsWith (.getName %) "goog.jar") (classpath-jarfiles))
file (filenames-in-jar g)
:when (.endsWith file ".js")]
file))

(defn dependency-index*
"Create an index of dependencies by namespace and file name."
[]
(letfn [(graph-node [res]
(-> (io/resource res)
io/reader
line-seq
parse-js-ns
(assoc :file res)))]
(let [all-nodes (map graph-node (all-goog-js))]
(build-index all-nodes))))
(letfn [(parse-list [s] (when (> (count s) 0)
(-> (.substring s 1 (dec (count s)))
(string/split #"'\s*,\s*'"))))]
(let [all-goog (->> (line-seq (io/reader (io/resource "goog/deps.js")))
(map #(re-matches #"^goog\.addDependency\('(.*)',\s*\[(.*)\],\s*\[(.*)\]\);.*" %))
(remove nil?)
(map #(drop 1 %))
(remove #(.startsWith (first %) "../../third_party"))
(map #(hash-map :file (str "goog/"(first %))
:provides (parse-list (second %))
:requires (parse-list (last %)))))]
(build-index all-goog))))

(def dependency-index (memoize dependency-index*))

Expand Down

0 comments on commit 03be3eb

Please sign in to comment.