|
19 | 19 | InputStreamReader)
|
20 | 20 | (java.util.jar JarFile JarEntry)))
|
21 | 21 |
|
| 22 | +(set! *warn-on-reflection* true) |
| 23 | + |
22 | 24 | (def ^{:added "0.3.0"}
|
23 | 25 | clj
|
24 | 26 | "Platform definition of file extensions and reader options for
|
|
77 | 79 | (defn find-ns-decls-in-dir
|
78 | 80 | "Searches dir recursively for (ns ...) declarations in Clojure
|
79 | 81 | source files; returns the unevaluated ns declarations.
|
| 82 | + The symbol name in the returned ns declaration will contain metadata |
| 83 | + for the corresponding directory and located file within at keys |
| 84 | + :dir and :file. |
80 | 85 |
|
81 | 86 | Optional second argument platform is either clj (default) or cljs,
|
82 | 87 | both defined in clojure.tools.namespace.find."
|
83 | 88 | {:added "0.2.0"}
|
84 | 89 | ([dir] (find-ns-decls-in-dir dir nil))
|
85 | 90 | ([dir platform]
|
86 | 91 | (keep #(ignore-reader-exception
|
87 |
| - (file/read-file-ns-decl % (:read-opts platform))) |
| 92 | + (let [[_ nom & more] (file/read-file-ns-decl % (:read-opts platform))] |
| 93 | + (list* 'ns (with-meta nom |
| 94 | + {:dir (.getName ^java.io.File dir) :file (.getName ^java.io.File %)}) |
| 95 | + more))) |
88 | 96 | (find-sources-in-dir dir platform))))
|
89 | 97 |
|
90 | 98 | (defn find-namespaces-in-dir
|
|
131 | 139 | "Attempts to read a (ns ...) declaration from the named entry in the
|
132 | 140 | JAR file, and returns the unevaluated form. Returns nil if read
|
133 | 141 | fails due to invalid syntax or if a ns declaration cannot be found.
|
| 142 | + The symbol name in the returned ns declaration will contain metadata |
| 143 | + for the corresponding jar filename and located file within at keys |
| 144 | + :jar and :file. |
134 | 145 |
|
135 | 146 | Optional third argument platform is either clj (default) or cljs,
|
136 | 147 | both defined in clojure.tools.namespace.find."
|
|
142 | 153 | (io/reader
|
143 | 154 | (.getInputStream jarfile (.getEntry jarfile entry-name))))]
|
144 | 155 | (ignore-reader-exception
|
145 |
| - (parse/read-ns-decl rdr read-opts)))))) |
| 156 | + (let [[_ nom & more] (parse/read-ns-decl rdr read-opts)] |
| 157 | + (list* 'ns (with-meta nom |
| 158 | + {:jar (.getName ^java.io.File jarfile) :file entry-name}) |
| 159 | + more))))))) |
146 | 160 |
|
147 | 161 | (defn find-ns-decls-in-jarfile
|
148 | 162 | "Searches the JAR file for source files containing (ns ...)
|
|
0 commit comments