|
19 | 19 | InputStreamReader)
|
20 | 20 | (java.util.jar JarFile JarEntry)))
|
21 | 21 |
|
22 |
| -(def clojure-platform |
23 |
| - "Definition of file extensions and reader options for Clojure (.clj |
24 |
| - and .cljc) source files." |
| 22 | +(def ^{:added "0.3.0"} |
| 23 | + clj |
| 24 | + "Platform definition of file extensions and reader options for |
| 25 | + Clojure (.clj and .cljc) source files." |
25 | 26 | {:read-opts parse/clojure-read-opts
|
26 | 27 | :extensions file/clojure-extensions})
|
27 | 28 |
|
28 |
| -(def clojurescript-platform |
29 |
| - "Definition of file extensions and reader options for ClojureScript |
30 |
| - (.cljs and .cljc) source files." |
| 29 | +(def ^{:added "0.3.0"} |
| 30 | + cljs |
| 31 | + "Platform definition of file extensions and reader options for |
| 32 | + ClojureScript (.cljs and .cljc) source files." |
31 | 33 | {:read-opts parse/clojurescript-read-opts
|
32 | 34 | :extensions file/clojurescript-extensions})
|
33 | 35 |
|
|
39 | 41 |
|
40 | 42 | (defn find-sources-in-dir
|
41 | 43 | "Searches recursively under dir for source files. Returns a sequence
|
42 |
| - of File objects, in breadth-first sort order." |
| 44 | + of File objects, in breadth-first sort order. |
| 45 | +
|
| 46 | + Optional second argument is either clj (default) or cljs, both |
| 47 | + defined in clojure.tools.namespace.find." |
| 48 | + {:added "0.3.0"} |
43 | 49 | ([dir]
|
44 | 50 | (find-sources-in-dir dir nil))
|
45 | 51 | ([^File dir platform]
|
46 |
| - (let [{:keys [extensions]} (or platform clojure-platform)] |
| 52 | + (let [{:keys [extensions]} (or platform clj)] |
47 | 53 | (->> (file-seq dir)
|
48 | 54 | (filter #(file/file-with-extension? % extensions))
|
49 | 55 | sort-files-breadth-first))))
|
|
53 | 59 |
|
54 | 60 | Searches recursively under dir for Clojure source files (.clj, .cljc).
|
55 | 61 | Returns a sequence of File objects, in breadth-first sort order."
|
| 62 | + {:added "0.2.0" |
| 63 | + :deprecated "0.3.0"} |
56 | 64 | [^File dir]
|
57 |
| - (find-sources-in-dir dir clojure-platform)) |
| 65 | + (find-sources-in-dir dir clj)) |
58 | 66 |
|
59 | 67 | (defn find-ns-decls-in-dir
|
60 | 68 | "Searches dir recursively for (ns ...) declarations in Clojure
|
61 |
| - source files; returns the unevaluated ns declarations." |
| 69 | + source files; returns the unevaluated ns declarations. |
| 70 | +
|
| 71 | + Optional second argument platform is either clj (default) or cljs, |
| 72 | + both defined in clojure.tools.namespace.find." |
| 73 | + {:added "0.2.0"} |
62 | 74 | ([dir] (find-ns-decls-in-dir dir nil))
|
63 |
| - ([dir options] |
64 |
| - (keep #(file/read-file-ns-decl % options) |
65 |
| - (find-clojure-sources-in-dir dir)))) |
| 75 | + ([dir platform] |
| 76 | + (keep #(file/read-file-ns-decl % (:read-opts platform)) |
| 77 | + (find-sources-in-dir dir platform)))) |
66 | 78 |
|
67 | 79 | (defn find-namespaces-in-dir
|
68 | 80 | "Searches dir recursively for (ns ...) declarations in Clojure
|
69 |
| - source files; returns the symbol names of the declared namespaces." |
70 |
| - ([dir] (find-namespaces-in-dir dir)) |
71 |
| - ([dir options] |
72 |
| - (map second (find-ns-decls-in-dir dir options)))) |
| 81 | + source files; returns the symbol names of the declared namespaces. |
| 82 | +
|
| 83 | + Optional second argument platform is either clj (default) or cljs, |
| 84 | + both defined in clojure.tools.namespace.find." |
| 85 | + {:added "0.3.0"} |
| 86 | + ([dir] (find-namespaces-in-dir dir nil)) |
| 87 | + ([dir platform] |
| 88 | + (map second (find-ns-decls-in-dir dir platform)))) |
73 | 89 |
|
74 | 90 | ;;; Finding namespaces in JAR files
|
75 | 91 |
|
|
79 | 95 |
|
80 | 96 | (defn sources-in-jar
|
81 | 97 | "Returns a sequence of source file names found in the JAR file.
|
82 |
| - Optional second argument is either clojure-platform or |
83 |
| - clojurescript-platform, both defined in this namespace.. Controls |
84 |
| - which file extensions are included." |
| 98 | +
|
| 99 | + Optional second argument platform is either clj (default) or cljs, |
| 100 | + both defined in clojure.tools.namespace.find." |
| 101 | + {:added "0.3.0"} |
85 | 102 | ([jar-file]
|
86 | 103 | (sources-in-jar jar-file nil))
|
87 | 104 | ([^JarFile jar-file platform]
|
88 |
| - (let [{:keys [extensions]} (or platform clojure-platform)] |
| 105 | + (let [{:keys [extensions]} (or platform clj)] |
89 | 106 | (filter #(ends-with-extension % extensions)
|
90 | 107 | (classpath/filenames-in-jar jar-file)))))
|
91 | 108 |
|
|
94 | 111 |
|
95 | 112 | Returns a sequence of filenames ending in .clj or .cljc found in the
|
96 | 113 | JAR file."
|
| 114 | + {:added "0.2.0" |
| 115 | + :deprecated "0.3.0"} |
97 | 116 | [jar-file]
|
98 |
| - (sources-in-jar jar-file clojure-platform)) |
| 117 | + (sources-in-jar jar-file clj)) |
99 | 118 |
|
100 | 119 | (defn read-ns-decl-from-jarfile-entry
|
101 | 120 | "Attempts to read a (ns ...) declaration from the named entry in the
|
102 |
| - JAR file, and returns the unevaluated form. Returns nil if the read |
103 |
| - fails, or if the first form is not a ns declaration." |
| 121 | + JAR file, and returns the unevaluated form. |
| 122 | +
|
| 123 | + Optional third argument platform is either clj (default) or cljs, |
| 124 | + both defined in clojure.tools.namespace.find." |
104 | 125 | ([jarfile entry-name]
|
105 | 126 | (read-ns-decl-from-jarfile-entry jarfile entry-name nil))
|
106 | 127 | ([^JarFile jarfile ^String entry-name platform]
|
107 |
| - (let [{:keys [read-opts]} (or platform clojure-platform)] |
| 128 | + (let [{:keys [read-opts]} (or platform clj)] |
108 | 129 | (with-open [rdr (PushbackReader.
|
109 | 130 | (io/reader
|
110 | 131 | (.getInputStream jarfile (.getEntry jarfile entry-name))))]
|
111 | 132 | (parse/read-ns-decl rdr read-opts)))))
|
112 | 133 |
|
113 | 134 | (defn find-ns-decls-in-jarfile
|
114 |
| - "Searches the JAR file for platform source files containing (ns ...) |
115 |
| - declarations; returns the unevaluated ns declarations." |
| 135 | + "Searches the JAR file for source files containing (ns ...) |
| 136 | + declarations; returns the unevaluated ns declarations. |
| 137 | +
|
| 138 | + Optional second argument platform is either clj (default) or cljs, |
| 139 | + both defined in clojure.tools.namespace.find." |
116 | 140 | ([jarfile]
|
117 | 141 | (find-ns-decls-in-jarfile jarfile nil))
|
118 | 142 | ([^JarFile jarfile platform]
|
|
122 | 146 | (defn find-namespaces-in-jarfile
|
123 | 147 | "Searches the JAR file for platform source files containing (ns ...)
|
124 | 148 | declarations. Returns a sequence of the symbol names of the
|
125 |
| - declared namespaces." |
| 149 | + declared namespaces. |
| 150 | +
|
| 151 | + Optional second argument platform is either clj (default) or cljs, |
| 152 | + both defined in clojure.tools.namespace.find." |
126 | 153 | ([jarfile]
|
127 | 154 | (find-namespaces-in-jarfile jarfile nil))
|
128 | 155 | ([^JarFile jarfile platform]
|
|
136 | 163 | JAR files) for platform source files containing (ns...)
|
137 | 164 | declarations. Returns a sequence of the unevaluated ns declaration
|
138 | 165 | forms. Use with clojure.java.classpath to search Clojure's
|
139 |
| - classpath." |
| 166 | + classpath. |
| 167 | +
|
| 168 | + Optional second argument platform is either clj (default) or cljs, |
| 169 | + both defined in clojure.tools.namespace.find." |
140 | 170 | ([files]
|
141 | 171 | (find-ns-decls files nil))
|
142 | 172 | ([files platform]
|
|
151 | 181 | JAR files) for platform source files containing (ns...)
|
152 | 182 | declarations. Returns a sequence of the symbol names of the declared
|
153 | 183 | namespaces. Use with clojure.java.classpath to search Clojure's
|
154 |
| - classpath." |
| 184 | + classpath. |
| 185 | +
|
| 186 | + Optional second argument platform is either clj (default) or cljs, |
| 187 | + both defined in clojure.tools.namespace.find." |
155 | 188 | ([files]
|
156 | 189 | (find-namespaces files nil))
|
157 | 190 | ([files platform]
|
|
0 commit comments