|
19 | 19 | DirectoryInfo FileSystemInfo) ;;; InputStreamReader)
|
20 | 20 | (clojure.lang PushbackTextReader))) ;;; (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
|
|
84 | 86 | (defn find-ns-decls-in-dir
|
85 | 87 | "Searches dir recursively for (ns ...) declarations in Clojure
|
86 | 88 | source files; returns the unevaluated ns declarations.
|
87 |
| -
|
| 89 | + The symbol name in the returned ns declaration will contain metadata |
| 90 | + for the corresponding directory and located file within at keys |
| 91 | + :dir and :file. |
| 92 | + |
88 | 93 | Optional second argument platform is either clj (default) or cljs,
|
89 | 94 | both defined in clojure.tools.namespace.find."
|
90 | 95 | {:added "0.2.0"}
|
91 | 96 | ([dir] (find-ns-decls-in-dir dir nil))
|
92 | 97 | ([dir platform]
|
93 | 98 | (keep #(ignore-reader-exception
|
94 |
| - (file/read-file-ns-decl % (:read-opts platform))) |
| 99 | + (let [[_ nom & more] (file/read-file-ns-decl % (:read-opts platform))] |
| 100 | + (list* 'ns (with-meta nom |
| 101 | + {:dir (.Name ^System.IO.DirectoryInfo dir) :file (.Name ^System.IO.FileInfo %)}) ;; .getName ^java.io.File x 2 |
| 102 | + more))) |
95 | 103 | (find-sources-in-dir dir platform))))
|
96 | 104 |
|
97 | 105 | (defn find-namespaces-in-dir
|
|
109 | 117 |
|
110 | 118 | (defn- ends-with-extension
|
111 | 119 | [^String filename extensions]
|
112 |
| - (some #(.EndsWith filename %) extensions)) ;;; .endsWith |
| 120 | + (some #(.EndsWith filename ^String %) extensions)) ;;; .endsWith, add type hint |
113 | 121 |
|
114 | 122 | (defn sources-in-jar
|
115 | 123 | "Returns a sequence of source file names found in the JAR file.
|
|
138 | 146 | "Attempts to read a (ns ...) declaration from the named entry in the
|
139 | 147 | JAR file, and returns the unevaluated form. Returns nil if read
|
140 | 148 | fails due to invalid syntax or if a ns declaration cannot be found.
|
141 |
| -
|
| 149 | + The symbol name in the returned ns declaration will contain metadata |
| 150 | + for the corresponding jar filename and located file within at keys |
| 151 | + :jar and :file. |
| 152 | + |
142 | 153 | Optional third argument platform is either clj (default) or cljs,
|
143 | 154 | both defined in clojure.tools.namespace.find."
|
144 | 155 | ([jarfile entry-name]
|
|
149 | 160 | ;;; (io/reader
|
150 | 161 | ;;; (.getInputStream jarfile (.getEntry jarfile entry-name))))]
|
151 | 162 | ;;; (ignore-reader-exception
|
152 |
| - ;;; (parse/read-ns-decl rdr read-opts)))))) |
| 163 | + ;;; (let [[_ nom & more] (parse/read-ns-decl rdr read-opts)] |
| 164 | + ;;; (list* 'ns (with-meta nom |
| 165 | + ;;; {:jar (.getName ^java.io.File jarfile) :file entry-name}) |
| 166 | + ;;; more))))))) |
153 | 167 | (defn find-ns-decls-in-jarfile
|
154 | 168 | "Searches the JAR file for source files containing (ns ...)
|
155 | 169 | declarations; returns the unevaluated ns declarations.
|
|
0 commit comments