-
Notifications
You must be signed in to change notification settings - Fork 9
/
source_analysis.clj
47 lines (44 loc) · 1.52 KB
/
source_analysis.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(ns cider.enrich-classpath.source-analysis
(:require
[clojure.java.io :as io]
[clojure.string :as string])
(:import
(java.io File)
(java.util.zip ZipException ZipEntry ZipInputStream)))
(defmacro while-let
{:style/indent 1}
[[sym expr] & body]
`(loop [~sym ~expr]
(when ~sym
~@body
(recur ~expr))))
(defn ls-zip [target]
(let [v (transient [])
zis (-> target io/input-stream ZipInputStream.)]
(try
(while-let [entry (-> zis .getNextEntry)]
(conj! v (-> ^ZipEntry entry .getName)))
(catch ZipException _)
(finally
(-> zis .close)))
(persistent! v)))
(defn bad-source? [[id version _classifier-keyword classifier]]
{:pre [(symbol? id)
(string? version)
(keyword? _classifier-keyword)
(string? classifier)]}
(when (#{"sources"} classifier)
(let [[groupid artifactid :as x] (-> id str (string/split #"/"))
artifactid (or artifactid groupid) ;; concise notation
_ (assert artifactid x)
segments (-> groupid (string/split #"\."))
home (System/getProperty "user.home")
file (apply io/file home ".m2" "repository" segments)
artifact (str artifactid "-" version "-" classifier ".jar")
^File file (io/file file artifactid version artifact)]
(when (-> file .exists)
(->> file
ls-zip
(not-any? (fn [^String s]
(or (-> s (.endsWith ".java"))
(-> s (.endsWith ".scala"))))))))))