Commits

Meikel Brandmeyer  committed a6f7c74

Simplify codox integration

  • Participants
  • Parent commits 4c3495c

Comments (0)

Files changed (3)

File clojuresque-base-runtime/src/main/resources/clojuresque/clojure/java/classpath.clj

-;;; classpath.clj: utilities for working with the Java class path
-
-;; by Stuart Sierra, http://stuartsierra.com/
-;; April 19, 2009
-
-;; Copyright (c) Rich Hickey, Stuart Sierra, and contributors.
-;; All rights reserved.  The use
-;; and distribution terms for this software are covered by the Eclipse
-;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
-;; which can be found in the file epl-v10.html at the root of this
-;; distribution.  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.
-
-
-(ns
-  ^{:author "Stuart Sierra"
-     :doc "Utilities for dealing with the JVM's classpath"}
-  clojuresque.clojure.java.classpath
-  (:require [clojure.java.io :as io])
-  (:import (java.io File)
-           (java.util.jar JarFile JarEntry)
-           (java.net URL URLClassLoader)))
-
-(defn jar-file?
-  "Returns true if file is a normal file with a .jar or .JAR extension."
-  [f]
-  (let [file (io/file f)]
-    (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 ^JarEntry %)
-       (filter #(not (.isDirectory ^JarEntry %))
-               (enumeration-seq (.entries jar-file)))))
-
-(defn system-classpath
-  "Returns a sequence of File paths from the 'java.class.path' system
-  property."
-  []
-  (map #(File. ^String %)
-       (.split (System/getProperty "java.class.path")
-               (System/getProperty "path.separator"))))
-
-(defn loader-classpath
-  "Returns a sequence of File paths from a classloader."
-  [loader]
-  (when (instance? java.net.URLClassLoader loader)
-    (map
-     #(java.io.File. (.getPath ^java.net.URL %))
-     (.getURLs ^java.net.URLClassLoader loader))))
-
-(defn classpath
-  "Returns a sequence of File objects of the elements on the classpath."
-  ([classloader]
-     (distinct
-      (mapcat
-       loader-classpath
-       (take-while
-        identity
-        (iterate #(.getParent %) classloader)))))
-  ([] (classpath (clojure.lang.RT/baseLoader))))
-
-(defn classpath-directories
-  "Returns a sequence of File objects for the directories on classpath."
-  []
-  (filter #(.isDirectory ^File %) (classpath)))
-
-(defn classpath-jarfiles
-  "Returns a sequence of JarFile objects for the JAR files on classpath."
-  []
-  (map #(JarFile. ^File %) (filter jar-file? (classpath))))

File clojuresque-base-runtime/src/main/resources/clojuresque/clojure/tools/namespace.clj

-;;; find_namespaces.clj: search for ns declarations in dirs, JARs, or CLASSPATH
-
-;; by Stuart Sierra, http://stuartsierra.com/
-;; April 19, 2009
-
-;; Copyright (c) Stuart Sierra, 2009. All rights reserved.  The use
-;; and distribution terms for this software are covered by the Eclipse
-;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
-;; which can be found in the file epl-v10.html at the root of this
-;; distribution.  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.
-
-
-(ns 
-  ^{:author "Stuart Sierra",
-     :doc "Search for ns declarations in dirs, JARs, or CLASSPATH"} 
-  clojuresque.clojure.tools.namespace
-  (:require [clojuresque.clojure.java.classpath :as classpath])
-  (import (java.io File FileReader BufferedReader PushbackReader
-                   InputStreamReader)
-          (java.util.jar JarFile)))
-
-
-;;; Finding namespaces in a directory tree
-
-(defn clojure-source-file?
-  "Returns true if file is a normal file with a .clj extension."
-  [^File file]
-  (and (.isFile file)
-       (.endsWith (.getName file) ".clj")))
-
-(defn find-clojure-sources-in-dir
-  "Searches recursively under dir for Clojure source files (.clj).
-  Returns a sequence of File objects, in breadth-first sort order."
-  [^File dir]
-  ;; Use sort by absolute path to get breadth-first search.
-  (sort-by #(.getAbsolutePath %)
-           (filter clojure-source-file? (file-seq dir))))
-
-(defn comment?
-  "Returns true if form is a (comment ...)"
-  [form]
-  (and (list? form) (= 'comment (first form))))
-
-(defn ns-decl?
-  "Returns true if form is a (ns ...) declaration."
-  [form]
-  (and (list? form) (= 'ns (first form))))
-
-(defn read-ns-decl
-  "Attempts to read a (ns ...) declaration from rdr, and returns the
-  unevaluated form.  Returns nil if read fails or if a ns declaration
-  cannot be found.  The ns declaration must be the first Clojure form
-  in the file, except for (comment ...)  forms."
-  [^PushbackReader rdr]
-  (try
-   (loop [] (let [form (read rdr)]
-              (cond
-               (ns-decl? form) form
-               (comment? form) (recur)
-               :else nil)))
-       (catch Exception e nil)))
-
-(defn read-file-ns-decl
-  "Attempts to read a (ns ...) declaration from file, and returns the
-  unevaluated form.  Returns nil if read fails, or if the first form
-  is not a ns declaration."
-  [^File file]
-  (with-open [rdr (PushbackReader. (BufferedReader. (FileReader. file)))]
-    (read-ns-decl rdr)))
-
-(defn find-ns-decls-in-dir
-  "Searches dir recursively for (ns ...) declarations in Clojure
-  source files; returns the unevaluated ns declarations."
-  [^File dir]
-  (filter identity (map read-file-ns-decl (find-clojure-sources-in-dir dir))))
-
-(defn find-namespaces-in-dir
-  "Searches dir recursively for (ns ...) declarations in Clojure
-  source files; returns the symbol names of the declared namespaces."
-  [^File dir]
-  (map second (find-ns-decls-in-dir dir)))
-
-
-;;; Finding namespaces in JAR files
-
-(defn clojure-sources-in-jar
-  "Returns a sequence of filenames ending in .clj found in the JAR file."
-  [^JarFile jar-file]
-  (filter #(.endsWith % ".clj") (classpath/filenames-in-jar jar-file)))
-
-(defn read-ns-decl-from-jarfile-entry
-  "Attempts to read a (ns ...) declaration from the named entry in the
-  JAR file, and returns the unevaluated form.  Returns nil if the read
-  fails, or if the first form is not a ns declaration."
-  [^JarFile jarfile ^String entry-name]
-  (with-open [rdr (PushbackReader.
-                   (BufferedReader.
-                    (InputStreamReader.
-                     (.getInputStream jarfile (.getEntry jarfile entry-name)))))]
-    (read-ns-decl rdr)))
-
-(defn find-ns-decls-in-jarfile
-  "Searches the JAR file for Clojure source files containing (ns ...)
-  declarations; returns the unevaluated ns declarations."
-  [^JarFile jarfile]
-  (filter identity
-          (map #(read-ns-decl-from-jarfile-entry jarfile %)
-               (clojure-sources-in-jar jarfile))))
-
-(defn find-namespaces-in-jarfile
-  "Searches the JAR file for Clojure source files containing (ns ...)
-  declarations.  Returns a sequence of the symbol names of the
-  declared namespaces."
-  [^JarFile jarfile]
-  (map second (find-ns-decls-in-jarfile jarfile)))
-
-
-;;; Finding namespaces anywhere on CLASSPATH
-
-(defn find-ns-decls-on-classpath
-  "Searches CLASSPATH (both directories and JAR files) for Clojure
-  source files containing (ns ...) declarations.  Returns a sequence
-  of the unevaluated ns declaration forms."
-  []
-  (concat
-   (mapcat find-ns-decls-in-dir (classpath/classpath-directories))
-   (mapcat find-ns-decls-in-jarfile (classpath/classpath-jarfiles))))
-
-(defn find-namespaces-on-classpath
-  "Searches CLASSPATH (both directories and JAR files) for Clojure
-  source files containing (ns ...) declarations.  Returns a sequence
-  of the symbol names of the declared namespaces."
-  []
-  (map second (find-ns-decls-on-classpath)))

File clojuresque-base-runtime/src/main/resources/clojuresque/codox/reader.clj

   (:use [clojuresque.codox.utils :only (unindent)])
   (:require [clojure.java.io :as io]
             [clojure.string :as str]
-            [clojuresque.clojure.tools.namespace :as ns])
+            [clojuresque.util :as util])
   (:import java.util.jar.JarFile))
 
 (defn- correct-indent [text]
         (update-in [:doc] correct-indent))))
 
 (defn- read-ns [namespace]
-  (try
-    (require namespace)
-    (-> (find-ns namespace)
-        (meta)
-        (assoc :name namespace)
-        (assoc :publics (read-publics namespace))
-        (update-in [:doc] correct-indent)
-        (list))
-    (catch Exception e
-      (println "Could not generate documentation for" namespace))))
-
-(defn- jar-file? [file]
-  (and (.isFile file)
-       (-> file .getName (.endsWith ".jar"))))
-
-(defn- clj-file? [file]
-  (and (.isFile file)
-       (-> file .getName (.endsWith ".clj"))))
-
-(defn- find-namespaces [file]
-  (cond
-    (.isDirectory file) (ns/find-namespaces-in-dir file)
-    (jar-file? file)    (ns/find-namespaces-in-jarfile (JarFile. file))
-    (clj-file? file)    (when-let [nspace (second (ns/read-file-ns-decl file))]
-                          [nspace])))
+  (when namespace
+    (try
+      (require namespace)
+      (-> (find-ns namespace)
+          (meta)
+          (assoc :name namespace)
+          (assoc :publics (read-publics namespace))
+          (update-in [:doc] correct-indent)
+          (list))
+      (catch Exception e
+        (println "Could not generate documentation for" namespace)))))
 
 (defn read-namespaces
   "Read namespaces from a source directory (defaults to \"src\"), and
       :doc      - the doc-string of the var
       :macro    - true if the var is a macro
       :added    - the library version the var was added in"
-  ([]
-     (read-namespaces "src"))
   ([path]
-     (->> (io/file path)
-          (find-namespaces)
-          (mapcat read-ns)))
+     (->> path
+          util/namespace-of-file
+          read-ns))
   ([path & paths]
      (mapcat read-namespaces (cons path paths))))