Skip to content

Commit 190c9fd

Browse files
committed
Update to Java commit 3125f4b (2023.02.13): TNS-55: Added jar/dir and file metadata to ns declaration symbol name in find-ns-decls and test.
1 parent d774e55 commit 190c9fd

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

src/main/clojure/clojure/tools/namespace/find.clj

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
DirectoryInfo FileSystemInfo) ;;; InputStreamReader)
2020
(clojure.lang PushbackTextReader))) ;;; (java.util.jar JarFile JarEntry)))
2121

22+
(set! *warn-on-reflection* true)
23+
2224
(def ^{:added "0.3.0"}
2325
clj
2426
"Platform definition of file extensions and reader options for
@@ -84,14 +86,20 @@
8486
(defn find-ns-decls-in-dir
8587
"Searches dir recursively for (ns ...) declarations in Clojure
8688
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+
8893
Optional second argument platform is either clj (default) or cljs,
8994
both defined in clojure.tools.namespace.find."
9095
{:added "0.2.0"}
9196
([dir] (find-ns-decls-in-dir dir nil))
9297
([dir platform]
9398
(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)))
95103
(find-sources-in-dir dir platform))))
96104

97105
(defn find-namespaces-in-dir
@@ -109,7 +117,7 @@
109117

110118
(defn- ends-with-extension
111119
[^String filename extensions]
112-
(some #(.EndsWith filename %) extensions)) ;;; .endsWith
120+
(some #(.EndsWith filename ^String %) extensions)) ;;; .endsWith, add type hint
113121

114122
(defn sources-in-jar
115123
"Returns a sequence of source file names found in the JAR file.
@@ -138,7 +146,10 @@
138146
"Attempts to read a (ns ...) declaration from the named entry in the
139147
JAR file, and returns the unevaluated form. Returns nil if read
140148
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+
142153
Optional third argument platform is either clj (default) or cljs,
143154
both defined in clojure.tools.namespace.find."
144155
([jarfile entry-name]
@@ -149,7 +160,10 @@
149160
;;; (io/reader
150161
;;; (.getInputStream jarfile (.getEntry jarfile entry-name))))]
151162
;;; (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)))))))
153167
(defn find-ns-decls-in-jarfile
154168
"Searches the JAR file for source files containing (ns ...)
155169
declarations; returns the unevaluated ns declarations.

src/test/clojure/clojure/tools/namespace/find_test.clj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,14 @@
2626
two-cljs (help/create-source dir 'example.two :cljs)]
2727
(is (help/same-files?
2828
[main-cljs one-cljc two-cljs]
29-
(find/find-sources-in-dir dir find/cljs)))))
29+
(find/find-sources-in-dir dir find/cljs)))))
30+
31+
(deftest t-find-ns-decl-meta
32+
(let [dir (help/create-temp-dir "t-find-clj-and-cljc-files")
33+
main-clj (help/create-source dir 'example.main :clj '[example.one])
34+
one-cljc (help/create-source dir 'example.one :cljc '[example.two])
35+
two-clj (help/create-source dir 'example.two :clj)
36+
two-cljs (help/create-source dir 'example.two :cljs)]
37+
(is (every? #{(.Name ^System.IO.DirectoryInfo dir)} ;; .getName ^java.io.File
38+
(map #(-> % second meta :dir)
39+
(find/find-ns-decls [dir]))))))

src/test/clojure/clojure/tools/namespace/track_test.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
z (remove y '(d))
2626
w (remove y '(q))]
2727
#_(is (equal-dep-map? z '(b a) '(a b d) '{b #{c d}, a #{b}} '{d #{b}, c #{b}, b #{a}})) ;; with the TNS-6 change, shouldn't this test change?
28-
(is (equal-dep-map? z '(b a) '(a b) '{b #{c}, a #{b}} '{c #{b}, b #{a}}))
28+
(is (equal-dep-map? z '(b a) '(a b d) '{b #{c}, a #{b}} '{c #{b}, b #{a}}))
2929
(is (= y w))))
3030

3131

0 commit comments

Comments
 (0)